源码编译安装 LNMP及论坛
阅读原文时间:2023年07月10日阅读:3

一.安装Nginx服务

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

1、安装依赖包  

yum -y install pcre-devel zlib-devel gcc gcc-c++ make

2、创建运行用户

useradd -M -s /sbin/nologin nginx

3、编译安装

1 cd /opt
2 tar zxvf nginx-1.12.0.tar.gz -C /opt/
3
4 cd nginx-1.12.0/
5 ./configure \
6 --prefix=/usr/local/nginx \
7 --user=nginx \
8 --group=nginx \
9 --with-http_stub_status_module
10
11 make && make install

4、优化路径

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

5、添加 Nginx 系统服务

1 vim /lib/systemd/system/nginx.service
2 [Unit]
3 Description=nginx
4 After=network.target
5 [Service]
6 Type=forking
7 PIDFile=/usr/local/nginx/logs/nginx.pid
8 ExecStart=/usr/local/nginx/sbin/nginx
9 ExecReload=/bin/kill -s HUP $MAINPID
10 ExecStop=/bin/kill -s QUIT $MAINPID
11 PrivateTmp=true
12 [Install]
13 WantedBy=multi-user.target
14
15 chmod 754 /lib/systemd/system/nginx.service
16 systemctl start nginx.service
17 systemctl enable nginx.service

二、安装 MySQL 服务
1、安装Mysql环境依赖包

1 yum -y install \
2 ncurses \
3 ncurses-devel \
4 bison \
5 cmake

2、创建运行用户

useradd -M -s /sbin/nologin mysql

3、编译安装

1 cd /opt
2 tar zxvf mysql-boost-5.7.20.tar.gz
3
4 cd /opt/mysql-5.7.20/
5 cmake \
6 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
7 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
8 -DSYSCONFDIR=/etc \
9 -DSYSTEMD_PID_DIR=/usr/local/mysql \
10 -DDEFAULT_CHARSET=utf8 \
11 -DDEFAULT_COLLATION=utf8_general_ci \
12 -DWITH_EXTRA_CHARSETS=all \
13 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
14 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
15 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
16 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
17 -DMYSQL_DATADIR=/usr/local/mysql/data \
18 -DWITH_BOOST=boost \
19 -DWITH_SYSTEMD=1
20
21 make && make install

4、修改mysql 配置文件

1 vim /etc/my.cnf
2 [client]
3 port = 3306
4 socket=/usr/local/mysql/mysql.sock
5
6 [mysqld]
7 user = mysql
8 basedir=/usr/local/mysql
9 datadir=/usr/local/mysql/data
10 port = 3306
11 character-set-server=utf8
12 pid-file = /usr/local/mysql/mysqld.pid
13 socket=/usr/local/mysql/mysql.sock
14 bind-address = 0.0.0.0
15 skip-name-resolve
16 max_connections=2048
17 default-storage-engine=INNODB
18 max_allowed_packet=16M
19 server-id = 1
20
21 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

5、更改mysql安装目录和配置文件的属主属组

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

6、设置路径环境变量

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile

7、初始化数据库

1 cd /usr/local/mysql/bin/
2 ./mysqld \
3 --initialize-insecure \
4 --user=mysql \
5 --basedir=/usr/local/mysql \
6 --datadir=/usr/local/mysql/data

8、添加mysqld系统服务

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld

9、修改mysql 的登录密码  

mysqladmin -u root -p password "abc123"

10、授权远程登录

mysql -u root -p

三、安装配置 PHP 解析环境
1、安装环境依赖包

1 yum -y install gd \
2 libjpeg libjpeg-devel \
3 libpng libpng-devel \
4 freetype freetype-devel \
5 libxml2 libxml2-devel \
6 zlib zlib-devel \
7 curl curl-devel \
8 openssl openssl-devel

2、编译安装

1 cd /opt
2 tar jxvf php-7.1.10.tar.bz2
3
4 cd php-7.1.10
5 ./configure \
6 --prefix=/usr/local/php \
7 --with-mysql-sock=/usr/local/mysql/mysql.sock \
8 --with-mysqli \
9 --with-zlib \
10 --with-curl \
11 --with-gd \
12 --with-jpeg-dir \
13 --with-png-dir \
14 --with-freetype-dir \
15 --with-openssl \
16 --enable-fpm \
17 --enable-mbstring \
18 --enable-xml \
19 --enable-session \
20 --enable-ftp \
21 --enable-pdo \
22 --enable-tokenizer \
23 --enable-zip
24
25 make && make install

3、路径优化

ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/

4、调整PHP配置文件

php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件

1 #调整主配置文件:
2 cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
3 vim /usr/local/php/lib/php.ini
4 --1170行--修改
5 mysqli.default_socket = /usr/local/mysql/mysql.sock
6 --939行--取消注释,修改
7 date.timezone = Asia/Shanghai
8
9 php -m #验证安装的模块
10
11 #调整进程服务配置文件:
12 cd /usr/local/php/etc/
13 cp php-fpm.conf.default php-fpm.conf
14 vim php-fpm.conf
15 --17行--去掉";"注释
16 pid = run/php-fpm.pid
17
18 #调整扩展配置文件:
19 cd /usr/local/php/etc/php-fpm.d/
20 cp www.conf.default www.conf

5、启动php-fpm

1 /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
2 netstat -anpt | grep 9000
3
4 #PHP-FPM(FastCGI Process Manager:FastCGI 进程管理器)是一个 PHPFastCGI 管理器, 由于Nginx服务器不能处理动态页面,需要由 Nginx 把动态请求交给 php-fpm 进程进行解析。
5
6 cd /opt/php-7.1.10/sapi/fpm
7 cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
8 systemctl restart php-fpm.service

6、配置 Nginx 支持 PHP 解析

1 vim /usr/local/nginx/conf/nginx.conf
2 --65行--取消注释,修改
3 location ~ \.php$ {
4 root html;
5 fastcgi_pass 127.0.0.1:9000;
6 fastcgi_index index.php;
7 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录
8 include fastcgi_params;
9 }
10
11 systemctl restart nginx.service

7、验证PHP 测试页

1 vim /usr/local/nginx/html/index.php
2
5
6 浏览器访问
7 http://192.168.80.10/index.php

8、验证数据库工作是否正常

1 mysql -u root -p
2 CREATE DATABASE bbs;
3 GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
4 GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
5 flush privileges;
6
7 vim /usr/local/nginx/html/index.php #替换原来的测试页内容
8 Success!!"; 11 else echo "Fail!!"; 12 ?>
13
14 浏览器访问
15 http://192.168.91.5/index.php

四、部署 Discuz!社区论坛 Web 应用

1 cd /opt
2 unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
3 cd /opt/dis/dir_SC_UTF8/
4 cp -r upload/ /usr/local/nginx/html/bbs/

调整论坛目录的权限:

1 cd /usr/local/nginx/html/bbs/
2 chown -R nginx ./config/
3 chown -R nginx ./data/
4 chown -R nginx ./uc_client/
5 chown -R nginx ./uc_server/
6 或
7 chmod -R 777 ./config/
8 chmod -R 777 ./data/
9 chmod -R 777 ./uc_client/
10 chmod -R 777 ./uc_server/

论坛页面访问

http://192.168.80.10/bbs/install/index.php