【LNMP平台架构】之Discuz站点搭建
一、依赖评估
1、查询系统适配的PHP版本
[root@localhost ~]# yum list | grep php
flamegraph-stackcollapse-php.noarch 1.0-1.oe2403sp1 everything
php.src 8.3.24-1.oe2403sp1 update-source
php.x86_64 8.3.24-1.oe2403sp1 update
2、下载Discuz软件包
3、安装php、php插件、nginx和mysql
[root@localhost ~]# yum install -y php php-mysqlnd nginx mysql-server
Nginx 服务器中用于配置 PHP 脚本处理规则的配置文件
[root@localhost nginx]# cd default.d/
[root@localhost default.d]# ls
php.conf
[root@localhost default.d]# cat php.conf
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm;location ~ \.(php|phar)(/.*)?$ {fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;fastcgi_intercept_errors on;fastcgi_index index.php;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_pass php-fpm;
}
Nginx 中用于定义 PHP-FPM 后端服务地址的配置文件
[root@localhost nginx]# cd conf.d/
[root@localhost conf.d]# ls
php-fpm.conf
[root@localhost conf.d]# cat php-fpm.conf
# PHP-FPM FastCGI server
# network or unix domain socket configurationupstream php-fpm {server unix:/run/php-fpm/www.sock;
}
4、启动php、mysql和nginx
root@localhost ~]# systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# ps aux |grep php-fpm
root 26488 0.3 1.9 195748 27952 ? Ss 19:27 0:00 php-fpm: master process (/etc/php-fpm.conf)
apache 26489 0.0 0.8 196300 12820 ? S 19:27 0:00 php-fpm: pool www
apache 26490 0.0 0.8 196300 12820 ? S 19:27 0:00 php-fpm: pool www
apache 26491 0.0 0.8 196300 12820 ? S 19:27 0:00 php-fpm: pool www
apache 26492 0.0 0.8 196300 12820 ? S 19:27 0:00 php-fpm: pool www
apache 26493 0.0 0.8 196300 12824 ? S 19:27 0:00 php-fpm: pool www
root 26657 0.0 0.5 21988 8004 pts/0 S+ 19:27 0:00 grep --color=auto php-fpm[root@localhost ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
5、创建php解析文件、mysql连接解析文件
[root@localhost ~]# cd /usr/share/nginx
[root@localhost nginx]# ls
html modules
[root@localhost nginx]# cd html/
[root@localhost html]# ls
404.html 50x.html index.html nginx-logo.png
[root@localhost html]# vim test.php<?phpphpinfo();
?>
[root@localhost html]# vim mysql_conn.php
<?php#连接数据库$link = mysqli_connect('localhost','root','');#检查连接if ($link) {echo "OK!";} else {echo "NO!";}mysqli_close($link);
?>
6、测试
7、解压Discuz软件包并拷贝upload
[root@localhost ~]# cd DiscuzX-MitFrame/
[root@localhost DiscuzX-MitFrame]# ls
developer README.md upload
[root@localhost DiscuzX-MitFrame]# cp -r upload/ /usr/share/nginx/html
[root@localhost DiscuzX-MitFrame]# cd /usr/share/nginx/html
[root@localhost html]# ls
404.html 50x.html index.html mysql_conn.php nginx-logo.png test.php upload
测试
8、创建数据库用户并赋权
mysql> create user discuz@'localhost' identified by '123.com';
Query OK, 0 rows affected (0.05 sec)mysql> grant all on discuzdb.* to discuz@'localhost';
Query OK, 0 rows affected (0.00 sec)
9、更改upload目录权限
[root@localhost html]# chown -R apache upload/
[root@localhost html]# ls -l
总计 28
-rw-r--r--. 1 root root 3454 9月 4日 18:27 404.html
-rw-r--r--. 1 root root 3497 9月 4日 18:27 50x.html
-rw-r--r--. 1 root root 3510 9月 4日 18:27 index.html
-rw-r--r--. 1 root root 175 10月21日 20:11 mysql_conn.php
-rw-r--r--. 1 root root 368 9月 4日 18:27 nginx-logo.png
-rw-r--r--. 1 root root 21 10月21日 19:43 test.php
drwxr-xr-x. 12 apache root 4096 10月21日 20:15 upload
10、完成Discuz搭建