Home >Backend Development >PHP Tutorial >Detailed explanation of nginx multi-version php

Detailed explanation of nginx multi-version php

小云云
小云云Original
2018-03-10 11:22:552439browse

This article mainly shares with you nginx multi-version php. The article mainly teaches you the installation steps and hopes to help you.

php7.2 official website download tar -xzvf...

Install whatever you have few dependencies

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

Compile and install

make ZEND_EXTRA_LIBS='-liconv' && make install

Copy related files

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

Configure alias

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

Add to Environment variables

vim /etc/profilePATH=$PATH:/usr/local/php72/bin/72export PATH

Make changes take effect

source /etc/profile

Modify the corresponding pecl configuration

pecl72 config-set php_ini /usr/local/php72/etc/php.ini  # 发现配置不生效

~ The /.pearrc file is the cache file of the pecl configuration file. The php_ini is automatically modified after the extension is installed. The modified value of the php.ini item can take effect.

Install the swoole extension

pecl72 install swoole

Install memcached extension

yum install -y libmemcached-devel libmemcachedpecl72 install memcached输入 libmemcached-dir/usr

Install event extension

pecl72 install event    # 全部默认值

Install mongodb extension

pecl72 install mongodb

Install rdkafka extension

pecl72 install rdkafka

Install redis extension

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

Install mcrypt extension; because php7.2 will mcrypt has removed the core package. The mcrypt library has not been updated for a long time. It is officially recommended to use open_ssl's

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

to install trie_filter.so to filter sensitive lexicon

# 依赖 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"

Check if there are any errors and the modules are installed correctly

php72 -m

Modify the www.conf configuration file under /usr/local/php72/etc/php-fpm.d

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

Start php-fpm72

/etc/init.d/php-fpm72 start

Configure php-fpm72 to start automatically at boot

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

nginx conf Add enable-php72.conf to the folder with the following content

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

Modify the permissions of php-cgi72.sock and the group owner

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

The above is the detailed content of Detailed explanation of nginx multi-version php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn