Getting Started
I built alamp
environment on the server before and want to switch to one with better performance Strongnginx
As a server software, 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
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 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 downloaded 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; }
Recommended study: "PHP7 Tutorial"