Installation of linux PHP environment

Keywords: PHP Nginx OpenSSL yum

Nginx installation
nginx relies on three modules, zlib pcre ssl, which should be installed before installation and ignored if installed
Installation by source code:
These three extensions do not need to specify the installation directory, they are all installed by default in the / usr/local directory.
The first step is to download the source code uniformly, basically the latest version. openssl that must download the latest version, think that the previous heartbeat vulnerability.
The yum installation is used here

yum install -y pcre-devel make gcc gcc-c++ ncurses-devel zlib-devel openssl--devel
yum -y install openssl openssl-devel

2: Download http://nginx.org/en/download.html

tar -zxvf nginx-1.7.10.tar.gz
cd nginx-1.7.10.tar.gz

3:Installation

./configure --prefix=/usr/www/nginx  --conf-path=/usr/www/nginx/nginx.conf --pid-path=/usr/www/nginx/nginx.pid --with-http_ssl_module
make&&make install

4: Start and Stop
Start running nginx command directly under nginx installation directory
If stop nginx-s stop

PHP
1: Download
To download the latest version of PHP official website because of PHP 7 changes a little general election used a more mature and stable 5.6.
decompression

tar -zxvf mirror
cd php-XXXX

2:Installation
Most dependency libraries were installed when nginx was installed, but PHP needed something else.

yum -y install libmcrypt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel curl curl-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

If there is a problem with this whole dependency library, don't copy and run it directly. It's just convenient for comparison. When compiling PHP, if there is a prompt to copy the corresponding library installation and install the dependency library, compile PHP after installing the dependency library.

./configure --prefix=/usr/www/php5.6 --with-config-file-path=/usr/www/php5.6/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --with-libdir=lib64 --enable-pdo --enable-fpm

make && make install
//Take a long time to install, sit down and wait.

The default installation location of PHP has been specified above as / usr/local/php. Next, configure the corresponding files:

cp php.ini-development /usr/www/php5.6/php.ini
cp /usr/www/php5.6/etc/php-fpm.conf.default /usr/www/php5.6/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin

Note that the current directory is the source directory

Then set php.ini and use: vim/usr/local/php/php.ini to open the PHP configuration file to find the cgi.fix_pathinfo configuration item, which is annotated by default and has a value of 1. According to the official document, in order to prevent Nginx from sending requests to the back-end PHP-FPM module when the file does not exist, malicious scripts are avoided. Injection attack, so this should be uncommented and set to 0
Set up, save and exit

At this point, you should first create a web user:

groupadd www-data
useradd -g www-data www-data

Modify the corresponding 149 lines of configuration under / usr/www/php5.6/etc/php-fpm.conf configuration file
After the modification is completed, save and exit, and then execute the following command to start the php-fpm service:

Start and exit php-fpm

/usr/www/php5.6/sbin/php-fpm
 Netstat-tln | grep 9000 // / The normal use of the query 9000 port for startup completion indicates that PHP-fpm is running normally.
The process number used to view the port number under Linux:
Use the lsof command: lsof - i: port number

After php 5.3.3, php-fpm no longer supports the commands of / usr/local/php/sbin/php-fpm (start|stop|reload) that php-fpm used to have, so don't look at this old command any more, you need to use signal control:

The master process understands the following signals

INT, TERM terminates immediately
QUIT Smooth Termination
USR1 reopens log files
USR2 smoothly overloads all worker processes and reloads configuration and binary modules

For example:
First look at the master process number ps aux|grep php-fpm of php-fpm
Kill-QUIT php-fpm master process ID

Configure nginx to support php-fpm

listen       80;
server_name  game100.win www.game100.win;

root   /data/wwwroot/www;
index  index.html index.htm index.php;

location / {
}

error_page   500 502 503 504  /50x.html;
   location = /50x.html {      
}

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

php Extension Installation APCU
Download address: https://pecl.php.net/package/APCu

Install necessary extensions 
yum install m4
yum install autoconf
1. tar zxvf apcu-4.0.11.tgz
2. cd apcu-4.0.11
3./usr/www/php5.6/bin/phpize
4../configure --with-php-config=/usr/www/php5.6/bin/php-config
5.make && make install
//Configure php.ini
extension = apcu.so
apc.enabled= on
apc.shm_size= 64M
apc.enable_cli = on

Posted by riddhi on Sun, 07 Jul 2019 19:51:05 -0700