(1) Installation Nginx1.5.2
Update Nginx and PHP dependency packages
Yum-y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng \
Libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel \
glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel \
Curl Curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel \
OpenSSL openssl-devel openldap openldap-devel nss_ldap openldap-clients \
Openldap-servers gd gd2 gd-devel gd2-devel Perl-cpan
Pcre Libraries required to install 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 www
Create a Web root and modify permissions, of course, you can specify a different directory, as long as the Nginx configuration file consistent
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; for user www www;
Modify the root HTML in location/{}; For the site directory such as/data0/htdocs/www
Create a index.html file anywhere in the/data0/htdocs/www directory
Start Nginx and access the test
Ulimit-shn 65535
Here we go.
/usr/local/webserver/nginx/sbin/nginx
Other commands:
Test that the Nginx configuration file is correct/usr/local/webserver/nginx/sbin/nginx-t
After modifying the Nginx configuration file, make it effective/usr/local/webserver/nginx/sbin/nginx-s reload
(2) Installing PHP
The dependencies required to install 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.. /
Make a symbolic link to a shared library
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.8
Ln-s/USR/LOCAL/LIB/LIBMHASH.A/USR/LIB64/LIBMHASH.A
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 is large, you can 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
For
user = www
Group = www
PID = run/php-fpm.pid; Remove and fix to
PID =/usr/local/webserver/php/var/run/php-fpm.pid
Start PHP-FPM
/usr/local/webserver/php/sbin/php-fpm
(3) Configuration Nginx support PHP, and support PathInfo
Vi/usr/local/webserver/nginx/conf/fastcgi.conf
Put Fastcgi_param script_name $fastcgi _script_name, pre-add # comment
and add at the top
#------------------------------------------------------
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 $;
Set $path _info;
}
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 effective
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 self-start
Vi/etc/rc.local
Input
Ulimit-shn 65535
/usr/local/webserver/php/sbin/php-fpm
/usr/local/webserver/nginx/sbin/nginx
=====================================================
compiling PHP extension Modules memcache, 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
to look for; Extension_dir = "/" to be preceded; removed and modified to
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
Execute KILL-USR2 ' cat/usr/local/webserver/php/var/run/php-fpm.pid '
Make the configuration file effective
------------------------------------------------------------------
(4) Other configuration and optimization of Nginx
To put on the front; remove open gzip compression
and add detailed parameters
Gzip_min_length 1k;
Gzip_buffers 64k;
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 the requests to index.php, add the following code to location/{}
if (!-e $request _filename) {
Rewrite ^ (. *) $/index.php/$1 last;
}
Nginx1.5 and PHP5.5 Installation documentation