: This article describes how to install php in Linux and configure it to nginx. For more information about PHP tutorials, see. 1. Download
Libxml2-2.6.32.tar.gz http://download.csdn.net/detail/netlong339/1351852
Php-5.3.16.tar.gz http://download.csdn.net/detail/aiyunbreak/5366061
2. create the target folder
Mkdir/usr/local/php
That is to say, wait for the php to be installed in this folder.
3. decompress the package:
Place the downloaded file on a server, for example,/root/xiebin.
First install libxmlto decompress libxml2-2.6.32.tar.gz,
tar -zxvf libxml2-2.6.32.tar.gz
Cd/root/xiebin/libxml2-2.6.32
Run:./configure
Execute: make
Run: make install
② Install php, decompress tar-zxvf php-5.3.16.tar.gz
Cd/root/xiebin/php-5.3.16
Run :. /configure -- prefix =/usr/local/php -- with-libxml-dir =/usr/local/libxml2 -- enable-fpm -- with-fpm-user = www -- with-fpm -group = www -- with-libevent-dir = libevent
This is extremely important. php and later support php-fpm startup. if it is not configured, php cannot be started later. [it doesn't matter if apache is used as the server, but we are nginx now]
./configure --prefix=/usr/local/php --with-libxml-dir=/usr/local/libxml2 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-libevent-dir=libevent
Execute: make
Run: make install
4. configuration file
① Ini file: copy php. ini-development from the installation file to/usr/local/php/lib.
Cp/root/xiebin/php-5.3.16/php. ini-development/usr/local/php/lib
Rename the file to php. ini. the tool I use is WinScp, which can be renamed directly by F2. Therefore, I usually copy the file first and name it in F2.
The message "not find" is displayed when you directly run cp.
② Php-fpm File: php has Integrated php-fpm since 5.3. this is very important !!! The following code is used to start php.
Rename the php-fpm.conf.default to the php-fpm.conf, that is, remove. default
Modify the configuration in php-fpm: replace www with root in line 2
Row 3 user = root
Group = root
5. start php: Actually starting php-fpm
/Usr/local/php/etc/php-fpm
Here you will encounter a problem: please specify user and group other than root
FPM initialation failed
An error is reported, indicating that the user and group running php-fpm can only select others except root.
View the php-fpm document and you will find one of the options:-R
So the correct start should be:/usr/local/php/etc/php-fpm-R
/usr/local/php/etc/php-fpm -R
Check whether startup is successful:
Netstat-lnt | grep 9000
netstat -lnt | grep 9000
Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN
You can also run the following command to check whether Port 9000 is occupied by php-fpm:
Netstat-tunpl | grep 9000
Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN 2124/php-fpm
5. nginx configuration
Add a section in the nginx configuration file
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
Location ~ \. Php $ {
Root/www/web /;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
# Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
Fastcgi_param SCRIPT_FILENAME/www/web/$ fastcgi_script_name;
Include fastcgi_params;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {root /www/web/;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;fastcgi_param SCRIPT_FILENAME /www/web/$fastcgi_script_name;include fastcgi_params;}
Ps: How to locate nginx: # whereis nginx. conf
Run the following command: find the name of the which nginx executable file.
After configuring nginx, run:/usr/sbin/nginx-s reload
/usr/sbin/nginx -s reload
Write a test page
Echo ("this is my first php pagesss ");
?>
The above describes how to install php in Linux and configure it to nginx, including some content. I hope my friends who are interested in the PHP Tutorial can help me.