Installation principle and steps of lnmp architecture

LNMP is Linux+Nginx+MySQL+PHP, Linux is the operating system of the server, and MySQL is the database. It is a group of open source software architectures for building dynamic websites. They are independent software services. They have high compatibility when used together, and together they form a powerful WEB application platform.

Nginx is a high-performance web server, which cannot handle PHP itself. When receiving a request, if it is judged that it is a PHP request, it will hand over the request to the PHP interpreter for processing, and then return the result to the Client. Nginx generally forwards the request to the fast-cgi management process for processing, and the fast-cgi management process selects the cgi sub-process to process the request, and then returns the result to Nginx.

LNMP is Linux+Nginx+MySQL+PHP, Linux is the operating system of the server, and MySQL is the database.

Difference (lamp and lnmp)
Apache generally starts PHP as a module of its own; while Ngnix forwards the http request variable to the PHP process, that is, a PHP independent process, which communicates with Ngnix. This method is called Fast-CGI operation mode . So PHP compiled by Apache cannot be used with Nginx.

The construction steps of lnmp

First, mysql source installation

Compile and install the source code to 20G, 9G is not enough! ! ! ! ! !

1. The installation package
yum install -y gcc gcc-c++ ncurses-devel bison cmake-2.8.12.2-4.el6.x86_64.rpm – because the cmake version of 6.5 is low, you need to upgrade the version —— – partial commercialization (see cmake version yum list cmake)

Source package: mysql-boost-5.7.17.tar.gz

2. Unzip and install
tar zxf mysql-boost-5.7.17.tar.gz

在解压目录下:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.17/boost/boost_1_59_0/

-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \  #安装目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \    #数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \   #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \    #安装 myisam 存储引擎 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \  #安装 innodb 存储引擎
-DDEFAULT_CHARSET=utf8 \    #默认使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \   #校验字符
-DEXTRA_CHARSETS=all \  #安装所有扩展字符集
-DWITH_BOOST=/mnt/mysql-5.7.11/boost/boost_1_59_0/  ##安装过程中指定下载目录

make && make install

If an error occurs during the compilation process, the cache should be cleaned up and then recompiled
make clean #Clear the cache
rm -rf CMakeCache.txt #When there is an error in the compilation, you also need to delete the cache

3. Initialization of the database

(1) Creation of database users
groupadd -g 27 mysql
useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/ mysql
usermod -s /sbin/nologin mysql #Security settings, prohibit interactive login

(2) Environment configuration
vim ~/.bash_profile #Set environment variables for easy login

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
cp /usr/local/lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld  #添加启动脚本

(3) Change the configuration file
First backup and then copy the required past
cp /etc/my.cnf /etc/my.cnf.bak
cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/ my.cnf

vim /etc/my.cnf

[mysqld]
datadir=/usr/local/lnmp/mysql/data
socket=/usr/local/lnmp/mysql/data/mysql.sock
user=mysql

(4) Database initialization and password change
mysqld –initialize –user=mysql #Initialize, copy the temporary password
chown root.mysql /usr/local/lnmp/mysql -R
chown mysql /usr/local/lnmp/mysql/data -R
/etc/init.d/mysqld start
mysql_secure_installation #Set password
mysql -p #Login

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[root@server1 mysql]# mysql_secure_installation 
New password:           -----新密码

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: ----是否检测密码强度(回车默认noUsing existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : ----------是否更改root密码

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.--------删除匿名用户


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y------------取消root用户远程登陆
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y------------删除test库和对test库的访问权限
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y---------刷新授权表使修改生效
Success.

All done! 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Second, php source code installation

1. Installation of dependent packages
yum install -y libxml2-devel openssl-devel curl-devel libjpeg-turbo-devel gd-devel-2.0.35-11.el6.x86_64.rpm (graphics, pictures) libmcrypt-2.5.8- 9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm re2c-0.13.5-1.el6.x86_64.rpm gmp-devel net-snmp-devel libpng-devel freetype-devel

Source package: php-5.6.35.tar.bz2

2. Unzip and install
tar jxf php-5.6.35.tar.bz2

在解压目录下:
./configure –prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc/ –enable-mysqlnd –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-openssl –with-snmp –with-gd –with-zlib –with-curl –with-libxml-dir –with-png-dir –with-jpeg-dir –with-freetype-dir –with-pear –with-gettext –with-gmp –enable-inline-optimization –enable-soap –enable-ftp –enable-sockets –enable-mbstring –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx –with-mcrypt –with-mhash

make && make install

3.php configuration
(1) Check the installed php size
cd /usr/local/lnmp/php/
du -sh (usually so large 109M.
(2) Copy the file for subsequent operations
cd /root/php-5.6.35
cp php.ini-production /usr/local/lnmp/php/etc/php.ini (must end with .ini)
cd /root/php-5.6.35/sapi/fpm/
file init.d.php-fpm ##View the file
typecp init.d.php-fpm /etc/init.d/php-fpm ##The fixed location of the script in Enterprise Six
chmod +x /etc/init.d/php-fpm
(3) Configuration file Changes
cd /usr/local/lnmp/php/etc/
ls
vim php.ini ##Change timezone

   925 date.timezone = Asia/shanghai

(4) Open php-fpm service
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

   25 pid = run/php-fpm.pid

/etc/init.d/php-fpm start (only the user can create the service, otherwise there is no legal identity to start)
(5) nginx user creation
useradd -u 800 -M -d /usr/local/lnmp/nginx nginx

Three, nginx source code installation

1. Installation of dependent packages
yum install pcre-devel openssl-devel zlib-devel -y

Source package:
nginx-1.14.0.tar.gz

2. Unzip and install
tar zxf nginx-1.14.0.tar.gz

(1) Hiding the version number:
vim /mnt/nginx-1.10.1/src/core/nginx.h

    #define NGINX_VER          "nginx/" #为了安全,不显示版本号

(2) Reduce compilation memory
vim /mnt/nginx-1.10.1/auto/cc/gcc

    # debug
    #CFLAGS="$CFLAGS -g"   #关闭DEBUG,减少内存

In the decompression directory:
./configure –prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module –with-file-aio –with-threads –user=nginx –group=nginx #The required modules are self- definition

make && make install

ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/

3. Add the path of php
cd /usr/local/lnmp/php
vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnm
p/php/bin

source ~/.bash_profile

4. Change the configuration file and open the nginx service
vim /usr/local/lnmp/nginx/conf/nginx.conf

    location ~\ \.php\$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
       # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi.conf;
    }
    server {
            listen 80;
            server_name bbs.xinhao.com;

            location / {
                    root /bbs;
                    index index.php;
            }

Check if the configuration is successful nginx -t
start the service: nginx

Test:
/usr/local/lnmp/nginx/html/
vim index.php ##php test page writing

##After the above three steps, the Lnmp framework has been basically built successfully. Let's test it by building a forum.

Fourth, the construction of a simple forum
1. unzip Discuz_X3.2_SC_UTF8.zip ##Unzip

  1. cd readme/
    less readme.txt ##View the installation process

  2. mv upload/ /usr/local/lnmp/nginx/html/ ##Push the forum to the default release directory of nginx

  3. cd /usr/local/lnmp/nginx/html/bbs
    chmod 777 config/ data/ uc_client/ uc_server/ -R

  4. cd /usr/local/lnmp/php/etc/
    vim php.ini (modified as follows)

    1001 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock    
    1150 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
    1210 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock

6. After changing the configuration file refresh service, view the port

/etc/init.d/php-fpm reload
to view port 9000: netstat -antlp | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7491/php-fpm

7. Browser
test Go in and find that the database permission is denied: authorize chmod 755 /usr/local/lnmp/mysql/data/
At this time, the installation is complete.

Guess you like

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