linux下编译安装nginx 1.x,php5.x,phpmyadmin 以及多版本php共存

可以执行 yum命令来安装先决软件:

yum install libxml2 libxml2-devel curl-devel free-type-devel

1)安装pcre

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz

tar -zxvf pcre-8.20.tar.gz

/configure && make && make install

2)安装zlib-1.2.3

wget http://www.zlib.net/zlib-1.2.3.tar.gz

/configure && make && make install

3)安装libxml2-2.7.6

wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz

/configure && make && make install

4)安装openssl

wget http://openssl.org/source/openssl-1.0.1a.tar.gz

./config --prefix=/usr/local/ssl-1.0.0 shared zlib-dynamic enable-camellia

make && make install

----------------

或者以上都用  : yum install libxml2 libxml2-devel curl-devel free-type-devel

 

5)安装nginx1.3.5

wget http://nginx.org/download/nginx-1.3.5.tar.gz

./configure --prefix=/opt/lnmp/nginx  --with-openssl=/usr/include  --with-pcre=/data/system/pcre

 make && make install

启动nginx

ps -efww|grep nginx |grep -v grep|cut -c 9-15|xargs kill -9 (强制停止服务)

cd /opt/lnmp

./nginx

6)下载,编译PHP5.3.18,由于php5.3已经自带了php-fpm源码,所以直接enable就可以了。

mkdir /opt/lnmp/php5/etc(首先要建立此目录)

./configure --prefix=/opt/lnmp/php5 --with-pear=/usr/share/php --with-zlib-dir --with-libxml-dir=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/opt/lnmp/php5/etc --with-iconv --disable-ipv6 --enable-static --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap  --with-gettext --enable-sysvsem --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect  --with-curl=/usr/lib --with-curlwrappers --enable-mbregex --enable-bcmath --enable-shmop --enable-suhosin --with-fpm --with-libevent=shared  --enable-pdo=shared --with-pdo-mysql=shared --with-gd --with-mcrypt --enable-zip --enable-soap --enable-mime-magic --enable-cgi --enable-xml --enable-ftp --enable-json --enable-ctype --enable-gd-native-ttf

6.1)make && make install

6.2)cp php.ini-production   /opt/lnmp/php/etc/php.ini

7)启动/php-fpm

7.1)cp /opt/lnmp/php5/etc/php-fpm.conf.default   /opt/lnmp/php5/etc/php-fpm.conf

7.2)/opt/lnmp/php5/sbin/php-fpm -c /opt/lnmp/php5/etc/php.ini

然后可以测试下9000端口: netstat -ano|grep :9000,说明php-fpm作为一个进程已经启动了

停止php-fpm进程用: kill -USR2 `cat /data/system/php5/var/run/php-fpm.pid`

如果以后修改了php.ini,记得要重新启动 php-fpm,才能使之生效!

8)编辑nginx配置文件

vi ../conf/nginx.conf

打开 '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  /opt/lnmp/nginx/html/$fastcgi_script_name; (注意此处的路径要对)
            include        fastcgi_params;
        }

9)编辑nginx配置文件支持虚拟主机+ PHP

 vi ../conf/nginx.conf

   -------------

   server {
        listen   80;
        server_name  test.nginx.com  alias  test2.nginx.com;

        location / {
            root   /opt/lnmp/nginx/html/vhost/test/;
            index  index.html index.htm index.php;
        }
        location ~ \.php$ {
            root            /opt/lnmp/nginx/html/vhost/test/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /opt/lnmp/nginx/html/vhost/test/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

9.1) 如果要安装phpmyadmin作为虚拟目录,同时支持php,那么可以添加如下配置:

        location /phpmyadmin/ {
            alias /data/www/phpmyadmin/;
            index  index.html index.htm index.php;
        }
        
        location ~ ^/phpmyadmin/.+\.php$ {
            rewrite /phpmyadmin/(.+\.php) /$1 break;

            #above line is important !!!

            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www/phpmyadmin$fastcgi_script_name;
        }

 

10)安装另外一个版本php5.4.8

其实就是启动2个php-fpm.修改另一版本的php-fpm.conf里端口号为9001,然后启动,再nginx.conf里被调用。

具体步骤省略。

11)给php添加模块:

cd /opt/lnmp/source/php-5.3.18/ext/curl/

/opt/lnmp/php5/bin/phpize
./configure --with-php-config=/opt/lnmp/php5/etc/

make&&make install

...

12) Wordpress 在nginix下安装要点,在wordpress的location中添加如下配置代码: 

if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
    rewrite (.*) /index.php;
}

-/etc/init.d/nginx自启动-------------

#!/bin/sh
#nx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /var/run/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

 

参考:

http://ixdba.blog.51cto.com/2895551/806622

http://hi.baidu.com/travel981cn/item/bd198c578cdb269509be172f

http://www.080909.com/wordpress/2010/01/centos-install-nginx-0-8-30-php-5-3-1-mysql-5-5-0/

http://www.cnblogs.com/wangbin/archive/2011/01/06/1927037.html

http://blog.linuxeye.com/321.html (Nginx开机自动启动)

转载于:https://www.cnblogs.com/youcanwin/archive/2012/11/07/2758546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值