操作系统 | Nginx版本 | 数据库版本 | PHP版本 |
---|---|---|---|
centos-8 | nginx-1.22.1 | mariadb-10.3 | php-8.2.10 |
//配置yum源(推荐使用阿里云源)和epel源
[root@wanf ~]# rm -rf /etc/yum.repos.d/*
[root@wanf ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@wanf ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@wanf ~]# yum clean all
[root@wanf ~]# yum makecache
[root@wanf ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@wanf ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@wanf ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@wanf ~]# yum makecache
//永久关闭防火墙和selinux
[root@wanf ~]# systemctl disable --now firewalld.service
[root@wanf ~]# setenforce 0
[root@wanf ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@wanf ~]# reboot
//安装相关依赖
[root@wanf ~]# yum -y install libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd sqlite-devel libzip libzip-devel gd-devel oniguruma make wget vim --nobest
[root@wanf ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@wanf ~]# yum -y install gcc gcc-c++ --allowerasing
[root@wanf ~]# yum -y groups mark install 'Development Tools'
//创建nginx系统用户
[root@wanf ~]# useradd -r -M -s /sbin/nologin nginx
[root@wanf ~]# id nginx
uid=995(nginx) gid=992(nginx) groups=992(nginx)
//创建日志存放目录
[root@wanf ~]# mkdir -p /var/log/nginx
[root@wanf ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx软件包,并安装
[root@wanf ~]# wget http://nginx.org/download/nginx-1.22.1.tar.gz -P /usr/src/
//编译安装
[root@wanf ~]# cd /usr/src/
[root@wanf src]# ls
debug kernels nginx-1.22.1.tar.gz
[root@wanf src]# tar -xf nginx-1.22.1.tar.gz
[root@wanf src]# cd nginx-1.22.1/
[root@wanf nginx-1.22.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
(配置过程省略)
[root@wanf nginx-1.22.1]# make -j4 && make install
(编译安装过程省略)
//nginx安装后配置
//配置环境变量
[root@wanf ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@wanf ~]# source /etc/profile.d/nginx.sh
//加入systemctl管理
[root@wanf ~]# vim /usr/lib/systemd/system/nginx.service
[root@wanf ~]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
[Install]
WantedBy=multi-user.target
[root@wanf ~]# systemctl daemon-reload
//启动并设置开机自启
[root@wanf ~]# systemctl enable --now nginx.service
[root@wanf ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@wanf ~]#
成功访问nginx主页
//安装mariadb
[root@wanf ~]# yum -y install mariadb mariadb-server
//启动mariadb并设置开机自启
[root@wanf ~]# systemctl enable --now mariadb.service
//设置密码
[root@wanf ~]# mysql
MariaDB [(none)]> set password = password('12345678'); //根据需求设置密码
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit
Bye
[root@wanf ~]#
//下载php软件包
[root@wanf ~]# wget https://www.php.net/distributions/php-8.2.10.tar.gz -P /usr/src/
//编译安装
[root@wanf ~]# cd /usr/src/
[root@wanf src]# tar -xf php-8.2.10.tar.gz
[root@wanf src]# cd php-8.2.10/
[root@wanf php-8.2.10]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
(配置过程省略)
[root@wanf php-8.2.10]# make -j4 && make install
(编译安装过程省略)
//安装后配置
[root@wanf php-8.2.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@wanf php-8.2.10]# source /etc/profile.d/php8.sh
[root@wanf php-8.2.10]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@wanf php-8.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@wanf php-8.2.10]# chmod +x /etc/rc.d/init.d/php-fpm
[root@wanf php-8.2.10]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@wanf php-8.2.10]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
[root@wanf php-8.2.10]# vim /usr/local/php8/etc/php-fpm.conf
[root@wanf php-8.2.10]# tail -4 /usr/local/php8/etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@wanf php-8.2.10]#
//加入systemctl管理
[root@wanf ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@wanf ~]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.targe
[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/php-fpm start
ExecStop=/etc/rc.d/init.d/php-fpm stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
[root@wanf ~]# systemctl daemon-reload
//启动并设置开机自启
[root@wanf ~]# systemctl enable --now php-fpm.service
//创建php测试页面
[root@wanf ~]# cd /usr/local/nginx/html/
[root@wanf html]# vim index.php
[root@wanf html]# cat index.php
<?php
phpinfo();
?>
[root@wanf html]#
//修改nginx主配置文件
[root@wanf html]# vim /usr/local/nginx/conf/nginx.conf
......
server {
listen 80;
server_name www.wanf.com; //自己的域名
......
location / {
root html;
index index.php index.html index.htm; //加一个index.php
}
......
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf; //改为fastcgi.conf;
}
......
//重启服务
[root@wanf html]# systemctl restart nginx.service
通过IP地址访问测试页面
部署完成
Discuz论坛系统下载地址Discuz官网
//我提前下好了,然后传进主机中
[root@wanf ~]# ls
Discuz_X3.5_SC_UTF8_20231001.zip
//创建一个目录存放网站文件
[root@wanf ~]# mkdir /usr/local/nginx/html/Discuz
//解压到刚刚创建的目录
[root@wanf ~]# yum -y install unzip
[root@wanf ~]# unzip Discuz_X3.5_SC_UTF8_20231001.zip -d /usr/local/nginx/html/Discuz/
[root@wanf ~]# cd /usr/local/nginx/html/
[root@wanf html]# ls
50x.html Discuz index.html index.php
[root@wanf html]# cd Discuz/
[root@wanf Discuz]# ls
LICENSE qqqun.png readme readme.html upload utility.html
[root@wanf Discuz]# cd upload/
[root@wanf upload]# ls
admin.php connect.php group.php misc.php source
api crossdomain.xml home.php plugin.php static
api.php data index.php portal.php template
archiver favicon.ico install robots.txt uc_client
config forum.php member.php search.php uc_server
[root@wanf upload]#
//修改权限
[root@wanf ~]# cd /usr/local/nginx/html/Discuz/upload/
[root@wanf upload]# chown -R nginx config/
[root@wanf upload]# chown -R nginx data/
[root@wanf upload]# chown -R nginx uc_client/
[root@wanf upload]# chown -R nginx uc_server/
[root@wanf upload]# chmod -R 777 config/
[root@wanf upload]# chmod -R 777 data/
[root@wanf upload]# chmod -R 777 uc_client/
[root@wanf upload]# chmod -R 777 uc_server/
//创建数据库
[root@wanf ~]# mysql -uroot -p12345678 -e "create database Discuz;"
//编辑nginx配置文件,创建一个虚拟主机,可以用域名访问
[root@wanf ~]# vim /usr/local/nginx/conf/nginx.conf
.......
server {
listen 80;
server_name www.wanf1.com; //自己的域名
location / {
root html/Discuz/upload; //改为网站目录
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html/Discuz/upload; //改为网站目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
......
//重启nginx服务和php-fpm
[root@wanf ~]# systemctl restart nginx.service
[root@wanf ~]# systemctl restart php-fpm.service
第一次安装需要在域名后面接/install才可以到安装界面
安装完毕