LNMP deployment and application of theory and practical operation

LNMP deployment and application

LNMP interpretation of architecture

LNMP platform is Linux, Ngnix, MySQL, PHP combination frame
structure, need a Linux server, MySQL database, PHP parsing environment

MySQL installation configuration

In keeping with Nginx, PHP environment, where the use of source code compiler choose the installed MySQL assembly
method of deploying MySQL
compile and install MySQL
optimal adjustment
to initialize the database
start mysql database services and sets the root account password

Configuring static and dynamic separation pages, parse PHP, there are two ways you can choose
to use the FPM PHP module will access Web PHP page request to the Apache server to handle
a newer version of PHP has built FPM module, PHP is used to resolve real
cases manage and optimize the efficiency of analysis
FastCGIl the Http server and dynamic scripting languages separated
Nginx deal specifically request static, dynamic forwards the request to
PHP
FPM special request parsing PHP dynamic
way LNMP single server architecture typically used to parse PHP FPM

PHP compiler installation steps

Compile and install PHP
add compile option "--enable-fpm" to enable this module
adjusted after installation, the main path is to establish the profile of the corresponding command tool optimization, installation ZendGuardLoader (PHP parsing improve efficiency), and load the configuration
call php-fpm process to configure the machine
to establish FPM configuration file php-fpm.conf, modify configuration options, such as: PID file to run user and server processes such as the number of
start php-fpm process
server in the Nginx configuration file {} PHP configuration section configuration page module for processing requests to the FPM
Server Nginx profile in the configuration section {} PHP configuration requests to the web processing module FPM
[root @ localhost ~] # vim / usr / local / nginx /conf/nginx.conf
Server {

......
location ~ .php$ {
root
/var/www/kgc;
fastcgi pass 127.0.0.1:9000; //fpm端口号:9000
fastcgi index index.php;
include
fastcgi.conf;
......

Discuz
Comsenz (Beijing) Technology Co., Ltd. introduced a common set of community forums software-based
system, available since June 2001, is the highest in the world maturity, the maximum coverage on the
altar software systems -
PHPWind
PHPWind (referred to as : PW) is a - a forum based on PHP and MySQL program
is one of the most popular general-purpose forum program. PHPWind, formerly known as
ofstar, released in 2004, PHPWind by the Germany-day Information Technology Co., Hangzhou
Development Division, comprehensive open source free software

WordPress
using PHP language development blog platform, users can support PHP and
set up your own blog on the MySQL database server. Can also
WordPress as a content management system (CMS) to use.
A free WordPress is an open source project under the GNU General Public License
License issued
SKYUC
by the Sky network after years of development of a VOD system, perfect support
QVOD, Webplayer9 and other streaming media software

LNMP architecture combat

A remote mount the required compression packages to a local LNMP

[root @ localhost ~] # mkdir / abc // create a mount point
[root @ localhost ~] # mount.cifs //192.168.100.10/LAMP-C7 / mnt // required to mount the remote package to a local / mnt directory

Second, compile and install Nginx

1, extract the source packet to the next directory / opt

[root @ localhost ~] # cd / mnt // switch to the mounted directory
[the root @ localhost mnt] # LS
Discuz_X3.4_SC_UTF8.zip Nginx-1.12.2.tar.gz
MySQL-Boost-5.7.20.tar. PHP-7.1.20.tar.gz GZ
[the root @ localhost mnt] # Nginx zxvf the tar-1.12.2.tar.gz -C / opt // packet to extract the source Nginx / opt the
[root @ localhost mnt] # cd / opt / // switch to the directory extracting
[the root @ localhost opt] LS #
Nginx 1.12.2-RH

2, assembly package installation environment required to compile Nginx

[root @ localhost opt] # yum -y install \
gcc \ // c language
gcc-c ++ \ // c ++ language
pcre-devel \ // pcre language tools
zlib-devel // use data compression library

3. Create a user program and compile nginx Nginx
[root @ localhost opt] # useradd -M -s / sbin / nologin nginx // create the program users, security can not log-in status
[root @ localhost opt] # nginx the above mentioned id
uid = 1001 (nginx ) gid = 1001 (nginx) 1001 group = (nginx)
[the root @ localhost opt] 1.12.0 # CD-nginx / nginx // switch to the directory
[root @ localhost nginx-1.12.0] # ./configure \ / / configure nginx

--prefix = / usr / local / nginx \ // installation path
--user = nginx \ // username
--group = nginx \ // user group
--with-http_stub_status_module // state statistics module

4, compile and install

[root@localhost nginx-1.12.2]#make && make install

5, route optimization

[root @ localhost nginx] # LN -s / usr / local / nginx / sbin / nginx / usr / local / sbin /
// create a soft connecting the system to recognize nginx startup scripts
[root @ localhost nginx] # nginx -t // grammar check the configuration file
nginx: the configuration file /usr/local/nginx/conf/nginx.conf at the syntax iS the ok
nginx: the configuration file /usr/local/nginx/conf/nginx.conf the Test iS successful
[root @ localhost nginx ] # nginx // open ngnix
[root @ localhost nginx] # netstat -ntap | grep 80 // viewing port, nginx has opened
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39620 / nginx: Master
[root @ localhost nginx] # systemctl stop firewalld.service // disable the firewall
[root @ localhost nginx] # setenforce 0
[root @ localhost nginx] # nginx nginx // open service

[root@localhost nginx]# cd /etc/init.d/   //切换到启动配置文件目录
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx         //编辑启动脚本文件

    #!/bin/bash
    # chkconfig: - 99 20                                    //注释信息
    # description: Nginx Service Control Script
    PROG="/usr/local/nginx/sbin/nginx"           //设置变量为nginx命令文件
    PIDF="/usr/local/nginx/logs/nginx.pid"       //设置变量PID文件 进程号为5346
    case "$1" in  
        start)
            $PROG                                              //开启服务
            ;;
        stop)
            kill -s QUIT $(cat $PIDF)                    //关闭服务
            ;;
        restart)                                                  //重启服务
            $0 stop
            $0 start
            ;;
        reload)                                                  //重载服务
            kill -s HUP $(cat $PIDF)
            ;;
        *)                                                           //错误输入提示
                    echo "Usage: $0 {start|stop|restart|reload}"
                    exit 1
    esac
    exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx    //授予启动脚本执行权限
[root@localhost init.d]# chkconfig --add nginx          //添加到service管理器
[root@localhost init.d]# service nginx stop                //使用service停止nginx服务
[root@localhost init.d]# service nginx start                //使用service启动nginx服务
[root@localhost ~]# vim /lib/systemd/system/nginx.service      //创建配置文件

[Unit]
Description=nginx                                            //描述
After=network.target                                        //描述服务类型
[Service]
Type=forking                                                    //后台运行形式
PIDFile=/usr/local/nginx/logs/nginx.pid            //PID文件位置
ExecStart=/usr/local/nginx/sbin/nginx              //启动服务
ExecReload=/usr/bin/kill -s HUP $MAINPID    //根据PID重载配置
ExecStop=/usr/bin/kill -s QUIT $MAINPID       //根据PID终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target

[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service     //设置执行权限
[root@localhost ~]# systemctl stop nginx.service       //关闭nginx 
[root@localhost ~]# systemctl start nginx.service       //开启nginx

Third, the installation MySQL

1, the mounting assembly environment
[root @ localhost ~] # yum install -y \ // mounting assembly environment

ncurses \
ncurese-devel \ // control library terminal screen display of
bison \ // parsing tools
cmake // cmake tool
[root @ localhost ~] # useradd -s / sbin / nologin mysql user to create a program //

2, to extract the source packet opt ​​/ directory

[root@localhost ~]# cd /mnt
[root@localhost mnt]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt   ##解压源码包到/opt
[root@localhost mnt]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20  nginx-1.12.2  rh

3, cmake configuration

[root@localhost opt]# cd mysql-5.7.20/       //切换到MySQL目录下
[root@localhost mysql-5.7.20]# cmake \     //cmake配置
-DCMAKE_INSTALL_PREFIX=/usr/localmysql \            //安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //定义sock文件连接数据库文件
-DSYSCONFDIR=/etc \                                                   //配置文件目录
-DSYSTEMD_PID_DIR=/usr/local/mysql \                      //PID文件目录
-DDEFAULT_CHARSET=utf8 \                                       //指定字符集
-DDEFAULT_COLLATION=utf8_general_ci \                 //指定字符集默认
-DWITH_INNOBASE_STORAGE_ENGINE=1 \            //存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \                 //数据库数据文件目录
-DWITH_BOOST=boost \                                               //底层运行库
-DWITH_SYSTEMD=1                                                   //主从参数

4, compile and install

[root@localhost mysql-5.7.20]#make && make install

5, modify configuration files Mysql

[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/   
//数据库目录进行权限调整
[root@localhost mysql-5.7.20]# vim /etc/my.cnf     
//调整配置文件

    [client]                            //客户端
    port = 3306
    default-character-set=utf8
    socket = /usr/local/mysql/mysql.sock

    [mysql]                           //客户端     
    port = 3306
    default-character-set=utf8
    socket = /usr/local/mysql/mysql.sock

    [mysqld]                         //服务器        
    user = mysql                  //用户
    basedir = /usr/local/mysql      //设置mysql的安装目录
    datadir = /usr/local/mysql/data    //设置mysql数据库的数据的存放目录
    port = 3306                    //设置3306端口
    character_set_server=utf8            //中文字符集
    pid-file = /usr/local/mysql/mysqld.pid     //pid文件路径
    socket = /usr/local/mysql/mysql.sock     //sock文件路径
    server-id = 1                                           //主从服务参数

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
//支持模块

[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
    //将MySQL命令写到本地主机环境配置中
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile   
     //设置全局环境配置
[root@localhost mysql-5.7.20]# source /etc/profile    
    //重启配置文件

6, initialize the database
[root @ localhost MySQL-5.7.20] # cd / usr / local / MySQL /
[root @ localhost MySQL] # bin / mysqld \

--initialize-insecure \ ## initializes
--user = mysql \ ## user
--basedir = / usr / local / mysql \ ## directory installation
--datadir = / usr / local / mysql / data ## database data file table of Contents

Easy to use systemctl Management 7, MySQL copy service profile to / usr / lib / systemd / system /

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 
//便于systemctl管理
[root@localhost mysql]# systemctl enable mysqld   //开机自启动
[root@localhost mysql]# systemctl start mysqld.service     //开启数据库
[root@localhost mysql]# netstat -ntap | grep 3306              //查看MySQL端口号开启情况
tcp6  0  0 :::3306    :::*       LISTEN   59464/mysqld   

8, set the mysql password

[root@localhost mysql]# mysqladmin -u root -p password
Enter password:               
New password:                 //新密码
Confirm new password:     //确认密码

Fourth, compile and install PHP

1, the installation environment dependencies

[root@localhost mysql]# yum install -y \
> libjpeg \                              //jpeg图片格式和开发包
> libjpeg-devel \
> libpng libpng-devel \           //png图片和开发包
> freetype freetype-devel \    //字体库
> libxml2 \                              //xml文件库
> libxml2-devel \
> zlib zlib-devel \                    //压缩库 
> curl curl-devel \                   //支持数据文件下载工具
> openssl openssl-devel        //安全访问连接

2, to extract the source packet opt ​​/ directory

[root@localhost mysql]# cd /abc   
[root@localhost abc]# tar jxvf php-7.1.10.tar.bz2 -C /opt    
[root@localhost abc]# cd /opt
[root@localhost opt]# ls   
mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh

3, the configuration parameters php

[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10]# ./configure 
--prefix=/usr/local/php                        //安装路径
--with-mysql-sock=/usr/local/mysql/mysql.sock   ##连接文件建立通信桥梁
--with-mysqli                                    //客户端支持库
--with-zlib                                         //压缩
--with-curl                                        //支持上传下载功能
--with-gd                                          //gd图像支持图片处理库
--with-jpeg-dir                                  //jpeg
--with-png-dir                                   //png
--with-freetype-dir                            //字体
--with-openssl                                  //安全访问连接
--enable-fpm                                    //fpm支持动态请求模块
--enable-mbstring                            //支持多字节的字符串
--enable-xml                                    //xml文件
--enable-session                             //session支持会话
--enable-ftp                                     //ftp服务
--enable-pdo                                   //驱动连接管理
--enable-tokenizer                          //PHP自带函数
--enable-zip                                    //zip压缩包

4, compile and install

[root@localhost php-7.1.10]# make && make install

5, configure the core configuration file
(php.ini core configuration file, php-fpm.conf process service profile, www. Conf extension configuration file)

[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini       //复制到安装目录lib库中
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini   //配置核心配置文件

mysqli.default_socket = /usr/local/mysql/mysql.sock     //默认连接文件
date.timezone = Asia/Shanghai                                      //时间

[root@localhost php-7.1.10]# /usr/local/php/bin/php -m   //验证安装的模块

6, module configuration and optimization FPM

[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf   //优化复制默认进程服务配置文件
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf   //优化复制扩展配置文件
[root@localhost php-fpm.d]# cd /usr/local/php/etc/  
[root@localhost etc]# vim php-fpm.conf      //开启fpm.pid进程
pid = run/php-fpm.pid
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
[root@localhost etc]# netstat -ntap | grep 9000     //查看端口信息
tcp   0 0 127.0.0.1:9000   0.0.0.0:*    LISTEN   69104/php-fpm: mast 
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/   //创建软连接便于系统识别
[root@localhost etc]# ps aux | grep -c "php-fpm"
4

7, Nginx configuration to support PHP function

[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf    ##配置nginx配置文件
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;     //站点路径
        include        fastcgi_params;
    }       
[root@localhost etc]# vim /usr/local/nginx/html/index.php               //测试php网页
<?php
phpinfo();
?>

[root@localhost etc]# nginx -s stop           //停止nginx服务
[root@localhost etc]# nginx                      //启动nginx服务

8, using the test machine test page
input http://192.168.35.134/index.php browser
LNMP deployment and application of theory and practical operation

9, enter the database administrator to create a database and set bbs and password

[root@localhost etc]# mysql -u root -p
Enter password:      //进入数据库,密码为之前设定的abc23
mysql> CREATE DATABASE BBS;   //创建bbs数据库
Query OK, 1 row affected (0.00 sec)

mysql> GRANT all ON bbs.* TO 'bbsusers'@'%' IDENTIFIED BY 'admin123';  
//提权数据库用户bbsuser为管理员并设定密码
Query OK, 0 rows affected, 1 warning (0.00 sec)       

mysql> GRANT all ON bbs.* TO 'bbsusers'@'localhost' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;         //刷新数据库
Query OK, 0 rows affected (0.00 sec)

mysql> quit       //退出

[root@localhost etc]# vim /usr/local/nginx/html/index.php   //测试数据库连接状态
<?php
$link=mysqli_connect('192.168.131.129','bbsusers','admin123');
if($link) echo "<h1>Success!</h1>";
else echo "Fail!!";
?>
[root@localhost etc]# systemctl restart nginx.service     //重启服务

V. Installation Discuz forum

1. Unzip the forum package to the / opt directory and copy the directory contents to the site bbs

[root@localhost etc]# cd /mnt                      
[root@localhost mnt]# unzip  Discuz_X3.4_SC_UTF8.zip -d /opt    //解压到/opt下
[root@localhost mnt]# cd /opt
[root@localhost opt]# ls
dir_SC_UTF8  mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh  说明.htm
[root@localhost opt]# cd dir_SC_UTF8/          //进入论坛目录
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/     
//复制/opt目录里的内容到html站点的bbs目录中

2, the user enters the site and to provide the right program

[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/          //切入bbs站点目录
[root@localhost bbs]# chown -R root:nginx ./config/                   //提权程序用户提权
[root@localhost bbs]# chown -R root:nginx ./data/                     //修改nginx属组
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/                            //修改所有权限
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

3, the browser input 192.168.131.129/bbs/install/index.php site, enter Discuz forum Installation Wizard
LNMP deployment and application of theory and practical operation

4, the operating environment for a new installation
LNMP deployment and application of theory and practical operation

5, install the database
LNMP deployment and application of theory and practical operation

6, successfully created and accessed forum
LNMP deployment and application of theory and practical operation

Guess you like

Origin blog.51cto.com/14449528/2449548