官方源都太慢,换成163 CeontOS 源
1、备份官方源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、安装 163 CeontOS 源
cd /etc/yum.repos.d/wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
3、重新执行缓存命令
# 运行以下命令生成缓存yum clean allyum makecache
安装Mysql 5.7
yum install mysql-server -y
如果报错No package mysql-server available错误是因为我们本地yum仓库中没有可用的mysql-server rpm包,因此在yum安装之前先在本地备好rpm软件包。
rpm -ivh https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
安装好之后,重新执行 yum install mysql-server -y
Centos 7 启动Mysql 服务
systemctl start mysql #centOs6是 service mysqld startsystemctl start mysqld.service
查看Mysql5.7 的初始密码
# grep 'temporary password' /var/log/mysqld.log
输出类似如下的随机密码(红色部分)
2018-08-12T07:01:32.485728Z 1 [Note] A temporary password is generated for root: _wpt.?%t76pH
然后输入mysql -uroot -p命令登录mysql服务器,并修改mysql初始化密码。//输入初始化密码登录之后,重新设置mysql密码mysql> set password for root@localhost = password('123456');
设置Mysql 开机启动
systemctl enable mysqld
安装Nginx
yum install nginx
启动Nginx服务
systemctl start nginx
设置开机启动Nginx服务
systemctl enable nginx
yum 安装 nginx 配置文件路径 /etc/nginx/nginx.conf
自定义的配置文件放在/etc/nginx/conf.d
项目文件存放在/usr/share/nginx/html/
日志文件存放在/var/log/nginx/
还有一些其他的安装文件都在/etc/nginx
安装PHP
yum install php php-mysql php-fpm
启动php-fpm服务
systemctl start php-fpm.service
php-fpm 的配置文件 在 /etc/php-fpm.d/www.conf
配置php开机启动
systemctl enable php-fpm
配置Nginx 支持PHP
配置nginx.conf 文件 vim/etc/nginx/nginx.conf
location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
执行 nginx -t 如果出现下面代码,则证明没有出错
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
然后重启nginx 服务 systemctl restart nginx
配置 Discuz
1、配置discuz 根目录
修改nginx.conf 文件 ,把nginx 默认根目录改成你项目网站的目录 ,/var/www/html
添加 index index.html index.html index.php; 让项目文件夹默认访问index 页面
server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; index index.html index.html index.php; # 配置index 让项目根目录默认访问index # root /usr/share/nginx/html; 系统默认跟目录 root /var/www/html; #重新配置的网站跟目录 # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
在项目根目录下载 discuz x3.4
我们用git 方式下载
yum install git -y
通过git 方式安装 discuz x3.4
git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
配置Discuz x3.4 网站更目录
由于PHP默认访问 /var/www/html/
文件夹,所以我们需要把upload文件夹里的文件都复制到 /var/www/html/
文件夹
cp -r upload/* /var/www/html/
给 /var/www/html 目录及其子目录赋予权限
chmod -R 777 /var/www/html
重启 nginx
systemctl restart nginx
配置Nginx url 静态化
因为nginx.conf 文件中已包含 include /etc/nginx/default.d/*.conf;
为了方便管理 ,专门写个 xxx.conf 来控制 url 静态化规则
在/etc/nginx/default.d/ 文件夹中 创建任名称的conf 文件
我自己新建的名称为 static.conf
添加 如下规则 (我自己只做了论坛相关的Url 规则)
# nginx url 静态化rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;if (!-e $request_filename) { return 404;
重启nginx服务器,即可完成
systemctl restart nginx