CentOS7.6 System using yum configuration lnmp environment method

  • 2020-12-18 02:03:00
  • OfStack

1. Installation version details


Server: MariaDB
 Server version: 5.5.60-MariaDB MariaDB Server
 [root@ln-125 ~]# cat /etc/redhat-release
 CentOS Linux release 7.6.1810 (Core)
 [root@ln-125 ~]# nginx -v
 nginx version: nginx/1.14.2
 [root@ln-125 ~]# php-fpm -v
 PHP 5.4.16 (fpm-fcgi) (built: Oct 30 2018 19:32:20)
 Copyright (c) 1997-2013 The PHP Group
 Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

2. Install Nginx services

1. Configure the yum source for Nginx


[root@ln-125 ~]# cat >> /etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/   
#releasever  is linux  The version number of the centos 7
gpgcheck=0
enabled=1
EOF

2. Install and add the boot from startup


yum clean all ;
yum makecache ;
yum list nginx ;
# And you can see that nginx The installation package  ;
yum install nginx ;
systemctl enable nginx ;
systemctl start nginx 

If you need additional installation modules, you can download the source package according to the current version of Nginx and incrementally compile the appended modules according to the current version


[root@ln-125 ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

3. Install related php services

Query the current php installation package

yum list php  php-fmp

Why is php-ES37en installed here?

php-fpm is the bridge between nginx and php, ES45en-ES46en (fast process management), php-ES48en default process is 127.0.0.1:9000, 1 php and ES50en-ES51en after installation, to configure the configuration file of nginx, let it encounter client php request is, It is forwarded to ES54en-ES55en (127.0.0.1:9000), and then php-ES57en lets php complete the parsing, and finally to nginx again.

1. Install


yum install -y php php-fpm php-pear php-devel #httpd 

#httpd optional, php-ES69en is the extension tool of php in parameter update, you can install php extension with pecl install command after installation

2. Configure Nginx to support php files

The default Nginx is the required configuration for html and htm files to support php


vim /etc/nginx/conf.d/default.conf 
...
  location / {
    root  /usr/share/nginx/html; # Sets the absolute path to the root directory 
    index index.html index.htm index.php; # matching php file 
  }
  location ~ \.php$ {   # The original comment is out of the need to turn on or copy 
    root      /usr/share/nginx/html; # Set the absolute path 
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # Set the root directory match 
    include    fastcgi_params;
  }
...

3. Set unix for php

sock communication (you can skip this step)

The default configuration file uses listening on port 9000 for communication, for small single 1. For servers that do not balance liabilities, unix sock can be used for communication to increase the php response speed


touch /dev/shm/php-fpm-default.sock
[root@ln-125 ~]# cat /etc/php-fpm.d/www.conf |grep -Ev '^;|^$'
[www]
listen = /dev/shm/php-fpm-default.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = nginx
group = nginx
 . 
systemctl restart php-fpm.service
systemctl enable php-fpm

4. Optimize configuration (optional)

A) modify the configuration of ES108en.ini


vim /etc/php.ini 
cgi.fix_pathinfo=1 # Remove the comment and turn it on PHP the pathinfo Pseudo-static functionality. 
max_execution_time = 0 # The maximum time the script will run, by default 30 seconds 
max_input_time = 300# Scripts can consume time by default 60 seconds 
memory_limit = 256M# The script runs the maximum amount of memory consumed, changing the values according to your requirements, by default 128M
post_max_size = 100M # Maximum data per submission. This does not limit the size of individual files uploaded , Instead, it restricts the submission data to the entire form. The scope of the restriction includes all content submitted by the form . For example, : When you publish a post , Post title , content , Accessories, etc... The default 8M
upload_max_filesize = 10M# Maximum permitted size of uploaded file   , the default 2M

B) modifies the configuration of php-ES116en


vim /etc/php-fpm.d/www.conf 
 Find the following two lines and uncomment  
listen.owner = nobody 
listen.group = nobody 
 Find the following two lines and make each of them apache Instead of nginx 
user = apache -> user = nginx 
group = apache -> group = nginx

4. Install mariadb database


yum install -y mariadb mariadb-server
# Boot from the rev. 
[root@ln-125 ~]# systemctl start mariadb.service
[root@ln-125 ~]# systemctl enable mariadb.service
# Initializes the database configuration 
mysql_secure_installation # Configure default Settings ( root Password login, etc.) 
# Set the default character set 
 The editor  vim /etc/my.cnf
[root@ln-125 ~]# grep -Ev '^#|^$' /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
character-set-server = utf8 ## Set default encoding 
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d

systemctl restart mariadb.service

5. Test


[root@ln-125 ~]# cat >> /etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/   
#releasever  is linux  The version number of the centos 7
gpgcheck=0
enabled=1
EOF
0

EOF

http: / / {domain}
http: / / {domain} / index php

See the test page, so congratulations on your setup.

conclusion


Related articles: