From: http://www.codingthink.com/c/20120203/201202030006062.html
Compiling and installing PHP in Ubuntu is very troublesome, so we can move other people's things here.
Abstract:
Install php5.3.8 in the 64-bit Ubuntu source code and configure nginx as a web server. There are already a lot of articles on the Internet for compiling and installing PHP in the source code, but I still write this on Google. One of the reasons is that it is necessary to reload the system. The most important thing is to configure the environment, previously, we had been using sudo apt-get to tune the installation method. Therefore, we can try the source code installation and try the installation method. The second reason is that this is the first source code installation.
I. Preparation
Environment:64-bit Ubuntu 11.10
Server:Nginx 1.1.13
Download PHP source code:This document uses version 5.3.8
apt-get install build-essential
Other required software packages
apt-get install libxml2-dev libcurl4-openssl-dev libbz2-dev libpng-dev libfreetype6-dev libmcrypt-dev libmhash-dev libmysqlclient-dev libxslt1-dev libjpeg62-dev libltdl-dev
Ii. Installation
# tar zxvf php5.3.8.tar.gz# cd php5.3.8# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-t1lib --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --with-fpm-user=xiaoxiao --with-fpm-group --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm
The following error occurs:
Error 1:
Configure: Error: xml2-config not found. Please check your libxml2 installation.
I have installed libxml2, but the following message is displayed:
Solution:
# sudo apt-get install libxml2-dev
Error 2:
Configure: Error: Please reinstall the Bzip2 Distribution
And I have already installed Bzip2, the solution found online is to install bzip2-dev, but 11.10 does not have this library.
Solution: Find bzip2-1.0.5.tar.gz on the internet, decompress, make directly, sudo make install. (the source I use is from the http://ishare.iask.sina.com.cn/f/9769001.html)
Error 3:
Configure: Error: Please reinstall the libcurl distribution-Easy. h shoshould be in <curl-dir>/include/curl/
Solution:
# sudo apt-get install libcurl4-gnutls-dev
Error 4:
Configure: Error: Invalid Lib. h not found.
Solution:
# sudo apt-get install libjpeg-dev
Error 5:
Configure: Error: PNG. h not found.
Solution:
# sudo apt-get install libpng-dev
Error 6:
Configure: Error: libxpm. (A | so) not found.
Solution:
# sudo apt-get install libxpm-dev
Error 7:
Configure: Error: FreeType. h not found.
Solution:
# sudo apt-get install libfreetype6-dev
Error 8:
Configure: Error: Your t1lib distribution is not installed correctly. Please reinstall it.
Solution:
# sudo apt-get install libt1-dev
Error 9:
Configure: Error: mcrypt. h not found. Please reinstall libmcrypt.
Solution:
# sudo apt-get install libmcrypt-dev
Error 10:
Configure: Error: cannot find MySQL header files under yes.
Note that the mysql client library is not bundled anymore!
Solution:
# sudo apt-get install libmysql++-dev
Error 11:
Configure: Error: XSLT-config not found. Please reinstall the libxslt> = 1.1.0 Distribution
Solution:
# sudo apt-get install libxslt1-dev
Visible PHP source code installation before you need to install these dependencies, detailed visibility http://forum.ubuntu.org.cn/viewtopic.php? F = 88 & t = 231159
After all the preceding errors are solved and no errors occur again./config,
# make# sudo make install
Iii. Configuration
Php-FPM is a PHP FastCGI manager. It has already been integrated in php5.3.x, so we can save the trouble of installing it by ourselves. Just configure it.
First, copy the relevant configuration files to the PhP5/etc directory (this directory is the directory where I have to store the configuration files), mainly involving:
1. php-FPM configuration file: PhP source directory/SAPI/FPM/php-fpm.conf.in
2. php-FPM Startup File: PhP source directory/SAPI/FPM/init. d. php-fpm.in
3. PHP configuration file: PhP source directory/PHP. ini-development PHP source directory/PHP. ini-Production
If you need to save an original file, you can copy the above file with another CP. If it is not saved, the above files are directly renamed as needed by the CP to etc. I keep a copy in the etc directory.
The PhP5/etc directory now has the following configuration files:
Php-fpm.conf init. d. php-fpm php. ini pear. conf (this file is available after installation)
First:Configure the php-fpm.conf file:
1. PID Configuration
; Pid = run/php-fpm.pid
Remove the preceding; number. You can configure a path based on your needs.
2. Log Configuration
; Error-log = log/php-fpm.log
Log configuration can be enabled and stored based on your needs
3. Listen Configuration
Listen = 127.0.0.1: 9000
This configuration should not conflict with the port. I used the socket method described on the Internet when configuring this configuration. The configuration is as follows:
Listen =/usr/local/PhP5/var/run/php-fpm.socket
Create the file in the/usr/local/PhP5/var/run/directory.
You can change the configurations of other items as needed. For details about the configuration items, see http://www.php.net/manual/en/install.fpm.configuration.php. At the same time, there is a relatively complete configuration available on GitHub: https://github.com/vladgh/VladGh.com/blob/master/php-fpm.conf
It can be used as a reference.
Second:Configure init. d. php-FPM
To change the file as the Startup File, you must configure the variable values at the beginning, including:
1. php_fpm_bin: point to the installed PHP Directory/sbin/PHP-FPM
2. php_fpm_conf: point to the installed PHP Directory/etc/php-fpm.conf {if you are not calling this configuration file, follow here to configure the name for you really}
3. php_fpm_pid: point to the PID storage path of PHP-FPM.
After that, copy the file to the/etc/init. d directory. This document uses the method of creating a soft link:
# sudo ln -s /usr/local/php5/etc/init.d.php-fpm /etc/init.d/php-fpm# sudo update-rc.d -f php-fpm defaults
Then:Configure PHP
I use PHP. ini-development, and almost no configuration is required.
Finally:Configure nginx. conf
After completing the preceding steps, you need to configure nginx to run php, as shown in the following Configuration:
Server:
1. Root HTML:This configuration specifies the directory of the script program, which is set to root/home/WWW
2. Identify the. php file:
location / { index index.html index.htm index.php; }
3. parse the PHP script:You only need to remove the comment.
location ~ \.php$ { fastcgi_pass unix:/usr/local/php5/var/run/php-fpm.socket; #127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Note: fastcgi_pass here, followed by the php-fpm.conf configured listen consistent, in listen I configured Socket mode, so this is also configured here.
Start the service:
# sudo /etc/init.d/nginx restart# sudo /etc/init.d/php-fpm start
Enter localhost on the webpage to view the information:
If necessary, you can add it to the system path:
# Sudo Vim/etc/bash. bashrc // Add the following if [-d "/usr/local/PhP5/bin"] & [-d "/usr/local/PhP5/sbin"] at the end; then Path = "$ path:/usr/local/PhP5/bin:/usr/local/PhP5/sbin" fi
Iv. Virtual Machine Configuration
Nginx virtual machine configuration is actually quite simple. Open nginx. conf and add it to HTTP {}.Include/usr/local/nginx/CONF/virtual_sites.conf;(It can also be a file in a folder, such as sites/*. conf)
Then configure the required Virtual Machine in virtual_sites.conf:
server { listen 80; server_name p9.xxx; root /home/www/p9/www; location / { index index.html index.htm index.php; } location ~ \.php$ { fastcgi_pass unix:/usr/local/php5/var/run/php-fpm.socket; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; }}
Then bind p9.xxx to hosts. An available virtual machine configuration may be like this.Http://wiki.nginx.org/NginxVirtualHostExample