溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Linux-rhel6.4 編譯安裝PHP,Nginx與php連接

發(fā)布時(shí)間:2020-06-29 13:56:45 來(lái)源:網(wǎng)絡(luò) 閱讀:937 作者:謝育政 欄目:建站服務(wù)器


確定依賴(lài)包安裝

gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel  

若沒(méi)安裝,掛載系統(tǒng)鏡像,從Packages文件夾里面找到安裝包安裝,或者有yum源的話(huà)可直接yum install安裝。


可利用鏡像自己制作本地yum源:http://kurol.blog.51cto.com/11433546/1927721


從官網(wǎng)獲取,編譯安裝

[root@kurolz ~]# wget http://de2.php.net/get/php-5.5.38.tar.gz/from/this/mirror 
[root@kurolz ~]# tar -zxvf php-5.5.38.tar.gz
[root@kurolz php-5.5.38]# ./configure --prefix=/usr/local/php-5.5.0 --with-config-file-path=/usr/local/php-5.5.0/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64

......
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

[root@kurolz ~]# make
[root@kurolz ~]# make install
[root@kurolz ~]# cd php-5.5.38
[root@kurolz php-5.5.38]# cp php.ini-production /usr/local/php-5.5.0/etc/php.ini
[root@kurolz php-5.5.38]# cd /usr/local/php-5.5.0/etc/
[root@kurolz etc]# cp php-fpm.conf.default php-fpm.conf
[root@kurolz etc]# cd /usr/local/php-5.5.0/sbin
[root@kurolz sbin]# ./php-fpm


Nginx與php連接

    要點(diǎn):  

        1:Nginx 默認(rèn)支持 fastcgi  

        2:php編譯開(kāi)啟模塊:  

            --enable-fpm  

    連接:  

[root@kurolz ~]# vim /usr/local/nginx/conf/nginx.conf
     server {  
            listen       80;  
            server_name  localhost;  
            location / {
                root   html;
                index  index.html index.php;
            }
            .......
            location ~ \.php$ {
                root   html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include   fastcgi_params;
            }
        }


重啟nginx:

[root@kurolz ~]# cd /usr/local/nginx/sbin
[root@kurolz sbin]# ./nginx -s reload


添加php測(cè)試文件:

[root@kurolz ~]# cd /usr/local/nginx/html
[root@kurolz ~]# touch info.php
[root@kurolz ~]# vim info.php
<?php
phpinfo();
?>


瀏覽器測(cè)試:

Linux-rhel6.4 編譯安裝PHP,Nginx與php連接



將pid文件存于var/run中

[root@kurolz ~]# vim /usr/local/php-5.5.0/etc/php-fpm.conf
pid = run/php-fpm.pid



配置開(kāi)機(jī)啟動(dòng)php-fpm

并可用service  php-fpm  [start | restart | stop]開(kāi)啟、重啟、關(guān)閉

[root@kurolz ~]# vim /etc/init.d/php-fpm


將下列腳本寫(xiě)入/etc/init.d/php-fpm中,12-15行的路徑自己修改

#!/bin/sh
       #
       # php-fpm - this script starts and stops the php-fpm daemin
       #
       # chkconfig: - 85 15
       # processname: php-fpm
       # config:      /usr/local/php/etc/php-fpm.conf
       set -e
       PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
       DESC="php-fpm daemon"
       NAME=php-fpm
       DAEMON=/usr/local/php-5.5.0/sbin/php-fpm 
       CONFIGFILE=/usr/local/php-5.5.0/etc/php-fpm.conf
       PIDFILE=/usr/local/php-5.5.0/var/run/php-fpm.pid
       SCRIPTNAME=/etc/init.d/php-fpm
       
       # If the daemon file is not found, terminate the script.
       test -x $DAEMON || exit 0
       d_start(){
           $DAEMON -y $CONFIGFILE || echo -n " already running"
       }
       d_stop(){
           kill -QUIT `cat $PIDFILE` || echo -n " no running"
       }
       d_reload(){
           kill -HUP `cat $PIDFILE` || echo -n " could not reload"
       }
       case "$1" in
           start)
               echo -n "Starting $DESC: $NAME"
               d_start
               echo "."
               ;;
           stop)
               echo -n "Stopping $DESC: $NAME"
               d_stop
               echo "."
               ;;
           reload)
               echo -n "Reloading $DESC configuration..."
               d_reload
               echo "Reloaded."
               ;;
           restart)
               echo -n "Restarting $DESC: $NAME"
               d_stop
               # Sleep for two seconds before starting again, this should give the nginx daemon some time to perform a graceful stop
               sleep 2
               d_start
               echo "."
               ;;
           *)
               echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2
               exit 3
               ;;
       esac
       exit 0


賦予php-fpm任何用戶(hù)可執(zhí)行權(quán)限

[root@kurolz ~]# chmod a+w /etc/init.d/php-fpm


設(shè)置開(kāi)機(jī)啟動(dòng)

[root@kurolz ~]# chkconfig php-fpm on


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI