1.系統環境php
centos6.3_x64html
nginx: 1.1.5mysql
php:php-5.4.14nginx
############################################c++
2.環境安裝web
#yum 安裝系統環境所須要的軟件包sql
yum -y install yum-fastestmirror ntpapache
yum -y install patch make flex bison tarvim
yum -y install libtool libtool-libs kernel-devel centos
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
./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
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
啓用以下幾行,即去掉前面的分號(;)
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,能瀏覽,安裝成功了。