This is the Nginx and PHP installation notes that the webmaster recorded when they installed the server at one time in 2011. Installation process records are simple, just a rough flow, some details are not detailed description, please forgive me, I will be in the future to reorganize a detailed installation process, this article is for reference only!
Software Environment: CentOS 5.7 + PHP 5.2.17 + Nginx 0.8.55
1. Compile and install PHP and PHP-FPM
Tips:
Install PHP before you should install MySQL, the specific method please Baidu or Google;
PHP need to support the installation of the library does not do too much introduction, can be online search reference related tutorials to install.
Download the PHP-FPM source package corresponding to the current PHP version from http://php-fpm.org/downloads/, for example: php-5.2.17-fpm-0.5.14.diff.gz
Tar zxvf php-5.2.17.tar.gz
GZIP-CD php-5.2.17-fpm-0.5.14.diff.gz | Patch-d PHP-5.2.17-P1
CD php-5.2.17
./configure–prefix=/usr/local/php/–with-config-file-path=/usr/local/php/etc–with-mysql=/usr/local/mysql/– with-pdo-mysql=/usr/local/mysql/–with-gd–with-zlib–with-curl–with-jpeg-dir–with-png-dir–with-libxml-dir– With-freetype-dir–with-iconv=/usr/local–with-mcrypt–enable-fastcgi–enable-fpm–enable-xml–enable-mbstring
Make
Make install
CP Php.ini-dist/usr/local/php/etc/php.ini
Note: The –enable-fastcgi in the PHP compilation parameters above must be turned on.
2. Create user and user groups used by Nginx
Groupadd www
Useradd-g www www
3. Create a Site directory and set permissions
Mkdir-p/htdocs/www
chmod +w/htdocs/www
Chown-r www:www/htdocs/www
4. PCRE Library for installing Nginx
Tar zxvf pcre-8.13.tar.gz
CD pcre-8.13
./configure
Make
Make install
5. Install Nginx
Tar zxvf nginx-0.8.55.tar.gz
CD nginx-0.8.55
./configure–prefix=/usr/local/nginx–with-http_stub_status_module–with-http_ssl_module–user=www–group=www
Make
Make install
6. Configure Nginx to create a virtual host
In the http{...} section of the nginx.conf file, add a server{...} segment, such as the following code:
server {
Listen 80;
server_name www.youdomain.com; #你的域名
root/htdocs/www;
Access_log Logs/www.access.log;
Location/{
Index index.html index.php;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
Location ~. *\.php?$ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}
Location ~/nginx_info {
Access_log off;
Stub_status on;
}
}
Note: In the above configuration, add location ~/nginx_info {...}, so that you can query Nginx state information by http://www.youdomain.com/nginx_info/.
Start PHP-FPM
/USR/LOCAL/PHP/SBIN/PHP-FPM start
Start Nginx
/usr/local/nginx/sbin/nginx