Twelve weekly classes (April 23)
12.1 Introduction to LNMP Architecture
12.2 MySQL Installation
12.3/12.4 PHP Installation
12.5 Introduction to Nginx
expand
Why is Nginx more efficient than Apache Httpd: Principles http://www.toxingwang.com/linux-unix/linux-basic/1712.html
Comparison of working principles of apache and nginxhttp : //www.server110.com/nginx/201402/6543.html
Comparison of mod_php and mod_fastcgi and php-fpm http://dwz.cn/1lwMSd
Conceptual understanding: CGI, FastCGI, PHP-CGI and PHP-FPM http://www.nowamagic.net/librarys/veda/detail/1319/ https://www.awaimai.com/371.html
12.1 Introduction to LNMP Architecture
The difference between LNMP and LAMP is that N of LNMP is Nginx (a web service software similar to Apache). So Nginx and Apache play a similar role, and their functions are similar.
Unlike LAMP, Nginx provides web services
There is a difference between php in LNMP and php in LAMP,
In LNMP, php exists as a separate service called php-fpm .
The user's request will be handed over to php-fpm for processing, and these php-fpm may interact with MySQL,
for example:
Dynamic file interaction process:
For example, when logging in to a website, php-fpm will first go to MySQL to query the account and password information. After the MySQL check is successful, it will tell php-fpm. At this time, php-fpm will tell Nginx, and Nginx will tell the user's browser.
Static file interaction process:
For example, when processing static html files, Nginx will process it directly (Nginx processes static files more efficiently than Apache).
Nginx processes static requests directly, and dynamic requests are forwarded to php-fpm
12.2 MySQL Installation
! Ready to work
1 Delete the old version of MySQL related,
2 Turn off the mysqld service first
[root@AliKvn ~]# service mysqld stop
Shutting down MySQL.. [ OK ]
3 Delete related files
[root@AliKvn ~]# rm -rf /usr/local/mysql/
[root@AliKvn ~]# rm -rf /etc/init.d/mysqld
4 Modify the configuration file
! Leave it here unmodified
[root@AliKvn src]# cd /usr/local/src
[root@AliKvn src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@AliKvn src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@AliKvn src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[root@AliKvn src]# cd !$
cd /usr/local/mysql
[root@AliKvn mysql]# ls
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
[root@AliKvn src]# cd /usr/local/mysql
[root@AliKvn src]# useradd mysql
Delete the files in the /data/mysql directory to avoid conflicts.
[root@AliKvn mysql]# rm -rf /data/mysql/*
! After the preparations are done, then do the subject operations of this lesson
1 Initialize
[root@AliKvn mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@AliKvn mysql]# echo $?
0
2 Do not edit the configuration file, just use /etc/my.cnf to edit it.
#cp support-files/my-default.cnf /etc/my.cnf
[root@AliKvn mysql]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
3 Copy the startup script file.
[root@AliKvn mysql]# cp support-files/mysql.server /etc/init.d/mysqld
Define basedir and datadir
[root@AliKvn mysql]# vi /etc/init.d/mysqld
4 Start the service
[root@AliKvn mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/AliKvn.err'.
[ OK ]
Check the process
5 Join the boot service
[root@AliKvn mysql]# chkconfig --add mysqld
[root@AliKvn mysql]# chkconfig --list
[root@AliKvn mysql]# chkconfig mysqld on
12.3 12.4 PHP Installation
outline
It is different from the method of installing PHP with LAMP, and you need to open the php-fpm service.
If you have installed and compiled php before, you don't need to do these steps such as downloading and decompressing. Enter the decompression directory and perform make clean to clear the previous compilation, and recompile it once.
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
! Ready to work
make clean to clear, return to the state just decompressed at this time, and then recompile.
[root@AliKvn php-5.6.30]# make clean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php sapi/cgi/php-cgi libphp5.la modules/* libs/*
1 Create a php-fpm user, which will be used later
useradd -s /sbin/nologin php-fpm
2 Enter the php directory
#cd php-5.6.30
3 to initialize
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
3.1 Initialization error,
3.2 The libcurl-devel package is missing, install it.
[root@AliKvn php-5.6.30]# yum install -y libcurl-devel
3.3 Initialize again. After the initialization, check the result.
[root@AliKvn php-5.6.30]# echo $?
0
4 After success, make && make install
[root@AliKvn php-5.6.30]# echo $?
0
Installed and compiled successfully.
/usr/local/php-fpm/sbin/php-fpm is the php service program.
4.1 can be followed by related commands, and -t can check for syntax errors.
[root@AliKvn php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t
[23-Apr-2018 17:09:14] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[23-Apr-2018 17:09:14] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[23-Apr-2018 17:09:14] ERROR: FPM initialization failed
5 Check the syntax configuration file for errors, the error generally means that the specified user is wrong.
Do the following operations to enable the service to start normally
5.1 Copy the configuration file
[root@AliKvn php-5.6.30]#cp php.ini-production /usr/local/php-fpm/etc/php.ini
[root@AliKvn php-5.6.30]# cd /usr/local/php-fpm/etc/
[root@AliKvn etc]# ls
pear.conf php-fpm.conf.default php.ini
5.2 Edit php-fpm.conf , style reference https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf
[root@AliKvn etc]# vim php-fpm.conf
6 copy startup script
Enter the source package directory,
[root@AliKvn etc]# cd /usr/local/src/php-5.6.30
6.1 Copy the startup script file to /etc/init.d and rename it to php-fpm
[root@AliKvn php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
6.2 Change file permissions
[root@AliKvn php-5.6.30]# chmod 755 /etc/init.d/php-fpm
6.3 Set the boot service
[root@AliKvn php-5.6.30]# chkconfig --add php-fpm
[root@AliKvn php-5.6.30]# chkconfig php-fpm on
[root@AliKvn php-5.6.30]# chkconfig --list
aegis 0:off1:off2:on3:on4:on5:on6:off
agentwatch 0:off1:off2:on3:on4:on5:on6:off
mysqld 0:off1:off2:on3:on4:on5:on6:off
netconsole 0:off1:off2:off3:off4:off5:off6:off
network 0:off1:off2:on3:on4:on5:on6:off
php-fpm 0:off1:off2:on3:on4:on5:on6:off
[root@AliKvn php-5.6.30]#
7 Failed to start the service because the php-fpm user was not established.
[root@AliKvn php-5.6.30]# service php-fpm start
Starting php-fpm [23-Apr-2018 17:34:27] ERROR: [pool www] cannot get uid for user 'php-fpm'
[23-Apr-2018 17:34:27] ERROR: FPM initialization failed
failed
7.1 Create a php-fpm user, start again, and start successfully
[root@AliKvn php-5.6.30]# useradd php-fpm
[root@AliKvn php-5.6.30]# service php-fpm start
Starting php-fpm done
[root@AliKvn php-5.6.30]# ps aux |grep php-fpm
www is a module in the configuration file.
12.5 Introduction to Nginx
Nginx official website nginx.org, the latest version 1.13, the latest stable version 1.12, with the stable label is the latest and most stable version.
Nginx application scenarios: web service, reverse proxy (proxy for one machine), load balancing (proxy for two machines)
The famous branch of Nginx, Taobao's Tengine developed based on Nginx, is consistent with Nginx in use, the service name and configuration file name are the same, the biggest difference from Nginx is that Tenging adds some customized modules, which are outstanding in terms of safe speed limit. Support for js, css merging
Nginx core + lua-related components and modules form a high-performance web container openresty that supports lua, refer to http://jinnianshilongnian.iteye.com/blog/2280928
The advantages of Nginx: small size, support for expansion and rich functions.