Home  >  Article  >  Backend Development  >  Teach you to install php7 and coexist with php5

Teach you to install php7 and coexist with php5

藏色散人
藏色散人forward
2021-02-24 17:56:382110browse

Recommended: "PHP7"

Install php7 and coexist with php5

Start

Before The server has built a lamp environment. I want to switch to the more powerful nginx as the server software, and I want to upgrade php5 to php7.
No need to go into details when installing nginx: sudo apt-get install nginx, modify the apache port before starting ng.

Install php7

Download the source code at http://php.net/downloads.php and unzip it.

# cd php7***
# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache

# make
# make install

In order not to conflict with 5, all folders use php7, and the dependencies of the installation response when errors are reported during the installation process.

Connecting to nginx

nginx itself cannot process PHP scripts and needs to be sent to the PHP interpreter for processing. nginx generally sends the request to the fastcgi management process for processing. The fascgi management process selects the cgi sub-process processing result and returns it to nginx.

# cp php.ini-production /usr/local/php7/etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
# chmod +x /etc/init.d/php7-fpm
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

Start php-fpm

# service php7-fpm start

If you encounter a log file path that does not exist, create it manually and give it write permission.

# service php7-fpm start
Starting php-fpm [07-Apr-2016 11:16:11] ERROR: [pool www] cannot get gid for group 'nobody'
[07-Apr-2016 11:16:11] ERROR: FPM initialization failed
 failed

When encountering this error, add a nobody groupgroupadd nobody and then restart.

nginx configuration

This is when accessing the php file, it becomes a download file, because ng is not configured for response processing.

location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

The above is the detailed content of Teach you to install php7 and coexist with php5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete