Nginx + php Installation 1. for nginx installation, see :? Qingwei201314.iteye. comblog1729174 2. install php: Get and unzip the PHP source code: tarzxfphp-x.x.x configuration and build PHP. In this step, you can use many options to customize PHP, such as enabling some extensions. Run the. configure -- help command nginx + php for installation.
1. for nginx installation, see :? Http://qingwei201314.iteye.com/blog/1729174
II. install php:
Obtain and decompress the PHP source code:
tar zxf php-x.x.x
Configure and build PHP. In this step, you can use many options to customize PHP, such as enabling some extensions. Run the./configure -- help command to obtain the complete list of available options. In this example, we only perform simple configuration that contains the PHP-FPM and MySQL support.
cd ../php-x.x.x./configure --enable-fpm --with-mysqlmakesudo make install
Create a configuration file and copy it to the correct location.
cp php.ini-development /usr/local/php/php.inicp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.confcp sapi/fpm/php-fpm /usr/local/bin
Note that, if the file does not exist, Nginx is prevented from sending requests to the backend PHP-FPM module to avoid malicious script injection attacks.
What are the configuration items in the php. ini file? Cgi. fix_pathinfo? Set?0?.
Open php. ini:
vim /usr/local/php/php.ini
Locate?Cgi. fix_pathinfo =? And modify it as follows:
cgi.fix_pathinfo=0
Before starting the service, you need to modify the php-fpm.conf configuration file to ensure that the php-fpm module runs as the www-data user and www-data user group.
vim /usr/local/etc/php-fpm.conf
Find and modify the following content:
; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's group; will be used.user = www-datagroup = www-data
Then start the php-fpm service:
/usr/local/bin/php-fpm
This document does not cover further configuration of php-fpm. For more information, see the relevant documentation.
Configure Nginx to support PHP applications:
vim /usr/local/nginx/conf/nginx.conf
Modify the default location block to support the. php file:
location / { root html; index index.php index.html index.htm;}Next configure to ensure that requests to the. php file will be sent to the back-end PHP-FPM module, uncomment the default PHP configuration block, and modify it to the following:
location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;}Restart Nginx.
- If thinkphp is used, configure pathinfo:
- Modify part of the content in step 1 as follows:
location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; }