目录
1 LNMP 架构
2 安装依赖包
2.1创建运行用户、组
2.2 编译安装nginx
2.3 编译安装mysql
2.4 编译安装php软件
2.4.1 配置 Nginx 支持 PHP 解析
2.5 安装论坛
2.6 安装博客
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
useradd -M -s /sbin/nologin nginx
解压
make && make install
做软连接让系统识别nginx的操作命令可以自动补全 nginx $PATH
添加Nginx系统服务
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 -1 $MAINPID
ExecStop=/bin/kill -3 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
添加Nginx系统服务
安装Mysql环境依赖包
yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
解压
安装
make && make install
修改mysql 配置文件
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
更改mysql安装目录和配置文件的属主属组
设置路径环境变量
初始化数据库
添加mysqld系统服务
修改mysql 的登录密码
授权远程登录
安装环境依赖包
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
编译安装
tar jxvf php-7.1.10.tar.bz2
[root@localhost opt]#cd 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
make && make install
路径优化
建立软件链接
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
调整PHP配置文件
php有三个配置文件:
调整主配置文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai
调整进程服务配置文件
root@localhost ~]#cd /usr/local/php/etc/
[root@localhost etc]#cp php-fpm.conf.default php-fpm.conf
调整扩展配置文件
[root@localhost ~]#cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]#cp www.conf.default www.conf
启动php-fpm
--65行--取消注释,修改
location ~ \.php$ {
root html; $document_root
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #$document_root 代表当前请求在root指令中指定的值
include fastcgi_params;
}
systemctl restart nginx.service
验证PHP 测试页
vim /usr/local/nginx/html/index.php
192.168.30.104/index.php
验证lnmp的是否搭建成功
数据库的用户名
用户名@主机名
[email protected]
验证数据库工作是否正常
替换原来的测试页内容
部署 Discuz!社区论坛 Web 应用
解压论坛软件
调整论坛目录的权限
[root@localhost dir_SC_UTF8]#cd /usr/local/nginx/html/bbs/
[root@localhost bbs]#chown -R nginx ./config/
[root@localhost bbs]#chown -R nginx ./data/
[root@localhost bbs]#chown -R nginx ./uc_client/
[root@localhost bbs]#chown -R 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/
建立数据库
图形化安装
http://192.168.30.104/bbs/install/index.php
安装完后访问论坛页面:
http://192.168.30.104/bbs/index.php
http://192.168.30.104/bbs/admin.php
http://192.168.30.104/bbs/admin.php
解压博客软件
调整博客目录的权限
建立数据库
图形化安装
http://192.168.30.104/wordpress/wp-admin/install.php