1.系统环境
centos6.3_x64
nginx: 1.1.5
php:php-5.4.14
############################################
2.环境安装
#yum 安装系统环境所需要的软件包
yum -y install yum-fastestmirror ntp
yum -y install patch make flex bison tar
yum -y install libtool libtool-libs kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel
yum -y install libtiff libtiff-devel gettext gettext-devel
yum -y install libxml2 libxml2-devel zlib-devel net-snmp
yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel
yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal unzip
# 安装PHP支持GD库模块
yum -y install freetype freetype-devel png jpeg zlib gd php-gd*
# 安装PHP 5.* 组件
yum -y install libiconv libevent mhash mcrypt
# 安装MYDSQL所需要系统库相关库文件
yum install -y gcc gcc-c++ gcc-g77 autoconf automake fiex* ncurses-devel libmcrypt* libtool-ltdl-devel*
# 安装NGINX 组件
yum -y install pcre*
####################################
3.PHP安装
php和nginx的整合是通过php-FastCGI
FastCGI 是一个可伸缩、高速的在web server和脚本语言间通迅的接口。被许多脚本语言所支持,包括 php多数流行的web server都支持 FastCGI。
正常情况下,nginx和php直接是完全不认识的,我们就是通过php-fastcgi将二者整合。
php5.3.0之前的版本,php-FastCGI 是需要单独安装的。但是在这之后,php-FastCGI 就整合在了php的源码包中,不必再去单独安装。在这里我用的就是php5.3.8的版本,内置了php-fpm ,编译时开启,并且编译后存在 php-cgi 文件了。
注意:PHP编译支持php-fpm功能就不能编译支持apache的apxs模块功能,不然报错。
tar jxf php-5.4.14.tar.bz2 && cd php-5.4.14
1 | ./configure '--prefix=/usr/local/php' '--with-iconv' '--with-mysql' '--with-mysqli' '--with-gd' '--with-zlib' '--with-jpeg-dir=/usr/lib64' '--with-png-dir' '--with-freetype-dir=/usr/lib64' '--with-curl=/usr/bin' '--with-openssl' '--with-openssl-dir=/usr' '--with-xsl=/usr' '--with-xmlrpc' '--enable-exif' '--enable-cli' '--enable-calendar' '--with-mhash' '--enable-mbstring' '--enable-mbregex' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-zip' '--enable-ftp' '--with-pear' '--disable-debug' '--with-bz2' '--with-mcrypt' '--with-mhash' --disable-cgi --enable-bcmath --enable-libxml -- with -libxml-dir -- with -gettext --enable-pcntl --enable-inline-optimization --disable-ipv6 --enable-fpm --enable-ftp --enable-gd- native -ttf |
make && make install
cp php-5.4.14/php.ini-production /usr/local/php/lib/php.ini
12 | date.timezone = "Asia/Shanghai" short_open_tag = On |
# cd /usr/local/php/etc/ # 切换到安装目录下的配置文件目录
# cp php-fpm.conf.default php-fpm.conf
# vi php-fpm.conf
启用如下几行,即去掉前面的分号(;)
12345678910111213141516 | pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice listen = 127.0 . 0.1 : 9000 listen.allowed_clients = 127.0 . 0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp |
wq保存退出
# /usr/local/php/sbin/php-fpm (启动PHP)
# netstat -antpl (如果看到9000端口,PHP-FPM配置成功)
注意:如果修改php.ini文件,则需要重启php-fpm进程使生效。
###########################################################
4.nginx安装
wget -c http://nginx.org/download/nginx-1.1.5.tar.gz
tar zxf nginx-1.1.5.tar.gz && cd nginx-1.1.5
./configure --prefix=/usr/local/nginx -- with -http_stub_status_module -- with -http_ssl_module -- with -http_gzip_static_module -- with -pcre --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --http-uwsgi-temp-path=/tmp/nginx/uwsgi --http-scgi-temp-path=/tmp/nginx/scgi |
make && make install
NGINX 配置文件设置:这个配置只是让NGX和PHP关联起来
/usr/local/nginx/conf/nginx.conf
user nginx nginx ; (nginx 用户需要新建,注释掉也OK的) worker_processes 8 ; #error_log logs/error.log; //默认在/usr/local/nginx/logs/error.log error_log / var /log/5aixue_error.log; //指定日志路径 #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 2048 ; } http { include mime.types; default_type application/octet-stream; charset utf- 8 ; //设置字符集 sendfile on; keepalive_timeout 65 ; server { listen 80 ; server_name test1.5aixue.com; //网站域名 root /home/aixue/public_html/; //网站路径 index index.php index.html index.htm ; //index.php 一定要放在前面 # pass the PHP scripts to FastCGI server listening on 127.0 . 0.1 : 9000 location ~ \.php$ { # root html; fastcgi_pass 127.0 . 0.1 : 9000 ; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; include fastcgi.conf; } location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php last; } } client_max_body_size 10M; //上传文件大小,nginx默认是1M,只修改php,ini文件中的大小是不生效的,nginx也要同步设置。 } } |
5.测试启动nginx
mkdir -p /tmp/nginx/proxy
cd /usr/local/nginx/sbin
./nginx -t 检测
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
./nginx 启动nginx
在/home/aixue/public_html/ 中编写Index.php文件
<?
phpinfo();
?>
打开浏览器 http://IP/index.php,能浏览,安装成功了。