Home > Backend Development > PHP7 > body text

Teach you to install php7 and coexist with php5

藏色散人
Release: 2023-02-17 20:04:02
forward
2164 people have browsed it

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
Copy after login

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
Copy after login

Start php-fpm

# service php7-fpm start
Copy after login

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
Copy after login

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;
        }
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template