CentOS 7.4 Build Lnmp
Latest versions lnmp:linux7.4, ngnix1.13.9, mysql5.7.20, php7.1.10
Directory:
The first part of the preparatory work
The second part installs the Nginx service
The third part installs the MySQL database
Part IV builds PHP operating environment
Part V LNMP Architecture application (build Discuz forum)
The first part of the preparatory work
One: server: Linux system-centos 7.4;
IP Address: 192.168.80.10
Client: Take WIN7 as an example, test the result of verification, and the server in the same network segment;
IP Address: 192.168.80.2
Two: Download the compressed package
Put the compressed package under the Linux system
Third: Close the firewall with SELinux
The second part installs the Nginx service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \
GCC \
gcc-c++ \
Make \
Pcre-devel \
Zlib-devel
[[email protected] ~]# useradd-m-s/sbin/nologin nginx//create Nginx User
-M: Do not establish and initialize the host directory for the user
Two: Configuration (custom personalization)
[[Email protected] ~]# tar xzvf nginx-1.13.9.tar.gz-c/opt///Decompression Nginx installation package to opt directory
[Email protected] ~]# cd/opt/nginx-1.13.9/
[[email protected] nginx-1.13.9]#./configure \//Personalized Configuration
--prefix=/usr/local/nginx \//Specify the installation directory
--user=nginx \//Specify user
--group=nginx \//Specify Group
--with-http_stub_status_module//Log Statistics module
Three: Compiling and installing
[[email protected] nginx-1.13.9]# make && make install//compile installation
[Email protected] nginx-1.13.9]# ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin/
Optimized execution path (the original path of the executing program file is not in the PATH environment variable, do a soft link to make it executable)
[[email protected] nginx-1.13.9]# nginx–t//Check syntax error
[[email protected] nginx-1.13.9]# nginx//Start Nginx Service
[[email protected] nginx-1.13.9]# killall-1 nginx//safe restart
[[email protected] nginx-1.13.9]# killall-3 nginx//Stop service
IV: Production Management scripts
[Email protected] nginx-1.13.9]# Vi/etc/init.d/nginx
#!/bin/bash
chkconfig:35 20description:nginx Service Control Script
Prog= "/usr/local/nginx/sbin/nginx"
pidf= "/usr/local/nginx/logs/nginx.pid"
Case "$" in
Start
$PROG
;;
Stop
Kill-s QUIT $ (cat $PIDF)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF)
;;
*)
echo "Usage: $ {start|stop|restart|reload}"
Exit 1
Esac
Exit 0
Save exit
[[email protected] nginx-1.13.9]# chmod +x/etc/init.d/nginx//Add Execute permission
[[email protected] nginx-1.13.9]# chkconfig--add nginx//Add Nginx to system service
V: Edit the master configuration file
[Email protected] nginx-1.13.9]# vi/usr/local/nginx/conf/nginx.conf
Edit the following content:
User Nginx Nginx; Run user
Error_log Logs/error.log Info; Error log path
-----Log Level: Debug Info Notice warn error crit//up record (low to high)-----
Events {
Use Epoll; New this line defaults to using Select/poll
Worker_connections 10240; Represents 1 worker processes that allow 10,240 connections.
}
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '//Definition log format Remove the previous # number
Save exit
[[email protected] ~]# ulimit–n//view and change the number of local open resources on the system
[Email protected] ~]# ulimit-n 65500 >>/etc/rc.local
VI: Win7 under verification
Browser access: http://192.168.80.40
Nginx Build Success
The third part builds MySQL database
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \
ncurses \
Ncurses-devel \
Bison \
CMake
Second: Establish database program users
[[email protected] ~]# useradd-s/sbin/nologin MySQL
Three: Unzip the MySQL installation package
[Email protected] ~]# Tar XF mysql-boost-5.7.20.tar.gz–c/opt/
Four: Configuration (personalized configuration and optimization project)
[Email protected] ~]# cd/opt/mysql-5.7.20/
[Email protected] mysql-5.7.20]# cmake \
-dcmake_install_prefix=/usr/local/mysql \//define the installation directory
-dmysql_unix_addr=/usr/local/mysql/mysql.sock \//Connection Database socket path
-DSYSCONFDIR=/ETC \//Specify initialization parameter file directory (MY.CNF)
-DSYSTEMD_PID_DIR=/USR/LOCAL/MYSQL \//Database directory
-DDEFAULT_CHARSET=UTF8 \//Specifies the character set encoding used by default
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \//Specifies the character set collation used by default, Utf8_general_ci is a universal rule for UTF-8 character set
-dwith_innobase_storage_engine=1 \//Support InnoDB engine
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwith_perfschema_storage_engine=1 \//install support database partition
-dmysql_datadir=/usr/local/mysql/data \
-dwith_boost=boost \
-dwith_systemd=1
(Note: If there is an error in the process of CMake, when the error is resolved, you need to put the source directory
CMakeCache.txt file Delete, and then re-cmake, otherwise the error remains)
V: Compile and install
[[email protected] mysql-5.7.20]# make
[[email protected] mysql-5.7.20]# make install
Configure permissions on a database directory
[Email protected] mysql-5.7.20]# chown-r mysql.mysql/usr/local/mysql/
VI: Edit MySQL master configuration file
[Email protected] mysql-5.7.20]# VI/ETC/MY.CNF
(All contents are deleted and replaced with the following contents)
[Client]
Port = 3306
Default-character-set=utf8
Socket =/usr/local/mysql/mysql.sock
[MySQL]
Port = 3306
Default-character-set=utf8
Socket =/usr/local/mysql/mysql.sock
[Mysqld]
user = MySQL
Basedir =/usr/local/mysql
DataDir =/usr/local/mysql/data
Port = 3306
Character_set_server=utf8
Pid-file =/usr/local/mysql/mysqld.pid
Socket =/usr/local/mysql/mysql.sock
Server-id = 1
Sql_mode=no_engine_substitution,strict_trans_tables,no_auto_create_user,no_auto_value_on_zero,no_zero_in_date, No_zero_date,error_for_division_by_zero,pipes_as_concat,ansi_quotes
Save exit
[[email protected] mysql-5.7.20]# chown mysql:mysql/etc/my.cnf//config file belongs to the main and genus Group
Six: Setting Environment variables
[Email protected] mysql-5.7.20]# echo ' path=/usr/local/mysql/bin:/usr/local/mysql/lib: $PATH ' >>/etc/profile
Add these two paths to the environment variable and put them in the profile file to start from running, otherwise it won't take effect
[[email protected] mysql-5.7.20]# echo ' export PATH ' >>/etc/profile
Set as a global variable to make it use a wider environment
[[email protected] mysql-5.7.20]# source/etc/profile//immediate effect
Seven: Initializing the database
[Email protected] ~]# cd/usr/local/mysql/
[Email protected] mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
Eight: Turn on MySQL service
[email protected] mysql]# CP usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/
[Email protected] mysql]# Systemctl daemon-reload
[Email protected] mysql]# systemctl start mysqld
[Email protected] mysql]# NETSTAT-ANPT | grep 3306//view service run status
[[email protected] mysql]# Systemctl enable MYSQLD//set to boot
Ten: Accessing Database operations
[Email protected] mysql]# mysqladmin-u root-p password "abc123"
Set password for root account to abc123
Note: Prompt input is the original password (original no password, direct return)
[[email protected] mysql]# mysql-u root–p//Login Database
Note: There is a password plus "-P", if no password is not added "-P"
Database installation configuration successful, exit enter "Quit"
Part IV builds PHP operating environment
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \
Libjpeg \
Libjpeg-devel \
Libpng libpng-devel \
FreeType freetype-devel \
LIBXML2 \
Libxml2-devel \
Zlib zlib-devel \
Curl curl-devel \
OpenSSL openssl-devel//Install the plug-in needed to support
Two: Unpack the installation package
[[Email protected] ~]# tar XJVF php-7.1.10.tar.bz2//Unzip PHP installation package
Three: Configuration (personalized configuration and optimization project)
[Email protected] ~]# CD php-7.1.10
[[email protected] php-7.1.10]#./configure \//Personalized Configuration
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--WITH-MYSQLI \
--with-zlib \
--with-curl \
--WITH-GD \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--WITH-OPENSSL \
--enable-mbstring \
--enable-xml \
--enable-session \
--ENABLE-FTP \
--ENABLE-PDO \
--enable-tokenizer \
--enable-zip \//Support compression function
--ENABLE-FPM//Support Dynamic page FPM function
(Note: Because the content is more, be sure to check whether the last missing, especially the last one)
Four: Compiling and installing
[[email protected] php-7.1.10]# make//compile
[[email protected] php-7.1.10]# make install//install
V: Edit the configuration file
[[email protected] php-7.1.10]# CP Php.ini-development/usr/local/php/lib/php.ini//create PHP config file
[[email protected] php-7.1.10]# Vi/usr/local/php/lib/php.ini//compiling PHP config file
Modify the following content:
Mysqli.default_socket =/usr/local/mysql/mysql.sock//associating PHP with MySQL
Date.timezone = Asia/shanghai//Set time zone
Save exit
[[email protected] php-7.1.10]#/usr/local/php/bin/php–m//Verify the installed module
Six: Configuring and optimizing the FPM module
[Email protected] php-7.1.10]# cd/usr/local/php/etc/
[[email protected] etc]# CP php-fpm.conf.default php-fpm.conf//Copy PHP fpm Module profile template for configuration file. PHP only recognizes php-fpm.conf as a configuration file
[Email protected] etc]# CD PHP-FPM.D
[[email protected] php-fpm.d]# CP www.conf.default www.conf//copy fpm www profile template as config file, FPM only recognizes www.conf configuration file
[Email protected] php-fpm.d]# CD. Return to previous level directory
[[Email protected] etc]# VI php-fpm.conf//configure FPM Module
Modify the following content:
PID = run/php-fpm.pid//semicolon Remove
user = Nginx//Add two lines
; group = Nginx
Save exit
Seven: Start the FPM module
[[email protected] etc]#/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini//Start FPM module
[Email protected] etc]# NETSTAT-ANPT | GREP 9000//View 9000 port running status (PHP-FPM running on port 9000)
[[email protected] etc]# ln-s/usr/local/php/bin/*/usr/local/bin///Put PHP's executable program into a system-aware environment for easy execution
[[Email protected] etc]# PS aux | Grep-c "PHP-FPM"//number of statistical processes
Eight: Update the startup script to enable the FPM module to perform system startup management
[Email protected] etc]# Vi/etc/init.d/nginx
#!/bin/bash
chkconfig:35 20description:nginx Service Control Script
Prog= "/usr/local/nginx/sbin/nginx"
pidf= "/usr/local/nginx/logs/nginx.pid"
Prog_fpm= "/USR/LOCAL/PHP/SBIN/PHP-FPM"
Pidf_fpm= "/usr/local/php/var/run/php-fpm.pid"
Case "$" in
Start
$PROG
$PROG _FPM
;;
Stop
Kill-s QUIT $ (cat $PIDF)
Kill-s QUIT $ (cat $PIDF _fpm)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF)
;;
*)
echo "Usage: $ {start|stop|restart|reload}"
Exit 1
Esac
Exit 0
Save exit
Nine: let Nginx support PHP function
[[email protected] etc]# vi/usr/local/nginx/conf/nginx.conf//Configure Nginx master configuration file
Edit the following content:
Location ~. php$ {
root/usr/local/nginx/html; Web page Default Path
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename/usr/local/nginx/html $fastcgi _script_name; Note Directory name
Include Fastcgi_params;
}
Save exit
Ten: Edit php Default Web page
[Email protected] etc]# vi/usr/local/nginx/html/index.php
Add the following content:
<?php
Phpinfo ();
?>
Save exit
[[Email protected] etc]# service nginx restart//restart Nginx Services
11: Verify:
Win7 under browser access http://192.168.80.40/index.php
Validation successful
- Test database
[[email protected] mysql]# mysql-u root–p//Login Database
Enter Password: abc123
CREATE DATABASE BBS; Create a Database BBS
GRANT all on BBS. To ' bbsadm ' @ '% ' identified by ' admin123 ';//Authorized BBSADM account has all rights of BBS database
GRANT all on BBS. To ' bbsadm ' @ ' localhost ' identified by ' admin123 '; Authorized BBSADM Account BBS database permissions on the local server
Flush privileges; Refresh Permissions
Edit index.php File
[Email protected] mysql]# vi/usr/local/nginx/html/index.php
Add the following content (delete the original content):
<?php
$link =mysqli_connect (' 192.168.80.40 ', ' bbsadm ', ' admin123 ');
if ($link) echo "else echo "fail!!";
?>
Save exit
Restart Service
[Email protected] ~]# service mysqld restart
[[Email protected] ~]# service Nginx restart
Win7 under Verification:
Browser access: http://192.168.80.40/index.php
Validation successful
Part V LNMP Architecture application (build Discuz forum)
One: Unzip the Discuz installation package
[email protected] ~]# Yum install-y unzip
[Email protected] ~]# Unzip discuz_x3.4_sc_utf8_0101.zip-d/opt/
[Email protected] opt]# CD dir_sc_utf8/
[Email protected] dir_sc_utf8]# cp-r upload//usr/local/nginx/html/bbs
Two: The configuration belongs to the owner, the group and the permission
[Email protected] dir_sc_utf8]# Cd/usr/local/nginx/html/bbs
[Email protected] bbs]# chown-r Root:nginx./config/
[Email protected] bbs]# chown-r Root:nginx./data/
[Email protected] bbs]# chown-r Root:nginx./uc_client/
[Email protected] bbs]# chown-r Root:nginx./uc_server/
[Email protected] bbs]# chmod-r 777./config/
[Email protected] bbs]# chmod-r 777./data/
[Email protected] bbs]# chmod-r 777./uc_client/
[Email protected] bbs]# chmod-r 777./uc_server/
Three: Restart Nginx service
[[Email protected] bbs]# service Nginx restart
Four: Verify:
Win7 Browser access: http://192.168.80.40/bbs/install/index.php//Installation Forum
Next:
Installation Complete
Access Address: http://192.168.80.40/bbs/index.php
Validation successful
http://192.168.80.40/bbs/admin.php Management Background
Enter account number, password login
Login does not go in, prompt to delete index.php, do the following actions:
[Email protected] bbs]# cd/usr/local/nginx/html/bbs/install/
[Email protected] bbs]# rm–f index.php
[[Email protected] install]# service Nginx restart
Re-access http://192.168.80.40/bbs/admin.php under Win7
Validation successful
Linux Essentials-centos 7.4 Source code compilation build LNMP architecture