首頁  >  文章  >  後端開發  >  nginx多版php詳解

nginx多版php詳解

小云云
小云云原創
2018-03-10 11:22:552416瀏覽

本文主要跟大家分享的是nginx 多版 php,文中主要教大家安裝的步驟希望能幫助大家。

php7.2 官網下載tar -xzvf …

依賴少什麼就安裝什麼##
yum -y install readline-devel libxslt libxslt-devel./configure --prefix=/usr/local/php72 \--exec-prefix=/usr/local/php72 \--with-config-file-path=/usr/local/php72/etc \--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-libxml-dir \--with-xmlrpc \--with-openssl \--with-mhash \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--with-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-zlib-dir \--with-freetype-dir \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--enable-zip \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache

#編譯安裝
make ZEND_EXTRA_LIBS='-liconv' && make install

拷貝相關檔案
cp php.ini-production /usr/local/php72/etc/php.inicp /usr/local/php72/etc/php-fpm.conf.default /usr/local/php72/etc/php-fpm.confcp /usr/local/php72/etc/php-fpm.d/www.conf.default /usr/local/php72/etc/php-fpm.d/www.confcp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm72cp sapi/fpm/init.d.php-fpm /usr/local/php72/bin/php-fpm72chmod +x /etc/init.d/php-fpm72

設定別名
mkdir /usr/local/php72/bin/72cp /usr/local/php72/bin/php /usr/local/php72/bin/72/php72cp /usr/local/php72/bin/pecl /usr/local/php72/bin/72/pecl72cp /usr/local/php72/bin/php-cgi /usr/local/php72/bin/72/php-cgi72cp /usr/local/php72/bin/php-config /usr/local/php72/bin/72/php-config72cp /usr/local/php72/bin/phpize /usr/local/php72/bin/72/phpize72

加入到環境變數
vim /etc/profilePATH=$PATH:/usr/local/php72/bin/72export PATH

使改變生效
source /etc/profile

修改對應的pecl 設定
pecl72 config-set php_ini /usr/local/php72/etc/php.ini  # 发现配置不生效

#~~ /.pearrc 檔案是pecl 的設定檔的快取檔案, 其中的php_ini 是安裝完擴充後自動修改php.ini 項目的修改其值可生效

安裝swoole 擴充功能
pecl72 install swoole

安裝memcached 擴充功能
yum install -y libmemcached-devel libmemcachedpecl72 install memcached输入 libmemcached-dir/usr

安裝event 擴充功能##
pecl72 install event    # 全部默认值

安裝mongodb 擴充功能

pecl72 install mongodb

安裝rdkafka 擴充功能

pecl72 install rdkafka

#安裝redis 擴充功能

pecl72 install redis# 会问是否开启压缩, 建议不开启 回车默认值

安裝mcrypt 擴充功能; 因為php7.2 將mcrypt 移除了核心套件, mcrypt庫很久沒有更新了官方建議用open_ssl的

pecl72 install channel://pecl.php.net/mcrypt-1.0.1  # 回车默认值

安裝trie_filter.so 過濾敏感詞庫

# 依赖 libdatrie 库 需要提前安装# 参考# https://github.com/zzjin/php-ext-trie-filter/tree/php7# 注意 phpize ---> phpize72; --with-php-config=/usr/local/php72/bin/php-configphpize72./configure --with-php-config=/usr/local/php72/bin/php-configmake && make install# 修改对应的 php.ini 添加 extension="trie_filter.so"

#檢查一下是否有錯誤模組是否都正確安裝了

php72 -m

修改/usr/local/php72/etc/php-fpm.d 下的www.conf 設定檔

大概 36 行listen = /tmp/php-cgi72.sock

啟動php-fpm72

/etc/init.d/php-fpm72 start

設定php-fpm72 開機自啟動

chkconfig --add php-fpm72chkconfig php-fpm72 onchkconfig # 检查一下

nginx conf資料夾下新增enable-php72.conf 內容如下

location ~ [^/]\.php(/|$){fastcgi_index index.php;fastcgi_pass unix:/tmp/php-cgi72.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}

nginx -t ok nginx reload

##修改php-cgi72.sock 的權限和所屬組所屬者

chmod 755 /tmp/php-cgi72.sockchown www:www /tmp/php-cgi72.sock

以上是nginx多版php詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn