文章目录
一、搭建LNMP
环境准备:
1.关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
vim /etc/selinux/config
SELINUX=disabled
setenforce 0
2.安装nginx/mariadb-server/php/php-mysql/php-fpm/php-gd
yum install nginx mariadb-server php php-mysql php-gd php-fpm -y
3.配置LNMP环境
1)数据库:
1、支持中文
vim /etc/my.cnf
[mysqld]
character-set-server=utf8
2、初始安全设置
mysql_secure_installation
Enter current password for root (enter for none): 回车键
Set root password? [Y/n] y
设置密码(123456)
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
2)nginx支持php:
[root@manager ~]# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
[root@manager html]# cat /etc/nginx/nginx.conf #或者虚拟主机文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm index.php;
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include /etc/nginx/conf.d/*.conf;
}
3)php:
[root@manager ~]# vim /etc/php.ini #增加以下两行:
cgi.fix_pathinfo=0
date.timezone ="Asia/shanghai"
3.启动服务
[root@manager ~]# systemctl restart nginx mariadb php-fpm
4.测试协同
测试nginx和php协同:
[root@manager ~]# vim /usr/share/nginx/html/phpinfo.php
<?php
phpinfo();
?>
测试 mysql和php协同:
[root@manager ~]# vim /usr/share/nginx/html/mysql.php
<?php
$con=mysql_connect("localhost","root","123456");
if(!$con){
die("could not connect to the db:\n".mysql_error());
}
else{
echo "success";
}
mysql_close($con);
?>
二、部署Discuz论坛
[root@manager ~]# cd /usr/share/nginx/html
[root@manager html]# unzip Discuz_X3.2_SC_UTF8.zip
[root@manager html]# ls
50x.html upload index.html.bak phpinfo.php
bbs Discuz_X3.2_SC_UTF8.zip mysql.php readme
blog index.html news utility
在浏览器进行访问服务器地址192.168.131.107/discuz:
点击我同意:
config/ data/ uc_server/ uc_client/ 这些目录里没有写权限:
[root@manager html]# cd discuz/
[root@manager discuz]# chmod -R a+w config/ data/ uc_server/ uc_client/
点击下一步:
点击下一步:创建数据库,数据库用户名以及设置密码
[root@manager discuz]# mysql -uroot -p123456 -e "create database discuz;"
[root@manager discuz]# mysql -uroot -p123456 -e "grant all on discuz.* to discuz@localhost identified by '123456';"
点击下一步:
出现这个问题:
原因是Discuz通过后台备份数据后,搬家过程中没全新安装程序,而直接进restore.php页面导入数据,就会出现各种table缺失的情况。
解决办法1:将install.sql导入数据库中。
[root@manager discuz]# mysql -uroot -p123456 discuz < install/data/install.sql
这样的话需要修改表中有些内容。
解决办法2:进数据库后台重建一下数据表就行。
解决如下:
1.先找到官方的安装文件,找到相关表的创建语句:
具体文件位置(discuz/install/data/install.sql),找到创建此表的语句。
2. 进入数据库执行该语句:
得到错误提示码:
ERROR 1064 (42000) at line 8: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘TYPE=MyISAMB’ at line 7
竟然说是语法错误,再次查找相关资料,得到的结论是:
这个错误出现是由于MySQL创建表的写法 TYPE=MyISAM 太古老了,在MySQL 5.6.20上已经不支持了,这个应该在MySQL 5.1后的相关版本已经取消了支持,具体参考链接http://bugs.mysql.com/bug.php?id=17501,只能将mysqldump导出的脚本文件里面的TYPE=MyISAM 全部替换成ENGINE=InnoDB后,才会导入成功。
3.都修复好后,登录后台,检验一下:
发现不少错误:有表缺失,有些刚才建的表字符集不正确。
成功登录,访问也正常,至此问题一一解决,后面的修复都是重复上面的过程,不再累述。
注:要是想进行后台管理,需要现在install/index.php删除(也可以对install目录进行重命名)