Task on June 6
12.1 LNMP architecture introduction
12.2 MySQL installation
12.3/12.4 PHP installation
12.5 Nginx Introduction
Extension
Why Nginx is more efficient than Apache Httpd:Principle
http://www.toxingwang.com/linux-unix/linux -basic/1712.html
A comparison of the working principles of apache and nginx
http://www.server110.com/nginx/201402/6543.html
Comparison of mod_php and mod_fastcgi and php-fpm
http://dwz.cn/1lwMSd
Concept understanding :CGI,FastCGI,PHP-CGI and PHP-FPM
http://www.nowamagic.net/librarys/veda/detail/1319/
p>
12.1 Introduction to LNMP Architecture
The difference between LNMP and LAMP is that Apache is replaced by Nginx, Nginx provides web services, Simply access PHP websites, if They are all for accessing static pictures,Nginx has more concurrent users than Apache,This is also something Apache cannot do.
12.2 MySQL Installation
The MySQL installation steps are as follows :
1. Download the mysql source package
[root@jimmylinux-001 ~]# cd /usr /local/src Enter the src directory
[root@jimmylinux-001 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux -glibc2.5-x86_64.tar.gz wget download MySQL source package
2, decompress source package
[root@jimmylinux-001 src]# tar zxvf mysql-5.6 .36-linux-glibc2.5-x86_64.tar.gz
3. Move the directory and rename it to mysql, and enter the mysql directory at the same time.
[root@jimmylinux-001 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
[root@ jimmylinux-001 src]# cd /usr/local/mysql
4. Create mysql user and data directory
[root@jimmylinux-001mysql]# useradd mysql
[root@jimmylinux-001 mysql]# mkdir /data/
5. Initialize and generate the directory required for mysql startup
[root@jimmylinux- 001 mysql]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad Interpreter: No such file or directory
#If this error occurs ,Solution (install perl and perl-devel)
Execute yum -y install perl Initialize after perl-devel
If the following error is reported during the initialization process ,you can install the corresponding software package according to the error prompt,until the initialization is successful.
[root@jimmylinux-001 mysql]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
[root@jimmylinux-001 mysql]# yum install -y Perl modules
[root@jimmylinux-001 mysql]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql
Installing MySQL system tables …./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared objectfile: No such file or directory
[root@jimmylinux-001 mysql]# yum install -y libaio*
After performing initialization , If you see 2 OK or execute echo $? The result is 0, which means the initialization is successful.
6, copy configuration file and startup script
[root@jimmylinux-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@jimmylinux-001 mysql]# vim /etc/my.cnf
Modify the my.cnf configuration file to the following
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
[root@jimmylinux-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@jimmylinux-001 mysql]# vim /etc/init.d/mysqld
Define the path in the startup script file
basedir= /usr/local/mysql
datadir=/data/mysql
7. Start mysql service
[root@jimmylinux-001 mysql] # /etc/init.d/mysqld start Start mysql service
If the following error occurs
Starting MySQL.180606 17:22:32 mysqld_safe error: log-error set to &## 39;/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user'mysql'.
ERROR! The server quit without updating PID file (/data/mysql/jimmylinux-001.pid)
Add # to comment out the following content of the my.cnf configuration file
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
Restart mysql service
[root@jimmylinux-001 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to'/data /mysql/jimmylinux-001.err'.
.. SUCCESS![root@jimmylinux-001 mysql]# ps aux |grep mysql
root4135 0.0 0.0 113304 1632 pts/0 S 17:37 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe –datadir=/data/mysql –pid-file=/data/mysql/jimmylinux-001.pid
mysql4272 6.0 7.6 1300824 453504 pts/0 Sl 17:37 0:02 /usr/local/mysql/bin/mysqld –basedir=/usr/local/mysql- -datadir=/data/mysql –plugin-dir=/usr/local/mysql/lib/plugin –user=mysql –log-error=/data/mysql/jimmylinux-001 .err –pid-file=/data/mysql/jimmylinux-001.pid –socket=/tmpmysql.sock
root4300 0.0 0.0 112720 984 pts/0 S+ 17 :37 0:00 grep –color=auto mysql
8. Add the mysqld service to the service list, and set it to start automatically.
[root@jimmylinux-001 mysql]# chkconfig –add mysqld
[root@jimmylinux-001 mysql]# chkconfig mysqld on
12.3/12.4 PHP installation
The installation of PHP in Nginx is different from the installation in Apache ,need to enable the php-fpm service.
The PHP installation steps are as follows :
1. Enter the src directory , use wget to download the PHP source package.
[root@jimmylinux-001 ~]# cd /usr/local/src/[root@jimmylinux-001 src]# wget http://cn2.php.net/distributions/ php-5.6.30.tar.gz
2. Unzip the source package , and enter the php directory.
[root@jimmylinux-001 src]# tar zxf php-5.6.30.tar.gz
[root@jimmylinux-001 src]# useradd -s /sbin/nologin php-fpm
[root@jimmylinux-001 src]# cd php-5.6.30
3, the first step of ./configure source code installation ,The main function is to configure the software to be installed,Check whether the current environment meets the dependencies of the software to be installed
[root@jimmylinux-001 php-5.6. 30]# ./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
If there is an error , install according to the prompt Required packages,until configure is complete.
checking target system type… x86_64-unknown-linux-gnu
checking for cc… no
checking for gcc… no missing gcc compilation environment
configure: error: in `/usr/local/src/php-5.6.30':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@jimmylinux-001 php-5.6.30]# yum install – y gcc After installing the missing gcc package, execute ./configure
checking libxml2 install dir… yes
checking for xml2-config path…
configure: error: xml2-config not found. Please check your libxml2 installation. Error xml2-config not found
You can install missing packages through yum fuzzy search,yum install -y libxml2-devel
Error all the way, Install all the way , according to the error message , install what is missing , until you see the following screenshot , means the execution is successful.
4、 Compile and install
[root@jimmylinux-001 php-5.6.30]# make && make install
[root@jimmylinux-001 php-5.6.30] # /usr/local/php-fpm/sbin/php-fpm -m View loaded modules
[PHP Modules]
cgi-fcgi
Core
ctype
curl
date
dom
ereg
exif
exif
p>
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
SPL
sqlite3
sqlite3
p>
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@jimmylinux-001 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -i View related information of php
phpinfo()
PHP Version=>5.6.30
[root@jimmylinux-001 php-5.6.30]# /usr /local/php-fpm/sbin/php-fpm -t Test your own configuration file syntax
[06-Jun-2018 23:09:47] ERROR: failed to open configuration file ' /usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[06-Jun-2018 23:09:47] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[06-Jun-2018 23:09:47] ERROR: FPM initialization failed The error reported here is because there is no configuration file , to start this service , must have a configuration file.
5, copy configuration file
[root@jimmylinux-001 php-5.6.30]# ls /usr/local/php-fpm/etc/pear.conf php -fpm.conf.default originally had no php.int file
[root@jimmylinux-001 php-5.6.30]# cp php.ini-production /usr/local/php-fpm /etc/php.ini
[root@jimmylinux-001 php-5.6.30]# ls /usr/local/php-fpm/etc/pear.conf php-fpm.conf.default After php.ini is copied, there is an additional php.ini file
6. Enter the specified directory and create a configuration file vi /usr/local/php/etc/php-fpm.conf and write the following content
[root@jimmylinux-001php-5.6.30]# cd /usr/local/php-fpm/etc/[root@jimmylinux-001etc]# ls
pear .conf php-fpm.conf.defaultphp.ini
[root@jimmylinux-001 etc]# vim php-fpm.conf
Write the following content
[global] defines global parameters
pid= /usr/local/php-fpm/var/run/php-fpm.pid (pid path)
error_log& #61; /usr/local/php-fpm/var/log/php-fpm.log (error_log path)
[www] module name
listen= /tmp /php-fcgi.sock listening address
listen.mode= 666 defines sock file permission 666
user= php-fpm defines that user
group= php-fpm definition is that group
pm= dynamicpm is process information
pm.max_children= 50pm.start_servers= 20pm. min_spare_servers= 5pm.max_spare_servers= 35pm.max_requests= 500rlimit_files= 1024
7. Enter the source package directory, then copy the startup script and start the php-fpm service.
[root@jimmylinux-001 etc]# cd /usr/local/src/php-5.6.30 Enter the source package directory [root@jimmylinux-001 php-5.6.30] # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm Copy the startup script to etc
[root@jimmylinux-001 php-5.6.30] # chmod 755 /etc/init.d/php-fpm modify file permissions to 755
[root@jimmylinux-001 php-5.6.30]# chkconfig –add php-fpm put php- Add the fpm service to the service list
[root@jimmylinux-001 php-5.6.30]# chkconfig php-fpm on set boot self-start
[root@ jimmylinux-001 php-5.6.30]# service php-fpm start Start php-fpm service
Starting php-fpm done
8. Check the startup status of php-fpm service
p>
[root@jimmylinux-001 php-5.6.30]# ps aux |grep php-fpm
root43099 0.0 0.0 123656 4952 ? Ss Jun 06 0:00 php-fpm : master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 43100 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43101 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43102 0.0 0.0 123656 4708 ? S Jun 06 0 :00 php-fpm: pool www
php-fpm 43103 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43104 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43105 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43106 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43107 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm : pool www
php-fpm 43108 0.0 0.0 123656 4712 ? S June 06 0:00 php-fpm: pool www
php-fpm 43109 0.0 0.0 123656 4716 ? S 6 Jun 06 0:00 php-fpm: pool www
php-fpm 43110 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43111 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43112 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
p>
php-fpm 43113 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43114 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43115 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43116 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43117 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43118 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43119 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
root43139 0.0 0.0 112720 984 pts/0 S+ 00:03 0:00 grep –color=auto php-fpm
12.5 Introduction to Nginx
bin/php-fpm -i View php related information
phpinfo()
PHP Version=>5.6.30
[root@ jimmylinux-001 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t Test the syntax of your own configuration file
[06-Jun-2018 23:09:47 ] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[06- Jun-2018 23:09:47] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[06-Jun -2018 23:09:47] ERROR: FPM initialization failed The error reported here is because there is no configuration file , to start this service , must have a configuration file.
5, copy configuration file
[root@jimmylinux-001 php-5.6.30]# ls /usr/local/php-fpm/etc/pear.conf php -fpm.conf.default originally had no php.int file
[root@jimmylinux-001 php-5.6.30]# cp php.ini-production /usr/local/php-fpm /etc/php.ini
[root@jimmylinux-001 php-5.6.30]# ls /usr/local/php-fpm/etc/pear.conf php-fpm.conf.default After php.ini is copied, there is an additional php.ini file
6. Enter the specified directory and create a configuration file vi /usr/local/php/etc/php-fpm.conf and write the following content
[root@jimmylinux-001php-5.6.30]# cd /usr/local/php-fpm/etc/[root@jimmylinux-001etc]# ls
pear .conf php-fpm.conf.defaultphp.ini
[root@jimmylinux-001 etc]# vim php-fpm.conf
Write the following content
[global] defines global parameters
pid= /usr/local/php-fpm/var/run/php-fpm.pid (pid path)
error_log& #61; /usr/local/php-fpm/var/log/php-fpm.log (error_log path)
[www] module name
listen= /tmp /php-fcgi.sock listening address
listen.mode= 666 defines sock file permission 666
user= php-fpm defines that user
group= php-fpm definition is that group
pm= dynamicpm is process information
pm.max_children= 50pm.start_servers= 20pm. min_spare_servers= 5pm.max_spare_servers= 35pm.max_requests= 500rlimit_files= 1024
7. Enter the source package directory, then copy the startup script and start the php-fpm service.
[root@jimmylinux-001 etc]# cd /usr/local/src/php-5.6.30 Enter the source package directory [root@jimmylinux-001 php-5.6.30] # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm Copy the startup script to etc
[root@jimmylinux-001 php-5.6.30] # chmod 755 /etc/init.d/php-fpm modify file permissions to 755
[root@jimmylinux-001 php-5.6.30]# chkconfig –add php-fpm put php- Add the fpm service to the service list
[root@jimmylinux-001 php-5.6.30]# chkconfig php-fpm on set boot self-start
[root@ jimmylinux-001 php-5.6.30]# service php-fpm start Start php-fpm service
Starting php-fpm done
8. Check the startup status of php-fpm service
p>
[root@jimmylinux-001 php-5.6.30]# ps aux |grep php-fpm
root43099 0.0 0.0 123656 4952 ? Ss Jun 06 0:00 php-fpm : master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 43100 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43101 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43102 0.0 0.0 123656 4708 ? S Jun 06 0 :00 php-fpm: pool www
php-fpm 43103 0.0 0.0 123656 4708 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43104 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43105 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43106 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43107 0.0 0.0 123656 4712 ? S Jun 06 0:00 php-fpm : pool www
php-fpm 43108 0.0 0.0 123656 4712 ? S June 06 0:00 php-fpm: pool www
php-fpm 43109 0.0 0.0 123656 4716 ? S 6 Jun 06 0:00 php-fpm: pool www
php-fpm 43110 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43111 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43112 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
p>
php-fpm 43113 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43114 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43115 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43116 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43117 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43118 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
php-fpm 43119 0.0 0.0 123656 4716 ? S Jun 06 0:00 php-fpm: pool www
root43139 0.0 0.0 112720 984 pts/0 S+ 00:03 0:00 grep –color=auto php-fpm
12.5 Introduction to Nginx