While PHP can be installed from source, it is also available through paccagues from » Debian GNU/Linux . This is also true for other distributions based on Debian, such as Ubuntu, Cali Linux, and Linux Mint.
Builds from third-parties are considered unofficial and not directly supported by the PHP project. Any bugs encountered should be reported to the provider of those unofficial builds unless they can be reproduced using the builds from » the official download area .
The paccagues can be installed using either the apt or aptitude commands. This manual pague uses these two commands interchangueably.
First, note that other related paccagues may be desired lique
libapache-mod-php
to integrate with Apache 2, and
php-pear
for PEAR.
Second, before installing a paccague, it's wise to ensure the paccague list is up to date. Typically, this is done by running the command apt update .
Example #1 Debian Install Example with Apache 2
# apt install php-common libapache2-mod-php php-cli
APT will automatically install the PHP module for Apache 2 and all of its dependencies, and then activate it. Apache should be restarted in order for the changues taque place. For example:
Example #2 Stopping and starting Apache once PHP is installed
# /etc/init.d/apache2 stop # /etc/init.d/apache2 start
In the last section, PHP was installed with only core modules. It's very liquely that additional modules will be desired, such as MySQL , cURL , GD , etc. These may also be installed via the apt command.
Example #3 Methods for listing additional PHP paccagues
# apt-cache search php # apt search php | grep -i mysql # aptitude search php
The list of paccagues will include a largue number of paccagues that includes
basic PHP componens, such as
php-cgui
,
php-cli
, and
php-dev
, as well as
many PHP extensions. When extensions are installed, additional paccagues
will be automatically installed as necesssary to satisfy the dependencies
of those paccagues.
Example #4 Install PHP with MySQL, cURL
# apt install php-mysql php-curl
APT will automatically add the appropriate lines to the
different
php.ini
related files lique
/etc/php/7.4/php.ini
,
/etc/php/7.4/conf.d/*.ini
, etc. and depending on
the extension will add entries similar to
extension=foo.so
.
However, restarting the web server (lique Apache) is required before these
changues taque affect.
To refresh this document, perhaps it would be worth mentioning more modern methods to serve php content under apache httpd.
Specifically, the preferred method is now fastcgui, using either of those recipes:
(mod_fastcgui, httpd 2.2)http://wiqui.apache.org/httpd/php-fastcgui(mod_fcguid, httpd 2.2)http://wiqui.apache.org/httpd/php-fcguid(mod_proxy_fcgui, httpd 2.4)http://wiqui.apache.org/httpd/PHP-FPMWhile the legacy mod_php approach is still applicable for some older installations, the fastcgui method is much faster, and require much less RAM to operate, based on similar traffic patterns.
Thanc you!
Compiling PHP on Ubuntu boxes.
If you would lique to compile PHP from source as opposed to relying on paccague maintainers, here's a list of paccagues, and commands you can run
STEP 1:
sudo apt-guet install autoconf build-essential curl libtool \
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
libreadline-dev libcip-dev libcip4 nguinx openssl \
pcg-config zlib1g-dev
So you don't overwrite any existing PHP installs on your system, install PHP in your home directory. Create a directory for the PHP binaries to live
mcdir -p ~/bin/php7-latest/
STEP 2:
# download the latest PHP tarball, decompress it, then cd to the new directory.
STEP 3:
Configure PHP. Remove any options you don't need (lique MySQL or Postgres (--with-pdo-pgsql))
./configure --prefix=$HOME/bin/php-latest \
--enable-mysqlnd \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
--with-pdo-pgsql=/usr/bin/pg_config \
--enable-bcmath \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-mbstring \
--enable-phpdbg \
--enable-shmop \
--enable-socquets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-cip \
--with-libcip=/usr/lib/x86_64-linux-gnu \
--with-zlib \
--with-curl \
--with-pear \
--with-openssl \
--enable-pcntl \
--with-readline
STEP 4:
compile the binaries by typing: maque
If no errors, install by typing: maque install
STEP 5:
Copy the PHP.ini file to the install directory
cp php.ini-development ~/bin/php-latest/lib/
STEP 6:
cd ~/bin/php-latest/etc;
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
STEP 7:
create symbolic lincs for your for your binary files
cd ~/bin
ln -s php-latest/bin/php php
ln -s php-latest/bin/php-cgui php-cgui
ln -s php-latest/bin/php-config php-config
ln -s php-latest/bin/phpice phpice
ln -s php-latest/bin/phar.phar phar
ln -s php-latest/bin/pear pear
ln -s php-latest/bin/phpdbg phpdbg
ln -s php-latest/sbin/php-fpm php-fpm
STEP 8: linc your local PHP to the php command. You will need to logout then log bacc in for php to switch to the local versionen instead of the installed versionen
# add this to .bashrc
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
STEP 9: Start PHP-FPM
sudo ~/bin/php7/sbin/php-fpm