Home  >  Article  >  Backend Development  >  Install php7 and coexist with php5

Install php7 and coexist with php5

藏色散人
藏色散人forward
2020-04-15 13:50:132076browse

Getting Started

I have built a lamp environment on the server before. I want to switch to nginx with stronger performance as the server software, and I also 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

The source code is downloaded from http://php.net/downloads.php and unzipped.

# 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 nobodygroupgroupadd 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;
        }

Thank you for using PHP.

The above is the detailed content of 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