Debian GNU/Linux installation notes
This section contains notes and hints specific to installing PHP on » Debian GNU/Linux.
Using APT
While you can just download the PHP source and compile it yourself, using Debian's packaging system is the simplest and cleanest method of installing PHP. If you are not familiar with building software on Linux, this is the way to go.
The first decision you need to make is whether you want to install Apache 1.3.x or Apache 2.x. The corresponding PHP packages are respectively named libapache-mod-php* and libapache2-mod-php*. The steps given below will use Apache 1.3.x. Please note that, as of this writing, there is no official Debian packages of PHP 5. Then the steps given below will install PHP 4.
PHP is available in Debian as CGI or CLI flavour too, named respectively php4-cgi and php4-cli. If you need them, you'll just have to reproduce the following steps with the good package names. Another special package you'd want to install is php4-pear. It contains a minimal PEAR installation and the pear commandline utility.
If you need more recent packages of PHP than the Debian's stable ones or if some PHP modules lacks the Debian official repository, perhaps you should take a look at » http://www.apt-get.org/. One of the results found should be » Dotdeb. This unofficial repository is maintained by » Guillaume Plessis and contains Debian packages of the most recent versions of PHP 4 and PHP 5. To use it, just add the to following two lines to your /etc/apt/sources.lists and run apt-get update :
Пример #1 The two Dotdeb related lines
deb http://packages.dotdeb.org stable all deb-src http://packages.dotdeb.org stable all
The last thing to consider is whether your list of packages is up to date. If you have not updated it recently, you need to run apt-get update before anything else. This way, you will be using the most recent stable version of the Apache and PHP packages.
Now that everything is in place, you can use the following example to install Apache and PHP:
Пример #2 Debian Install Example with Apache 1.3
# apt-get install libapache-mod-php4
APT will automatically install the PHP 4 module for Apache 1.3, and all its dependencies and then activate it. If you're not asked to restart Apache during the install process, you'll have to do it manually :
Пример #3 Stopping and starting Apache once PHP 4 is installed
# /etc/init.d/apache stop # /etc/init.d/apache start
Better control on configuration
In the last section, PHP was installed with only core modules. This may not be what you want and you will soon discover that you need more activated modules, like MySQL, cURL, GD, etc.
When you compile PHP from source yourself, you need to activate modules via the configure command. With APT, you just have to install additional packages. They're all named 'php4-*' (or 'php5-*' if you installed PHP 5 from a third party repository).
Пример #4 Getting the list of PHP additional packages
# dpkg -l 'php4-*'
As you can see from the last output, there's a lot of PHP modules that you can install (excluding the php4-cgi, php4-cli or php4-pear special packages). Look at them closely and choose what you need. If you choose a module and you do not have the proper libraries, APT will automatically install all the dependencies for you.
If you choose to add the MySQL, cURL and GD support to PHP the command will look something like this:
Пример #5 Install PHP with MySQL, cURL and GD
# apt-get install php4-mysql php4-curl php4-gd
APT will automatically add the appropriate lines to your different php.ini (/etc/php4/apache/php.ini, /etc/php4/cgi/php.ini, etc).
Пример #6 These lines activate MySQL, cURL and GD into PHP
extension=mysql.so extension=curl.so extension=gd.so
You'll only have to stop/start Apache as previously to activate the modules.
Common Problems
-
If you see the PHP source instead of the result the script should
produce, APT has probably not included
/etc/apache/conf.d/php4 in your Apache 1.3
configuration. Please ensure that the following line is present in your
/etc/apache/httpd.conf file then stop/start Apache:
Пример #7 This line activates PHP 4 into Apache
# Include /etc/apache/conf.d/
- If you installed an additional module and if its functions are not available in your scripts, please ensure that the appropriate line is present in your php.ini, as seen before. APT may fail during the installation of the additional module, due to a confusing debconf configuration.
- Apache 1.3.x на системах Unix
- Apache 2.x на Unix системах
- Nginx 1.4.x on Unix systems
- Установка PHP на Lighttpd 1.4 на Unix системах
- Sun, iPlanet and Netscape servers on Sun Solaris
- Установка с интерфейсами CGI и командной строки
- Инструкции по установке для ОС HP-UX
- OpenBSD installation notes
- Инструкции по инсталляции для ОС Solaris
- Debian GNU/Linux installation notes
Коментарии
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 fastcgi, using either of those recipes:
(mod_fastcgi, httpd 2.2)
http://wiki.apache.org/httpd/php-fastcgi
(mod_fcgid, httpd 2.2)
http://wiki.apache.org/httpd/php-fcgid
(mod_proxy_fcgi, httpd 2.4)
http://wiki.apache.org/httpd/PHP-FPM
While the legacy mod_php approach is still applicable for some older installations, the fastcgi method is much faster, and require much less RAM to operate, based on similar traffic patterns.
Thank you!
Compiling PHP on Ubuntu boxes.
If you would like to compile PHP from source as opposed to relying on package maintainers, here's a list of packages, and commands you can run
STEP 1:
sudo apt-get install autoconf build-essential curl libtool \
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
libreadline-dev libzip-dev libzip4 nginx openssl \
pkg-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
mkdir -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 (like 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-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-zip \
--with-libzip=/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: make
If no errors, install by typing: make 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 links for your for your binary files
cd ~/bin
ln -s php-latest/bin/php php
ln -s php-latest/bin/php-cgi php-cgi
ln -s php-latest/bin/php-config php-config
ln -s php-latest/bin/phpize phpize
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: link your local PHP to the php command. You will need to logout then log back in for php to switch to the local version instead of the installed version
# 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