Brief introduction
1 · LNMP Introduction
2 · NINGX installation (version 1.12)
3 · MySQL installation (version 5.5)
4 · PHP installation (version 5.6)
5 · installation Discuz forum
6 · Summary
LNMP Introduction
1 · Many people know the LAMP architecture, which is architected by Linux + Apache + MySQL + PHP, but as Nginx is used more and more in the enterprise, the LNMP architecture is also loved by people. In fact, these two architectures have not changed much, but the provision of WEB services has become Nginx. Then there will be differences between them. In Lnmp, Nginx can configure the static and dynamic separation of Web pages, parsing PHP, you can use the FPM module PHP. Now compare the new PHP version with the FPM module (Process Manager). This allows Nginx to handle the static request, and it forwards the dynamic request to the FPM module in PHP, or it can be described as a PHP-FPM service. But in LAMP PHP just exists as a module!
2 · and nginx it can withstand the number of concurrent connections up to 50000 or so, to throw Apache a few streets. and its stability and system resources are very small. So very popular with people.
Prepare the source package before installing, I put on Baidu net disk click Free Download: lnmp+ Forum Source code package password: jx5k
Nginx Installation
1 • Install a dependency package before installing Nginx
[Email protected] ~]# yum-y install pcre-devel zlib-devel gcc gcc-c++ make
2 · Create a dedicated user for Nginx for accurate control of permissions and reduce security risks
[Email protected]alhost ~]# useradd-m-s/sbin/nologin nginx
3 • Unzip, compile and install Nginx, general compilation and installation are placed under the/usr/local directory
[Email protected] ~]# tar zxvf nginx-1.12.0.tar.gz-c/opt
[Email protected] ~]# cd/opt/nginx-1.12.0
[Email protected] nginx-1.12.0]#/configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module (Support statistics status)
[[email protected] nginx-1.12.0]# make && make install (compile installation)
4 · In order to make nginx convenient for administrators to run and manage, create a connection file for Nginx
[Email protected] nginx-1.12.0]# ln-s/usr/local/nginx/sbin//usr/local/sbin/
5 · In order to make the Nginx start stop more convenient, write a startup script for him, it is more convenient.
[Email protected] nginx-1.12.0]# VIM/ETC/INIT.D/NGIXN
#!/bin/bash
#chkconfig:-99 20
#description: Nginx Service Control Script
Prog= "/usr/local/nginx/sbin/nginx" (Here is: Main program path)
Pidf= "/usr/local/nginx/logs/nginx.pid" (here is the PID storage path)
Case "$" in
Start
$PROG
;;
Stop
Kill-s QUIT $ (cat $PIDF) (terminate Nginx process based on PID, kill process)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF) (Reload configuration based on process)
;;
*)
echo "Usage: $ {start|stop|restart|reload}" (If you enter other prompts to enter the syntax)
Exit 1
Esac
Exit 0
6 · Give the script permission to execute and add Nginx as a system service.
[Email protected] ~]# chmod +x/etc/init.d/nginx
[Email protected] ~]# chkconfig--add nginx
7 • Start the Nginx service and view the status.
[[email protected] ~]# systemctl start Nginx
[Email protected] ~]# systemctl status Nginx
Nginx.service-sysv:nginx Service Control Script
Loaded:loaded (/etc/rc.d/init.d/nginx; bad; vendor preset:disabled)
Active:active (running) since two 2018-08-28 14:14:00 CST; 7s ago
Docs:man:systemd-sysv-generator (8)
process:5323 Execstart=/etc/rc.d/init.d/nginx Start (code=exited, status=0/success)
CGroup:/system.slice/nginx.service
├─5325 Nginx:master Process/usr/local/nginx/sbin/nginx
└─5326 Nginx:worker Process
MySQL Installation (version 5.5 OH)
1 · There is still a need to install the dependency package, MySQL here need to note is no longer used./configure Install the module, but with the Cmake, so here need to install Cmake and other packages
[Email protected] ~]# yum-y install ncurses-devel bion libaio-devel cmake
2 · Create a dedicated user for MySQL for accurate control of permissions and reduce security risks
[[email protected] ~]# useradd-s/sbin/nologin MySQL
3 • Unzip, compile and install MySQL, the general compilation installation is placed under the/usr/local directory
[Email protected] ~]# tar zxvf mysql-5.5.24.tar.gz-c/opt
[Email protected] ~]# cd/opt/mysql-5.5.24
[Email protected] mysql-5.5.24]# cmake \
-dcmake_install_prefix=/usr/local/mysql \
-ddefault_charset=utf8 \
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
-dwith_extra_charsets=all \
-DSYSCONFDIR=/ETC \
-dmysql_datadir=/home/mysql/\
-dmysql_unix_addr=/home/mysql/mysql.sock \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-denabled_local_infile=1 \
-dwith_ssl=system \
-dmysql_tcp_port=3306 \
-denable_downloads=1 \
-dwith_ssl=bundled
[[email protected] mysql-5.5.24]# make && make install
4 · Make some adjustments to MySQL according to some of your daily habits.
[email protected] mysql-5.5.24]# CP support-files/my-medium.cnf/etc/my.cnf
[email protected] mysql-5.5.24]# CP support-files/mysql.server/etc/init.d/mysqld
[Email protected] mysql-5.5.24]# chmod +x/etc/init.d/mysqld
5 • Add System management, set boot boot
[Email protected] mysql-5.5.24]# chkconfig--add mysqld
[Email protected] mysql-5.5.24]# chkconfig--level mysqld on
6 • Add the variable to the/etc/profile file and make the file effective again.
[Email protected] mysql-5.5.24]# echo "path= $PATH:/usr/local/mysql/bin/" >>/etc/profile
[Email protected] ~]#. /etc/profile (you need to be aware that there are spaces in the middle)
[Email protected] ~]# chown-r mysql.mysql/usr/local/mysql
7 • Initializing the database
[Email protected] ~]#/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
8 · Specify the home directory and the installation path in the boot configuration file
[Email protected] ~]# Vim/etc/init.d/mysqld
Basedir=/usr/local/mysql
Datadir=/home/mysql
9 · Here I could have started the service, but here error, such as the error message, is to shut down the firewall, Setenforce 0 after the start.
[Email protected] ~]# systemctl start Mysqld.service
It says to let you use its prompt statement to see the state, in fact, we start with another method, you can see the error message is not the same. Such as
[[email protected] ~]#/etc/init.d/mysqld start
This means: Do not start with the new PID file. You can't start without a PID.
Workaround:
[Email protected] ~]# Mv/etc/my.cnf/etc/my.cnf.bak
The equivalent of deleting this file to start the success.
Either comment out the two sentences in/etc/my.cnf or create your own mkdir-p/var/run/mariadb
Mkdir-p/log/run/mariadb
Install PHP
1 · Install dependent packages and GD libraries and other associated programs
[[email protected] ~]# yum-y install \
GD \
Libxml2-devel \
Libjpeg-devel \
Libpng-devel \
Zlib-devel \
Fontconfig-devel \
Openssl-devel \
Bzip2-devel
2 • Unzip, compile and install PHP, generally compiled and installed under the/usr/local directory
[Email protected] ~]# tar jxvf php-5.6.11.tar.bz2-c/opt/
[Email protected] php-5.6.11]#/configure \
--PREFIX=/USR/LOCAL/PHP5 \
--WITH-GD \
--with-zlib \
--with-mysql=/usr/local/mysql \
--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP5 \
--enable-mbstring \
--with-jpeg-dir=/usr/lib \
--WITH-OPENSSL \
--disable-ipv6 \
--enable-fpm
[[email protected] php-5.6.11]# make && make install
3 · Some optimizations for PHP
[email protected] php-5.6.11]# CP Php.ini-development/usr/local/php5/php.ini
[Email protected] php-5.6.11]# ln-s/usr/local/php5/bin/ /usr/local/bin/
[Email protected] php-5.6.11]# ln-s/usr/local/php5/sbin/ /usr/local/sbin/
4 · Install Accelerators for PHP
[Email protected] ~]# tar zxvf zend-loader-php5.5-linux-x86_64_update1.tar.gz-c/opt
[Email protected] ~]# cd/opt/zend-loader-php5.5-linux-x86_64/
[email protected] zend-loader-php5.5-linux-x86_64]# CP zendguardloader.so/usr/local/php5/lib/php
5 · Configuring the PHP Recognition accelerator
[Email protected] ~]# Vim/usr/local/php5/php.ini
Insert at end of file:
[Zend Guard Loader]
Zend_extension=/usr/local/php5/lib/php/zendguardloader.so
Zend_loader.enable=1
6 · Open Nginx PHP Support
[Email protected] ~]# cd/usr/local/php5/etc/
[email protected] etc]# CP Php-fpm.conf.default php-fpm.conf
[[email protected] etc]# useradd-m-s/sbin/nologin php (almost forgot)
7 • Modify the PHP-FPM configuration file
[[email protected] etc]# vim php-fpm.conf-----(here is the modified file)
PID = Run/php-fpm.pid
user = PHP
Group = PHP
Pm.max_children=50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
[[email protected] etc]#/usr/local/sbin/php-fpm-------------(make the file effective)
[Email protected] etc]# Netstat-tnal | grep 9000-------------(see port)
8 · Let Nginx support PHP function
[[email protected] ~]# vim/usr/local/nginx/conf/nginx.conf----(just modify nginx config file)
Location ~. php$ {
Root/var/www/benet;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}
Add the above parameters to the server, such as:
9 • Check nginx configuration file, restart Nginx service, view status
[Email protected] conf]# nginx-t
[Email protected] conf]# systemctl restart Nginx
[Email protected] conf]# systemctl status Nginx
10 • Test PHP page
[Email protected] conf]# mkdir-p/var/www/benet
[Email protected] conf]# vim/var/www/benet/index.php
<?php
Phpinfo ();
?>
11 · Start testing, Access
Install Discuz Forum
1 · After we set up the LNMP, we can install the software based on this foundation, which is listed in the Discuz forum.
2 · To install the Discuz forum you need to create a database for this forum and create a user to manage it
3 · Enter MySQL database to create a new database named BBS
[Email protected] ~]# mysql-u root-p-----(enter password)
mysql> Create databases BBS; ------(Create a library name called BBS with a semicolon end)
Mysql> Grant all on bbs.* to ' bbsuser ' @ ' percent ' identified by ' admin123 ';
To bbsuser this user on any server login, login password is ' admin123 ', to BBS this library, the library all the tables have all the permissions.
mysql> flush Privileges; ----(Refreshes the database, takes effect immediately)
• Test the database with the following test code:
vim/var/www/benet/index.php
<?php
$link =mysql_connect (' Host IP ', ' bbsuser ', ' admin123 ');
if ($link) echo "success!!";
else echo "fail!!";
Mysql_close ();
?>
Unzip the Discuz software package, optimize the content
[Email protected] ~]# Unzip discuz_x3.3_sc_utf8.zip-d/opt/dis
[Email protected] ~]# Cd/opt/dis
[Email protected] dis]# cp-r upload//var/www/benet/bbs
[Email protected] dis]# Cd/var/www/benet/bbs
[[email protected] bbs]# chown-r php./config
[[email protected] bbs]# chown-r php./data
[[email protected] bbs]# chown-r php./uc_client
[[email protected] bbs]# chown-r php./uc_server/data
Start installation
The installation is installed on Windows 7 and the Access address is:
Discuz installation is complete, we can access the management background.
Summarize:
1 · For some nginx other configuration can look at Nginx optimization
2 · In the entire LNMP installation process, said not necessarily will report some mistakes, just did not encounter, error on Baidu more check.
3 · Need to know the advantages of Nginx where, its high concurrent connection, and dynamic static separation, there is very little resource consumption and so on.
4 · php in LNMP is used to do dynamic work with the PHP-FPM module. But in lamp, PHP is just a module.
CentOS 7 Build LNMP Architecture detailed process + Discuz Forum installation (manual compilation)