lnmp build (Nginx1.12.1; MySQL 5.7.20; php7.2.0)

Keywords: PHP Nginx MySQL yum

Install dependent packages:

#yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel 

Create a WW user:

#groupadd www
#useradd -g www -s /sbin/nologin -M www

1. Install Nginx1.12.1:

The Nginx version of the centos6.8 mirror band is 1.12.1

#yum install -y nginx 
#/etc/init.d/nginx start 

2. Install mysql5.7.20:

#wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
#rpm -Uvh mysql57-community-release-el6-9.noarch.rpm 
#yum install mysql-community-server
#service mysqld start
#grep 'temporary password' /var/log/mysqld.log  | awk '{print $NF}' 
#mysql -uroot -p
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=6; 
mysql>SET PASSWORD FOR 'root'@'localhost' =PASSWORD('******');

3. Install PHP7.2.0
3.1 Source Compilation and Installation

#wget rm -php-7.2.0.tar.xz
#tar xvJf php-7.2.0.tar -C /usr/local/
#cd /usr/local/php-7.2.0
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp  --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --with-libdir=lib64

# make 
# make install

The above configure steps may have errors due to the lack of dependent packages. I have installed some other packages on this machine. Different machines may have different situations and compile according to the error information
Use yum search to find dependent packages and install them without error s after compilation!!!
Once make install is complete, there is no error before you can proceed to the next steps.

3.2 Configure PHP

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

3.3 Start php-fpm

# /etc/init.d/php-fpm start
Starting php-fpm  done 

3.4 Add PHP commands to environment variables

vim ~/.bash_profile
cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/php/bin

export PATH

Make it effective:

#. ~/.bash_profile

3.5 View PHP version:

# php -v
PHP 7.2.0 (cli) (built: Dec 17 2017 19:58:31) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

3.6 Test results:

vim /usr/share/nginx/html/a.php
<?php
        phpinfo();
    ?>
vim /etc/nginx/conf.d/default.conf
cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Where the Nginx configuration file was modified (add the file in index.php format to the server).Add a location module)
Reload Nginx, restart php-fpm

# /etc/init.d/nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

Test:

# curl 192.168.1.185/a.php

Or go directly to the web page.

So far, the lnmp environment has been successfully built

Posted by ChrisDarl on Fri, 08 May 2020 11:18:51 -0700