文章目录
LNMP平台搭建
- nginx
- MySQL
- PHP
- php-fpm
- 论坛
防火墙设置
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
nginx
安装环境依赖
[root@localhost ~]yum -y install gcc gcc-c++ make zlib-devel pcre pcre-devel elinks lynx
创建nginx程序用户,运来维护程序
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
编译安装
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.12.2]#make &&make install
测试优化
命令管理
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
自测
[root@localhost ~]# nginx
[root@localhost ~]# lynx 127.0.0.1
启动管理
[root@localhost ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forcking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service
[root@localhost ~]# systemctl enable nginx.service
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# cp -p nginx.conf nginx.conf.bak
配置文件管理
[root@localhost ~]# ln -s /usr/local/nginx/conf/nginx.conf /etc/
[root@localhost ~]# ls -l /etc/nginx.conf
lrwxrwxrwx. 1 root root 32 8月 8 15:23 /etc/nginx.conf -> /usr/local/nginx/conf/nginx.conf
mysql
安装MySQL环境依赖包
[root@localhost ~]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \ ##语法分析
> cmake
创建运行用户,用于管理维护进程
[root@localhost ~]# useradd -s /sbin/nologin mysql
编译安装
[root@localhost ~]# cd /mnt/LNMP/
[root@localhost LNMP]# ls
mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2
[root@localhost LNMP]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt
[root@localhost ~]# cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-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
[root@localhost mysql-5.7.20]# make &&make install
数据库目录进行权限调整
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/
调整配置文件
vi /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
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.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 LNMP]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost LNMP]# echo 'export PATH' >> /etc/profile
[root@localhost LNMP]# source /etc/profile
初始化数据库
[root@localhost mysql]# cd /usr/local/mysql/bin/
[root@localhost bin]# mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql/ \
> --datadir=/usr/local/mysql/data
启动
[root@localhost bin]# cd ..
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/mysqld.service
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# netstat -antp |grep mysql
tcp6 0 0 :::3306 :::* LISTEN 36069/mysqld
设置MySQL密码
[root@localhost mysql]# mysqladmin -u root -p password
登录数据库
[root@localhost mysql]# mysql -uroot -p
PHP
安装环境依赖包
[root@localhost LNMP]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
编译安装
[root@localhost LNMP]# cd /mnt/LNMP/
[root@localhost LNMP]# tar jxvf php-7.1.10.tar.bz2 -C /opt
[root@localhost opt]# cd /opt/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 \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]#make && make install
三个配置文件
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
mysqli.default_sock = /usr/local/mysql/mysql.sock
date.timezone= Asia/Shanghai
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m ##验证安装的模块
[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]# vim php-fpm.conf
pid = run/php-fpm.pid
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
启动PHP
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost php-fpm.d]# netstat -antp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 44041/php-fpm: mast
[root@localhost php-fpm.d]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost php-fpm.d]# cd /usr/local/nginx/conf
修改nginx配置文件,支持PHP
[root@localhost conf]# vim nginx.conf
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;
}
重载nginx配置文件
[root@localhost logs]# systemctl stop nginx
[root@localhost logs]# netstat -antp |grep nginx
[root@localhost logs]# systemctl start nginx
[root@localhost logs]# netstat -antp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 45217/nginx: master
论坛
创建数据库,登录用户
[root@localhost ~]# mysql -uroot -p
Enter password:
mysql> CREATE DATABASE bbs;
Query OK, 1 row affected (0.01 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '123456' ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY '123456' ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
mysql>quit
搭论坛
安装包解压
[root@localhost bbs]# cd /mnt/LNMP/
[root@localhost LNMP]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt
使用upload加载首页安装
[root@localhost dir_SC_UTF8]# cd /opt/dir_SC_UTF8/
[root@localhost dir_SC_UTF8]#cp -r upload/ /usr/local/nginx/html/bbs
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[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/