LNMP四大金刚之NMP,重中之重,请务必好好学习(文末附论坛安装)
Posted 丁CCCCC
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP四大金刚之NMP,重中之重,请务必好好学习(文末附论坛安装)相关的知识,希望对你有一定的参考价值。
LNMP
一、nginx安装
1.1 安装前准备
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
安装软件包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
上传压缩包解压缩
tar zxvf nginx-1.12.0.tar.gz -C /opt/
创建用户
useradd -M -s /sbin/nologin nginx
1.2 编译安装
# 进入nginx目录中
cd nginx-1.12.0/
# 编译
./configure \\
--prefix=/usr/local/nginx \\
--user=nginx \\
--group=nginx \\
--with-http_stub_status_module
# 安装
make -j2 && make install
1.3 优化路径
# 软链接到sbin目录
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
1.4 添加系统服务
- vim /lib/systemd/system/nginx.service
- 新建服务配置文件
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 给文件权限
chmod 754 /lib/systemd/system/nginx.service
1.5 测试
systemctl start nginx.service
systemctl enable nginx.service
# 搜索服务
netstat -anpt | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11805/nginx: master
二、安装mysql
2.1 安装软件包
yum -y install ncurses ncurses-devel bison cmake
2.2 编码安装
创建用户
- useradd -M -s /sbin/nologin mysql
编码
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_EXTRA_CHARSETS=all \\
-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
安装
make -j8 &&make install
2.3 修改配置文件
编辑文件
- vim /etc/my.cnf
# 内容替换为以下
[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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
修改属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
设置路径环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
2.4 初始化数据库
- cd /usr/local/mysql/bin/
mysqld \\
--initialize-insecure \\
--user=mysql \\
--basedir=/usr/local/mysql \\
--datadir=/usr/local/mysql/data
添加服务
# 复制服务文件
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service
/usr/lib/systemd/system/
# 刷新识别
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
2.5 修改密码
- mysqladmin -u root -p password “abc123”
授权远程登录
mysql -u root -p
三、安装php
3.1 安装软件包
yum -y install gd libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
上传压缩包并解压缩
- cd /opt
- tar jxvf php-7.1.10.tar.bz2
3.2 编译安装
- cd 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
安装
- make -j2 && make install
3.3 路径优化
- ln -s /usr/local/php/bin/* /usr/local/bin/
- ln -s /usr/local/php/sbin/* /usr/local/sbin/
3.4 调整配置文件
主配置文件
- cp /opt/php-7.1.10/php.ini-development /usr/local/php/php.ini
- vim /usr/local/php/php.ini
# 修改1170行
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
# 修改939行
939 date.timezone = Asia/Shanghai
进程服务文件
- cd /usr/local/php/etc/
- cp php-fpm.conf.default php-fpm.conf
- vim php-fpm.conf
# 修改17行
pid = run/php-fpm.pid
调整扩展配置文件
- cd /usr/local/php/etc/php-fpm.d/
- cp www.conf.default www.conf
3.5 启动PHP
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
# 查看端口号
netstat -anpt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 6903/php-fpm: maste
3.6 配置nginx支持PHP解析
- vim /usr/local/nginx/conf/nginx.conf
65 location ~ \\.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
70 include fastcgi_params;
71 }
3.7 验证
- systemctl restart nginx.service
- vim /usr/local/nginx/html/index.php
- 添加测试页
<?php
phpinfo();
?>
http://192.168.253.33/index.php
3.8 验证数据库
mysql -u root -p
Enter password: # 输入密码进入mysql
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
# 进入网页配置文件
vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.253.33','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
测试
四、部署 Discuz 社区论坛
4.1 准备
cd /opt
# 解压压缩包
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/
4.2 调整论坛目录的权限
进入目录
cd /usr/local/nginx/html/bbs/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
4.3 论坛页面访问
- http://192.168.253.33/bbs/install/index.php
创建论坛信息
数据库服务器:localhost
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123
- 论坛后台管理员页面
http://192.168.253.33/bbs/admin.php
以上是关于LNMP四大金刚之NMP,重中之重,请务必好好学习(文末附论坛安装)的主要内容,如果未能解决你的问题,请参考以下文章