实验八 LNMP平台搭建
LNMP也称为LEMP, E来自nginx的发音【engine x】
LNMP 就像构建LAMP平台一样,构建LNMP平台也需要用到Linux服务器,Mysql数据库,PHP解析环境等应用,p (PHP ,Perl ,Python)
LNMP 就是基于nginx服务的平台
LAMP就是基于apache服务的平台
wamp是什么? xampp
wamp就是基于windows上apache的mysql php
LNMP也称为LEMP, E来自nginx的发音【engine x】
LNMP 就像构建LAMP平台一样,构建LNMP平台也需要用到Linux服务器,Mysql数据库,PHP解析环境等应用,p (PHP ,Perl ,Python)
LNMP 就是基于nginx服务的平台
LAMP就是基于apache服务的平台
wamp是什么? xampp
wamp就是基于windows上apache的mysql php
一、部署Nginx软件
1)安装支持软件:
[root@nginx~]#systemctl stop firewalld
[root@nginx~]#iptables-F
[root@nginx~]#setenforce 0
[root@nginx~]# yum -y install pcre-devel zlib-develo penssl-devel
2)创建运行用户、组:
[root@nginx~]#useradd -M -s /sbin/nologin nginx
3)编译安装nginx:
[root@nginx~]# tar xfnginx-1.14.2.tar.gz -C /usr/src/
4)配置编译:
[root@nginx~]# cd /usr/src/nginx-1.14.2/
[root@nginxnginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module--with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module&&make && make install
[root@nginxnginx-1.14.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
5)启动、停止Nginx:
[root@nginxconf]#nginx
[root@nginxconf]#killall -3 nginx
二、安装Mysql数据库
1)基于源码包安装MySQL
[root@nginx~]# yum -y install ncurses-develc make
[root@nginx~]#useradd -M -s /sbin/nologin mysql
[root@nginx~]# tar xf mysql-5.7.24.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/mysql-5.7.24/
[root@nginx~]#mkdir /usr/local/boost
[root@nginx~]# cd /usr/local/boost
[root@nginxboost]# tar xf boost_1_59_0.tar.gz
[root@nginx mysql-5.7.24]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc-DWITH_BOOST=/usr/local/boost&& make && make install
2)安装后的调整
[root@nginx~]# cd /usr/local/mysql/
[root@nginxmysql]#chown -R mysql:mysql ./
[root@nginxmysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
3)初始化数据库
[root@nginxmysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2018-12-08T01:51:39.798903Z 1 [Note] A temporary password is generated for root@nginx: TvC:Rm1ZlxtG
4)设置环境变量
[root@nginx mysql-5.7.24]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@nginx mysql-5.7.24]#source /etc/profile
5)启动
[root@nginx mysql-5.7.24]# /usr/local/mysql/support-files/mysql.server start
后期修改数据库用户的密码:
[root@nginx~]#mysqladmin -u root -p'TvC:Rm1ZlxtG' password '123456'
三、安装PHP解析环境
1)编译安装php
[root@nginx~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@nginx~]# tar xfphp-5.6.39.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/php-5.6.39/
[root@nginxphp-5.6.39]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
2)安装后的调整
[root@nginxphp-5.6.39]#cp php.ini-production /usr/local/php5/php.ini
[root@nginxphp-5.6.39]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@nginxphp-5.6.39]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
3)安装ZendGuardLander
[root@nginx~]# tar xf zend-loader-php5.6-linux-x86_64_update1.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/zend-loader-php5.6-linux-x86_64/
[root@nginx zend-loader-php5.6-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[root@nginx zend-loader-php5.6-linux-x86_64]#vim /usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
配置Nginx支持PHP环境
[root@nginx~]# cd /usr/local/php5/etc/
[root@nginxetc]# cp php-fpm.conf.default php-fpm.conf
[root@nginxetc]#useradd -M -s /sbin/nologin php
[root@nginxetc]# vim php-fpm.conf
25 pid = run/php-fpm.pid //确认pid文件位置
149 user = php //运行用户
150 group = php //运行组
246pm.start_servers = 20 //启动时开启的进程数
251pm.min_spare_servers = 5 //最少空闲进程数
256pm.max_spare_servers = 35 //最大空闲进程数
241pm.max_children = 50 //最多空闲进程数
启动
[root@nginxetc]# /usr/local/sbin/php-fpm
[root@nginxetc]# vim /usr/local/nginx/conf/nginx.conf
server {
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000; //php-fpm的监听地址
fastcgi_indexindex.php; //PHP首页文件
include fastcgi.conf; //包括fastcgi.conf样本配置
}
}
重启
[root@nginxetc]#killall -HUP nginx
4、LNMP平台中部署WEB应用
[root@nginx~]# unzip ComsenzDiscuz-DiscuzX-master.zip
[root@nginx~]# cd DiscuzX/
[root@nginxDiscuzX]# mv upload/ /usr/local/nginx/html/bbs
浏览器访问http://192.168.200.111/bbs/install/index.php
设置权限及模板文件
[root@nginx~]# cd /usr/local/nginx/html/bbs/config/
[root@nginxconfig]# cp config_global_default.phpconfig_global.php
[root@nginxconfig]# cp config_ucenter_default.phpconfig_ucenter.php
[root@nginx~]# cd /usr/local/nginx/html/bbs
[root@nginxbbs]#chmod -R 777 config/ data/ uc_client/ uc_server/
准备数据库并配置相关授权
[root@nginx~]#mysql -uroot -p123456
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on bbs.* to 'bbs'@'localhost' identified by 'bbs123456';
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
1)安装支持软件:
[root@nginx~]#systemctl stop firewalld
[root@nginx~]#iptables-F
[root@nginx~]#setenforce 0
[root@nginx~]# yum -y install pcre-devel zlib-develo penssl-devel
2)创建运行用户、组:
[root@nginx~]#useradd -M -s /sbin/nologin nginx
3)编译安装nginx:
[root@nginx~]# tar xfnginx-1.14.2.tar.gz -C /usr/src/
4)配置编译:
[root@nginx~]# cd /usr/src/nginx-1.14.2/
[root@nginxnginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module--with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module&&make && make install
[root@nginxnginx-1.14.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
5)启动、停止Nginx:
[root@nginxconf]#nginx
[root@nginxconf]#killall -3 nginx
二、安装Mysql数据库
1)基于源码包安装MySQL
[root@nginx~]# yum -y install ncurses-develc make
[root@nginx~]#useradd -M -s /sbin/nologin mysql
[root@nginx~]# tar xf mysql-5.7.24.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/mysql-5.7.24/
[root@nginx~]#mkdir /usr/local/boost
[root@nginx~]# cd /usr/local/boost
[root@nginxboost]# tar xf boost_1_59_0.tar.gz
[root@nginx mysql-5.7.24]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc-DWITH_BOOST=/usr/local/boost&& make && make install
2)安装后的调整
[root@nginx~]# cd /usr/local/mysql/
[root@nginxmysql]#chown -R mysql:mysql ./
[root@nginxmysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
3)初始化数据库
[root@nginxmysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2018-12-08T01:51:39.798903Z 1 [Note] A temporary password is generated for root@nginx: TvC:Rm1ZlxtG
4)设置环境变量
[root@nginx mysql-5.7.24]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@nginx mysql-5.7.24]#source /etc/profile
5)启动
[root@nginx mysql-5.7.24]# /usr/local/mysql/support-files/mysql.server start
后期修改数据库用户的密码:
[root@nginx~]#mysqladmin -u root -p'TvC:Rm1ZlxtG' password '123456'
三、安装PHP解析环境
1)编译安装php
[root@nginx~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@nginx~]# tar xfphp-5.6.39.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/php-5.6.39/
[root@nginxphp-5.6.39]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
2)安装后的调整
[root@nginxphp-5.6.39]#cp php.ini-production /usr/local/php5/php.ini
[root@nginxphp-5.6.39]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@nginxphp-5.6.39]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
3)安装ZendGuardLander
[root@nginx~]# tar xf zend-loader-php5.6-linux-x86_64_update1.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/zend-loader-php5.6-linux-x86_64/
[root@nginx zend-loader-php5.6-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[root@nginx zend-loader-php5.6-linux-x86_64]#vim /usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
配置Nginx支持PHP环境
[root@nginx~]# cd /usr/local/php5/etc/
[root@nginxetc]# cp php-fpm.conf.default php-fpm.conf
[root@nginxetc]#useradd -M -s /sbin/nologin php
[root@nginxetc]# vim php-fpm.conf
25 pid = run/php-fpm.pid //确认pid文件位置
149 user = php //运行用户
150 group = php //运行组
246pm.start_servers = 20 //启动时开启的进程数
251pm.min_spare_servers = 5 //最少空闲进程数
256pm.max_spare_servers = 35 //最大空闲进程数
241pm.max_children = 50 //最多空闲进程数
启动
[root@nginxetc]# /usr/local/sbin/php-fpm
[root@nginxetc]# vim /usr/local/nginx/conf/nginx.conf
server {
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000; //php-fpm的监听地址
fastcgi_indexindex.php; //PHP首页文件
include fastcgi.conf; //包括fastcgi.conf样本配置
}
}
重启
[root@nginxetc]#killall -HUP nginx
4、LNMP平台中部署WEB应用
[root@nginx~]# unzip ComsenzDiscuz-DiscuzX-master.zip
[root@nginx~]# cd DiscuzX/
[root@nginxDiscuzX]# mv upload/ /usr/local/nginx/html/bbs
浏览器访问http://192.168.200.111/bbs/install/index.php
设置权限及模板文件
[root@nginx~]# cd /usr/local/nginx/html/bbs/config/
[root@nginxconfig]# cp config_global_default.phpconfig_global.php
[root@nginxconfig]# cp config_ucenter_default.phpconfig_ucenter.php
[root@nginx~]# cd /usr/local/nginx/html/bbs
[root@nginxbbs]#chmod -R 777 config/ data/ uc_client/ uc_server/
准备数据库并配置相关授权
[root@nginx~]#mysql -uroot -p123456
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on bbs.* to 'bbs'@'localhost' identified by 'bbs123456';
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)