LNMP架构及应用部署

安装nginx

关闭防火墙和selinux

[root@localhost ~]#systemctl stop firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]#iptables -F

安装依赖软件

[root@localhost ~]# mount /dev/cdrom /mnt —挂载光盘(先要创建yum仓库)

[root@localhost ~]# yum -y install pcre-devel zlib-devel

创建管理nginx用户

[root@localhost ~]# useradd -M -s /sbin/nologin nginx

配置nginx

[root@localhost ~]# rz

[root@localhost ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src

[root@localhost ~]# cd /usr/src/nginx-1.16.0/

[root@localhost nginx-1.16.0]#

配置nginx

[root@localhost nginx-1.16.0]# ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –user=nginx(#如果没启动成功,可能是缺少C环境安装gcc)

编译安装

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

优化Nginx命令

[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/

检测配置文件是否有错误

[root@localhost ~]# nginx -t

[root@localhost etc]# vim /etc/init.d/nginx ——进入nginx脚本

#!/bin/bash

#chkconfig:2345 99 20

# description: Nginx Server Control Script

PROG=”/usr/local/nginx/sbin/nginx”

PIDF=”/usr/local/nginx/logs/nginx.pid”

PROG_FPM=”/usr/local/sbin/php-fpm”

PIDF_FPM=”/usr/local/php5/var/run/php-fpm.pid”

case “$1” in

start)+

$PROG

$PROG_FPM

;;

stop)

kill -s QUIT $(cat $PIDF)

kill -s QUIT $(cat $PIDF_FPM)

;;

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 ~]# chmod +x /etc/init.d/nginx

[root@localhost ~]# chkconfig –add nginx

安装mysql数据库

[root@localhost conf]# yum -y install libaio

先查看有没有libaio依赖包

上传MySQL二进制安装包

[root@localhost ~]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local

——解压MySQL

[root@localhost ~]# cd /usr/local/

[root@localhost local]# mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql ——改名字

[root@localhost local]# useradd -s /sbin/nologin mysql ——添加用户和组

[root@localhost local]# cd mysql/

[root@localhost mysql]# chown -R mysql:mysql ./ ——将当前目录下的用户和组都递归给入权限

[root@localhost ~]# /usr/local/mysql/bin/mysqld –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –initialize —–初始化数据库

[root@localhost mysql]# 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

[root@localhost mysql]# ./support-files/mysql.server start ——重启服务

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld ——将MySQL服务加入到系统服务当中

[root@localhost mysql]# chmod +x /etc/init.d/mysqld ——将脚本加入执行权限

[root@localhost ~]# chkconfig –add mysqld ——优化命令

[root@localhost ~]# systemctl start mysqld ——启动

[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/bin/

[root@localhost ~]# mysqladmin -uroot -p’T;PNK1Odu:i<' password 123456 ——修改MySQL密码

[root@localhost ~]# mysql -uroot -p123456——登录MySQL

安装PHP

[root@localhost ~]# yum -y install gd libxml2-devel.x86_64 libjpeg-devel libpng-devel

——查看是否安装依赖包

上传PHP安装包

[root@localhost ~]# tar xf php-5.6.39.tar.gz -C /usr/src——解压安装包

[root@localhost ~]# cd /usr/src/php-5.6.39/——进入到解压路径

[root@localhost php-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-jbeg-dir=/usr/lib && make && make install ——进行安装

[root@localhost php-5.6.39]# cp php.ini-production /usr/local/php5/php.ini

——准备配置文件

[root@localhost php-5.6.39]# ln -s /usr/local/php5/bin/* /usr/local/bin/

[root@localhost php-5.6.39]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/ ——命令优化

上传zend -loader安装包

[root@localhost ~]# tar xf zend-loader-php5.6-linux-x86_64_update1.tar.gz ——解压

[root@localhost ~]# cd zend-loader-php5.6-linux-x86_64/ 进入解压路径

[root@localhost zend-loader-php5.6-linux-x86_64]#

cp ZendGuardLoader.so /usr/local/php5/lib/php—-复制

[root@localhost zend-loader-php5.6-linux-x86_64]# vim /usr/local/php5/php.ini

——进入php配置文件

zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so

zend_loader.enable=1 ———–写入两行

[root@localhost zend-loader-php5.6-linux-x86_64]# cd /usr/local/php5/etc/

[root@localhost etc]# ls

pear.conf php-fpm.conf.default

[root@localhost etc]# mv php-fpm.conf.default php-fpm.conf ——调整

[root@localhost etc]# vim php-fpm.conf ——进入主配置文件

149 user = php

150 group = php

241 pm.max_children = 50

246 pm.start_servers = 20

251 pm.min_spare_servers = 5

256 pm.max_spare_servers = 35

[root@localhost etc]# useradd -M -s /sbin/nologin php ——创建程序用户

[root@localhost etc]# /usr/local/sbin/php-fpm ——启动

[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf——进入主配置文件

添加一个location

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

第一个人location也要加一个index.php

[root@localhost html]# systemctl restart nginx ——重启

[root@localhost html]# vim /usr/local/nginx/html/php.php ——编写测试文件

phpinfo();

?>

客户端浏览http://192.168.200.112/php.php

[root@localhost html]# vim /usr/local/nginx/html/mysql.php ——连接mysql

$link=mysqli_connect(‘localhost’,’root’,’123456′);

if($link) echo”

陈佳峰没u有小jj

“;

mysqli_close();

?>

访问:http://192.168.200.112/mysql.php

LNMP平台中部署WEB应用-1

  1. 解压

[root@localhost ~]# unzip SKYUC.v3.4.2.SOURCE.zip

[root@localhost ~]# cd SKYUC.v3.4.2.SOURCE

[root@localhost SKYUC.v3.4.2.SOURCE]# rm -rf /usr/local/nginx/html/*

[root@localhost SKYUC.v3.4.2.SOURCE]# cp -rf wwwroot/ /usr/local/nginx/html/

[root@localhost SKYUC.v3.4.2.SOURCE]# cd /usr/local/nginx/html

  1. 属主

[root@localhost html]#cd wwwroot

[root@localhost wwwroot]# chown -R php:php admincp/data/templates/upload/#给这四个目录属主属组全部更改为php

3.创建数据库和授权用户

[root@localhost html]# mysql -u root -p123456

mysql> create database skyuc;

mysql> grant all on skyuc.* to skyuc@localhost identified by ‘123’;

mysql> flush privileges;

4.访问

IE –> http://192.168.100.20/wwwroot/index.php

备注:配置完成删除目录下的install目录,防止下次登录清除网站界面信息

[root@localhost html]# mysql -u root -p123456

mysql> use skyuc;

mysql> show tables;

mysql> select * from skyuc_admin;

IE –> http://192.168.100.20/wwwroot/admincp/index.php

LNMP平台中部署WEB应用-2

上传论坛软件包

[root@localhost ~]# unzip ComsenzDiscuz-DiscuzX-master.zip ——下载

[root@localhost ~]# cd DiscuzX/ ——进入到解压路径下

[root@localhost DiscuzX]# ls

[root@localhost DiscuzX]# mv upload/ /usr/local/nginx/html/bbs ——名为bbs

http://192.168.42.5/bbs/install/index.php ——浏览器访问

出现安装向导

出现问题

[root@localhost DiscuzX]# cd /usr/local/nginx/html/bbs/config/——进入此路径

[root@localhost config]# cp config_global_default.php config_globa.php

[root@localhost config]# cp config_ucenter_default.php config_ucenter.php ——将两个文件复制一份

[root@localhost config]# cd ../ ——还是到bbs路径下

[root@localhost bbs]# chmod -R 777 config/ data/ uc_client/ uc_server/ ——给权限

进行下一步安装

[root@localhost bbs]# mysql -uroot -p123456 ——进入mysql数据库

mysql> create database bbs; ——创建一个数据叫bbs

Query OK, 1 row affected (0.01 sec)

mysql> grant all on bbs.* to ‘bbs’@’localhost’ identified by ‘123456’; ——授权所有权限

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges; ——刷新授权表

Query OK, 0 rows affected (0.00 sec)

开始安装

192.168.1.51/bbs/index.php

访问时后面不用加bbs:

[root@localhost bbs]# vim /usr/local/nginx/conf/nginx.conf ——进入nginx主配置文件

HTML后加上bbs

[root@localhost bbs]# nginx -s reload ——重新加载