下载相关的文件
- pcre-8.21.tar.bz2
- nginx-1.4.1.tar.gz
- php-5.3.27
PCRE
系统自带的PCRE版本太低了.所以需要卸载重装。
第一步:查看PCRE的版本
第二步:保留以前的libpcre.so.0,没有这个无法重装PCRE的
1
| $ sudo cp /lib/libpcre.so.0 /lib/libpcre.so.0.back
|
第三步:卸载PCRE
1
| $ sudo rpm -e --nodeps pcre-7.8-4.el6.i686 #这里的这个7.8-4.el6.i686-是我这里版本,要根据自己电脑修改
|
第四步:安装新的PCRE
1 2 3 4 5 6
| $ tar -xj -f pcre-8.21.tar.gz $ cd pcre-8.21 $ sudo mv /lib/libpcre.so.0.back /lib/libpcre.so.0 $ ./configure $ make $ sudo make install
|
Nginx
1 2 3 4
| $ ./configure --prefix=/usr/local/nginx $ make $ sudo make install $ sudo /usr/local/nginx/sbin/nginx
|
配置, 开启PHP支持
1
| $ sudo vim /usr/local/nginx/conf/nginx.conf
|
增加PHP主页
1 2 3 4
| location / { root html; index index.html index.php index.htm; }
|
开启PHP支持
1 2 3 4 5 6 7
| location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; include fastcgi_params; }
|
注意这里的fastcgi_pass 和 fastcgi_param的”/var/www”, fastcgi_pass是nginx请求到php的端口,而”/var/www”就是项目的存放路径
1
| $ sudo /usr/local/nginx/sbin/nginx
|
在浏览器输入https://127.0.0.1就可以查看Nginx的欢迎信息了
PHP
这里是最小化安装,所以就不配置什么插件了
Nginx 与 PHP的通信需要使用 PHP-FPM,在php5.3.3以后,PHP-FPM以及集成到了php,如果要使用的话,在编译的时候,加一句–enable-fpm
1 2 3 4
| $ sudo ./configure --prefix=/usr/local/php --enable-fpm $ sudo make $ sudo make test $ sudo make install
|
配置
1 2 3 4
| $ sudo cd /usr/local/php $ cp etc/php-fpm.conf.default etc/php-fpm.conf $ sudo vim etc/php-fpm.conf $ 找到[global],去掉";pid = run/php-fpm.pid"的注释
|
测试
我们之前提到了”/var/www”,我们在这里新建一个php文件,来测试环境是否搭建成功
1
| $ sudo vim /var/www/info.php
|
info.php
如果之前已经开启nginx服务器,现在就不用开了
1 2
| $ sudo /usr/local/nginx/sbin/nginx $ sudo /usr/local/php/sbin/php-fpm
|
编写快速启动和关闭的nginx与php脚本
示例:
1 2 3 4
| $ sudo vim /etc/init.d/php-fpm $ sudo chmod +x /etc/init.d/php-fpm $ sudo /sbin/chkconfig php-fpm on $ sudo /sbin/chkconfig --list php-fpm
|
成功的话
就可以看到好几个 on
测试
1 2 3
| $ sudo /etc/init.d/php-fpm stop $ sudo /etc/init.d/php-fpm start $ sudo /etc/init.d/php-fpm restart
|
php-fpm 脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #!/bin/bash # # Startup script for the PHP-FPM server. # # chkconfig: 345 85 15 # description: PHP is an HTML-embedded scripting language # processname: php-fpm # config: /usr/local/php/etc/php.ini
# Source function library. . /etc/rc.d/init.d/functions
PHP_PATH=/usr/local DESC="php-fpm daemon" NAME=php-fpm # php-fpm路径 DAEMON=$PHP_PATH/php/sbin/$NAME # 配置文件路径 CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf # PID文件路径(在php-fpm.conf设置) PIDFILE=$PHP_PATH/php/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed. test -x $DAEMON || exit 0
rh_start() { $DAEMON -y $CONFIGFILE || echo -n " already running" }
rh_stop() { kill -QUIT `cat $PIDFILE` || echo -n " not running" }
rh_reload() { kill -HUP `cat $PIDFILE` || echo -n " can't reload" }
case "$1" in start) echo -n "Starting $DESC: $NAME" rh_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" rh_stop echo "." ;; reload) echo -n "Reloading $DESC configuration..." rh_reload echo "reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" rh_stop sleep 1 rh_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3 ;; esac exit 0
|
nginx 脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #!/bin/bash # #chkconfig: - 85 15 #description: Nginx is a World Wide Web server. #processname: nginx
nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf
case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done" ;;
stop) echo -n "Stopping Nginx" killall -9 nginx echo " done" ;;
test) $nginx -t -c $conf ;;
reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done" ;;
restart) $0 stop $0 start ;;
show) ps -aux|grep nginx ;;
*) echo -n "Usage: $0 {start|restart|reload|stop|test|show}" ;;
esac
|