LNMP架构是指Linux+Nginx+Mysql+PHP(Perl、Python)
首先准备Linux主机,关闭防火墙和selinux
需要获取相关的源码包
配置字段含义可参考 LAMP架构搭建实操_Evens7xxX的博客-CSDN博客
LNMP架构中,nginx处理静态页面请求,fastCGI会将动态页面请求转发给php-fpm模块中,再经过wrapper筛选,最后给php解析,涉及到数据库的数据,会打开数据库连接接口获取数据。
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
#解压源码包
cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/
#自定义安装
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
#编译安装
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#自定义service文件
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
systemctl start nginx.service
systemctl enable nginx.service
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
useradd -M -s /sbin/nologin mysql
#解压源码包
cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
#自定义安装
cd /opt/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_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 && make install
vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysql]
port = 3306
socket = /usr/local/mysql/mysql.sock
auto-rehash
[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
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
mysqladmin -u root -p password "abc123"
mysql -u root -p
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
#自定义安装
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 && make install
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
#复制模板并修改
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#939行,取消注释,修改
date.timezone = Asia/Shanghai
#1170行,修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
#验证安装的模块
php -m
#复制模板文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
#修改进程服务配置文件
vim php-fpm.conf
#17行,去掉";"注释
pid = run/php-fpm.pid
最后一行代表加载/usr/local/php/etc/php-fpm.d/下所有conf文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
vim www.conf
修改监听地址(默认指定ip为本机,如果提供nginx服务与提供php服务的主机不是一台,需要修改为提供nginx服务器的ip地址)
#进入软件包目录,复制并启用service文件
cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
#重载并开启服务
systemctl daemon-reload
systemctl restart php-fpm.service
vim /usr/local/nginx/conf/nginx.conf
#65行,取消注释,修改
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#重启服务使配置生效
systemctl restart nginx.service
将 /scripts 改为 $document_root 代表当前请求在root指令中指定的值(网页根目录)
首先需要在 /usr/local/nginx/conf/nginx.conf 中添加指定首页文件index.php
重载服务使配置生效
systemctl reload nginx.service
添加index.php文件用于访问测试
#在root指定的根目录下创建index.php文件,并添加内容
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
解压论坛压缩包
【部署 Discuz!社区论坛 Web 应用】
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/
调整论坛目录的权限:
cd /usr/local/nginx/html/bbs/
chown -R nginx ./config/
chown -R nginx ./data/
chown -R nginx ./uc_client/
chown -R nginx ./uc_server/
或
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
论坛页面访问
http://192.168.17.51/bbs/install/index.php
----------------------------------------------------------------------------------------------------------
数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123
----------------------------------------------------------------------------------------------------------
访问论坛页面:
http://192.168.17.51/bbs/index.php
http://192.168.17.51/bbs/admin.php
进入论坛文件中,将页面拷贝到bbs网页根目录下
数据库授权
访问页面
修正报错部分,更改属主和权限
刷新网页后继续下一步
设置刚刚的数据库和密码,再设置一个管理员和密码