(1) install Nginx1.5.2
Update Nginx and PHP dependent packages
Yum-y install gcc-c ++ autoconf libjpeg-devel libpng \
Libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel \
Glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses-devel \
Curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel \
Openssl-devel openldap-devel nss_ldap openldap-clients \
Openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN
Install the pcre library required by Nginx
Tar zxvf pcre-8.33.tar.gz
Cd pcre-8.33
./Configure
Make & make install
Ln-s/usr/local/lib/libpcre. so.1/usr/lib64/libpcre. so.1
Cd ../
Tar zxvf nginx-1.5.2.tar.gz
Cd nginx-1.5.2
./Configure -- user = www -- group = www -- prefix =/usr/local/webserver/nginx -- with-http_stub_status_module \
-- With-http_ssl_module -- with-http_realip_module -- with-http_image_filter_module
Make
Make install
/Usr/sbin/groupadd www
/Usr/sbin/useradd-g www
Create a web root directory and modify permissions. You can specify other directories as long as they are consistent with the Nginx configuration file.
Mkdir-p/data0/htdocs/www
Chmod + w/data0/htdocs/www
Chown-R www: www/data0/htdocs/www
Vi/usr/local/webserver/nginx/conf/nginx. conf
Modify # user nobody; to user www;
Modify the root html in location/{} to the website directory such as/data0/htdocs/www.
Create an index.html file in the/data0/htdocs/wwwdirectory.
Start nginx and access the test
Ulimit-SHn 65535
/Usr/local/webserver/nginx/sbin/nginx
Other commands:
Test whether the nginx configuration file is correct/usr/local/webserver/nginx/sbin/nginx-t
Modify the nginx configuration file to make it take effect/usr/local/webserver/nginx/sbin/nginx-s reload
(2) install PHP
Install the required dependency package for PHP
Tar zxvf libiconv-1.14.tar.gz
Cd libiconv-1.14
./Configure -- prefix =/usr/local
Make
Make install
Cd ../
Tar zxvf libmcrypt-2.5.8.tar.gz
Cd libmcrypt-2.5.8/
./Configure
Make
Make install
/Sbin/ldconfig
Cd libltdl/
./Configure -- enable-ltdl-install
Make
Make install
Cd ../../
Tar zxvf mhash-0.9.9.9.tar.gz
Cd mhash-0.9.9.9/
./Configure
Make
Make install
Cd ../
Symbolic links to shared libraries
Ln-s/usr/local/lib/libmcrypt. la/usr/lib64/libmcrypt. la
Ln-s/usr/local/lib/libmcrypt. so/usr/lib64/libmcrypt. so
Ln-s/usr/local/lib/libmcrypt. so.4/usr/lib64/libmcrypt. so.4
Ln-s/usr/local/lib/libmcrypt. so.4.4.8/usr/lib64/libmcrypt. So.4.4.4.8
Ln-s/usr/local/lib/libmhash. a/usr/lib64/libmhash.
Ln-s/usr/local/lib/libmhash. la/usr/lib64/libmhash. la
Ln-s/usr/local/lib/libmhash. so/usr/lib64/libmhash. so
Ln-s/usr/local/lib/libmhash. so.2/usr/lib64/libmhash. so.2
Ln-s/usr/local/lib/libmhash. so.2.0.1/usr/lib64/libmhash. so.2.0.1
Ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config
Ln-s/usr/local/webserver/mysql/lib/libmysqlclient. so.18/usr/lib64/libmysqlclient. so.18
Tar zxvf mcrypt-2.6.8.tar.gz
Cd mcrypt-2.6.8/
/Sbin/ldconfig
./Configure
Make
Make install
Cd ../
Tar zxvf php-5.5.0.tar.gz
Cd php-5.5.0
./Configure -- prefix =/usr/local/webserver/php -- with-config-file-path =/usr/local/webserver/php/etc \
-- With-mysql =/usr/local/webserver/mysql -- with-mysqli =/usr/local/webserver/mysql/bin/mysql_config \
-- With-iconv-dir -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib -- with-libxml-dir =/usr \
-- Enable-xml -- disable-rpath -- enable-bcmath -- enable-shmop -- enable-sysvsem -- enable-inline-optimization \
-- With-curl -- enable-mbregex -- enable-fpm -- enable-mbstring -- with-mcrypt -- with-gd -- enable-gd-native-ttf \
-- With-openssl -- with-mhash -- enable-pcntl -- enable-sockets -- with-xmlrpc -- enable-zip -- enable-soap \
-- Enable-opcache = no -- without-pear -- disable-fileinfo
If the memory size is large, remove -- disable-fileinfo.
Make ZEND_EXTRA_LIBS = '-liconv'
Make install
Cp php. ini-development/usr/local/webserver/php/etc/php. ini
Cd ../
Cp/usr/local/webserver/php/etc/php-fpm.conf.default/usr/local/webserver/php/etc/php-fpm.conf
Modify
User = nobody
Group = nobody
Is
User = www
Group = www
Remove; pid = run/php-fpm.pid; and change
Pid =/usr/local/webserver/php/var/run/php-fpm.pid
Start php-fpm
/Usr/local/webserver/php/sbin/php-fpm
(3) Configure Nginx to support PHP and pathinfo
Vi/usr/local/webserver/nginx/conf/fastcgi. conf
Add the fastcgi_param SCRIPT_NAME $ fastcgi_script_name; prefix with # Comment
Add
#------------------------------------------------------
Fastcgi_pass 127.0.0.1: 9000;
# Fastcgi_index index. php;
Set $ path_info "";
Set $ real_fastcgi_script_name $ fastcgi_script_name;
If ($ fastcgi_script_name ~ "^ (. +? \. Php) (/. +) $ "){
Set $ real_fastcgi_script_name $1;
Set $ path_info $2;
}
Fastcgi_param SCRIPT_NAME $ real_fastcgi_script_name;
Fastcgi_param PATH_INFO $ path_info;
#------------------------------------------------------
Vi/usr/local/webserver/nginx/conf/nginx. conf
Locate location/{***} in the first server and add
#------------------------------------------------------
Location ~ *. * \. Php ($ | /){
Include fastcgi. conf;
}
#------------------------------------------------------
Make the configuration file take effect
Kill-USR2 'cat/usr/local/webserver/php/var/run/php-fpm.pid'
/Usr/local/webserver/nginx/sbin/nginx-s reload
Add Nginx and fpm to auto-start
Vi/etc/rc. local
Input
Ulimit-SHn 65535
/Usr/local/webserver/php/sbin/php-fpm
/Usr/local/webserver/nginx/sbin/nginx
========================================================== ==================
Compile the PHP Extension ModuleMemcache, pdo_mysql, imagick
Tar zxvf memcache-2.2.7.tgz
Cd memcache-2.2.7
/Usr/local/webserver/php/bin/phpize
./Configure -- with-php-config =/usr/local/webserver/php/bin/php-config
Make
Make install
Cd ../
Tar zxvf PDO_MYSQL-1.0.2.tgz
Cd PDO_MYSQL-1.0.2/
/Usr/local/webserver/php/bin/phpize
./Configure -- with-php-config =/usr/local/webserver/php/bin/php-config -- with-pdo-mysql =/usr/local/webserver/mysql
Ln-s/usr/local/webserver/mysql/include/*/usr/local/include/
Make
Make install
Cd ../
Tar zxvf ImageMagick.tar.gz
Cd ImageMagick-6.5.1-2/
./Configure
Make
Make install
Cd ../
Tar zxvf imagick-3.1.0RC2.tgz
Cd imagick-3.1.0RC2
/Usr/local/webserver/php/bin/phpize
Export PKG_CONFIG_PATH =/usr/local/lib/pkgconfig
./Configure -- with-php-config =/usr/local/webserver/php/bin/php-config
Make
Make install
Cd ../
Modify the php configuration file
Vi/usr/local/webserver/php/etc/php. ini
Search; extension_dir = "/" remove the previous one and change it
Extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20121212 /"
And join
Extension = memcache. so
Extension = pdo_mysql.so
Extension = imagick. so
Run kill-USR2 'cat/usr/local/webserver/php/var/run/php-fpm.pid'
Make the configuration file take effect
------------------------------------------------------------------
(4) other nginx configurations and optimizations
Before gzip on, remove and enable gzip compression.
Add detailed parameters
Gzip_min_length 1 k;
Gzip_buffers 16 64 k;
Gzip_http_version 1.1;
Gzip_comp_level 9;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
If you need to rewrite all requests to index. php, add the following code in location/{}:
If (! -E $ request_filename ){
Rewrite ^ (. *) $/index. php/$1 last;
}