12-week class LNMP architecture introduction, MySQL installation, PHP installation, Nginx introduction

LNMP. Combination of Linux, Nginx, Mysql, PHP. Nginx is a web service software similar to Apache. It is worse than Apache in processing static pages, but not as good as Apache in processing dynamic pages.

MySQL installation
First, we enter the /usr/local/src directory. This is to unify the download directory and facilitate management.
Then we start to download Mysql
[root@linletao-001 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz (this It is a binary package compiled by the surface, the download address is r.aming.com )
After downloading, decompress the
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

After decompression, move the mysql directory to /usr/local and change its name to mysql. What we should pay attention to here is that if there is mysql in the target directory, then we must delete it first, because if there is mysql in the target directory , the system will put the mysql we want to move to the target directory.
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

Then we start the initialization. The initialization process is to generate some directories required for mysql to start. There are two ok here. We can also echo $? Check the result, the correct result is 0
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

Then copy the configuration file
cp support-files/my-default.cnf /etc/my.cnf

After copying, enter the editing mode and check whether some of his parameters are configured correctly
vim /etc/my.cnf

Then copy the startup script
cp support-files/mysql.server /etc/init.d/mysqld
and then edit
vi /etc/init.d/mysqld
define basedir and datadir
vim /etc/init.d/mysqld
find and edit

Then start mysql
/etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/linletao-001.err'.
. SUCCESS! (start successful)

Then we add it to the list of services
chkconfig --add mysqld

Set the boot to start
chkconfig mysqld on

At this time, we can use service mysqld to control mysql, stop stop, and start start. Restart can be restarted.

The installation
of php in lnmp is different from the installation of php in lamp, because php in lnmp is given to Nginx in the form of fastcgi, which can also be understood as Nginx proxying php's fastcgi, while apache uses php as its own module to call.
First go to /usr/local/src
and then start to download php
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
then extract php
tar zxf php-5.6.30.tar.gz
Then we start compiling php for Nginx
./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
This is different from when we compile apache. There is one more --enable-fpm here. If this parameter is not added, there will be no php-fpm executable file generation, and the php-fpm service cannot be started.

During the compilation process, we should pay attention to the error
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
An error occurs here, prompting Missing cURL, we can use yum to install.
yum install -y libcurl-devel
After the installation is complete, we continue to compile. After compiling, we can find that php-fpm has two more directories sbin and var than php
[root@linletao-001 php-5.6.30]# ls / usr/local/php-fpm/
bin etc include lib php sbin var
[root@linletao-001 php-5.6.30]# ls /usr/local/php
bin etc include lib php
where sbin includes the php we need -fpm, and var contains log.
We can also use -m to view the modules loaded in php-fpm, and -t can check whether the syntax is wrong.
[root@linletao-001 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t
[22-Apr-2018 22:33:17] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[22-Apr -2018 22:33:17] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[22-Apr-2018 22:33:17] ERROR: FPM initialization failed
Here we found the error, /usr/local/php-fpm/etc/php-fpm.conf': No such file or directory, missing configuration file. So I have to add the configuration file cp php.ini-production /usr/local/php-fpm/etc/php.ini
to him first and then edit the file php-fpm.conf vim php-fpm.conf https://coding For the specific content of .net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf, we can refer to this URL and copy its content . After editing, save and exit.




Then copy the startup script
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
then change the permissions
chmod 755 /etc/init.d/php-fpm
add it to the list of services
chkconfig - -add php-fpm
then add it to boot
chkconfig php-fpm on
then start php-fpm
service php-fpm start
Starting php-fpm [22-Apr-2018 22:54:59] ERROR: [pool www] cannot get uid for user 'php-fpm'
[22-Apr-2018 22:54:59] ERROR: FPM initialization failed
failed
At this time, an error is reported, saying that a user php-fpm does not exist, then we will create this user
useradd -s /sbin/nologin php-fpm
and then start php-fpm
service php-fpm start
Starting php-fpm done
At this point the startup has been successful
and then we can check
ps aux|grep php-fpm

Nginx introduction
Nginx official website nginx.org
Nginx is a lightweight Web server/reverse proxy server and email (IMAP/POP3) proxy server, and released under a BSD-like protocol. Its characteristics are that it occupies less memory and has strong concurrency capabilities. In fact, the concurrency capabilities of nginx are indeed better among web servers of the same type. The users of nginx websites in mainland China include: Baidu, JD.com, Sina, NetEase, Tencent, Taobao, etc.
The famous branch of Nginx, Tengine developed by Taobao 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 has added some customized modules, which are outstanding in terms of safe speed limit. Support js, css merging
Nginx application scenarios: web service, reverse proxy, load balancing.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324751064&siteId=291194637