在搭建了LAMP环境的基础上安装Dscuz
一、下载并解压Discuz_X3.2
[root@www ~]#mkdir /data/www -p
[root@www ~]#cd /data/www/
[root@www www]# mv /usr/local/src/Discuz_X3.2_SC_GBK.zip .
[root@www www]# unzip Discuz_X3.2_SC_GBK.zip
[root@www www]# ls
Discuz_X3.2_SC_GBK.zip readme upload utility
[root@www www]# mv upload/* ./
[root@www www]# rm -rf readme/ utility/ upload/ Discuz_X3.2_SC_GBK.zip
二、修改http配置文件,打开虚拟主机配置
[root@www www]# vim /etc/httpd/httpd.conf
400 # Virtual hosts
401 Include /etc/httpd/extra/httpd-vhosts.conf
三、配置虚拟主机文件,修改配置
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
#ServerAdmin [email protected]
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com
#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common
[root@www www]# /usr/local/apache2/bin/apachectl -t
Syntax OK
四、在windows主机下的hosts文件添加两个测试域名解析
192.168.1.21 www.test.com www.aaa.com
五、出现403访问错误,修改配置文件
[root@www www]# vim /etc/httpd/httpd.conf
116 # First, we configure the "default" to be a very restrictive set of
117 # features.
118 #
119
120 Options FollowSymLinks
121 AllowOverride None
122 Order deny,allow
123 allow from all
124
[root@www www]# /usr/local/apache2/bin/apachectl graceful
六、PHP和Discuz字符集不一致出现乱码
修改PHP配置文件,将字符集改为GBK
[root@www www]# vim /usr/local/php/etc/php.ini
678 ; PHP's default character set is set to UTF-8.
679 ; http://php.net/default-charset
680 #default_charset = "UTF-8"
681 default_charset = "GBK"
重新加载配置,刷新网页
[root@www www]# /usr/local/apache2/bin/apachectl graceful
七、安装Discuz
[root@www www]# chown -R daemon config/ data/ uc_client/ uc_server/
八、配置MySQL相关
1、创建discuz数据库
mysql> create database discuz;
Query OK, 1 row affected (0.07 sec)
2、创建mysql用户
mysql> grant all on discuz.* to 'ming'@'localhost' identified by 'ming123';
Query OK, 0 rows affected (0.28 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
3、继续安装discuz
安装完成
九、Apache相关配置
1、Apache用户认证
(1)创建目录
[root@www ~]# cd /data/www/
[root@www www]# mkdir abc
[root@www www]# cp /etc/passwd abc/1.txt
(2)修改虚拟主机配置文件
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
#ServerAdmin [email protected]
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com
#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common
AllowOverride AuthConfig
AuthName "自定义的"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
[root@www www]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@www www]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
[root@www www]# source /etc/profile.d/path.sh
(3)创建认证用户和密码
[root@www www]# htpasswd -c /data/.htpasswd user1 //创建第一个用户加-c选项
New password: //密码123456
Re-type new password:
Adding password for user user1
[root@www www]# cat /data/.htpasswd //cat查看密码文件
user1:$apr1$yVj/LOxx$DikS0h570cv8UF4QLZAyN/
[root@www www]# htpasswd /data/.htpasswd user2 //创建第二个用户不用加-c选项
New password: //密码123456
Re-type new password:
Adding password for user user2
[root@www www]# !cat
cat /data/.htpasswd
user1:$apr1$yVj/LOxx$DikS0h570cv8UF4QLZAyN/
user2:$apr1$sXRy3Ga1$wYMyiI9DyFaMcSH1dFRnw1
重新加载apache
[root@www www]# apachectl graceful
2、默认虚拟主机
[root@www www]# mkdir /tmp/123
[root@www www]# chmod 600 /tmp/123
增加以下虚拟目录,用于拒绝访问
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
DocumentRoot "/tmp/123"
ServerName 11111.com
#ServerAdmin [email protected]
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.aaa.com
#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common
AllowOverride AuthConfig
AuthName "users"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
[root@www www]# apachectl graceful
访问测试:www.222.com或直接访问IP,只有test和aaa可以访问
3、域名301跳转
修改虚拟主机配置文件,增加域名跳转模块
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.aaa.com$
RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]
[root@www www]# apachectl -t
Syntax OK
[root@www www]# apachectl graceful
在浏览器访问www.aaa.com会自动跳转成www.test.com
[root@www www]# curl -x192.168.1.21:80 www.aaa.com -I
HTTP/1.1 301 Moved Permanently
Date: Mon, 14 Dec 2015 09:11:28 GMT
Server: Apache/2.2.31 (Unix) PHP/5.6.14
Location: http://www.test.com/
Content-Type: text/html; charset=iso-8859-1
增加多个域名跳转,使别名为www.bbb.com跳转到www.test.com
[root@www www]# apachectl graceful
[root@www www]# curl -x192.168.1.21:80 www.bbb.com -I
HTTP/1.1 301 Moved Permanently
Date: Mon, 14 Dec 2015 09:15:05 GMT
Server: Apache/2.2.31 (Unix) PHP/5.6.14
Location: http://www.test.com/
Content-Type: text/html; charset=iso-8859-1
4、Apache日志切割
[root@www ~]# ls /usr/local/apache2/logs/
access_log error_log httpd.pid
[root@www www]# vim /etc/httpd/httpd.conf //查看combined格式
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
修改配置
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
ErrorLog "logs/test.com-error_log"
CustomLog "logs/test.com-access_log" combined
[root@www ~]# cd /usr/local/apache2/logs/
[root@www logs]# ls
access_log error_log httpd.pid test.com-access_log test.com-error_log
[root@www logs]# wc -l test.com-access_log
124 test.com-access_log
日志切割:
[root@www ~]# ls /usr/local/apache2/bin/rotatelogs
/usr/local/apache2/bin/rotatelogs
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
日志文件增加时间戳,是日志按天切割
ErrorLog "logs/test.com-error_log"
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined
重新加载配置,访问测试
[root@www www]# apachectl graceful
[root@www ~]# ls /usr/local/apache2/logs/
access_log error_log httpd.pid test.com-access_20151214_log test.com-access_log test.com-error_log
[root@www www]# date -s "2015-12-15 01:01:01"
Tue Dec 15 01:01:01 CST 2015
[root@www ~]# ls /usr/local/apache2/logs/
access_log httpd.pid test.com-access_20151215_log test.com-error_log
error_log test.com-access_20151214_log test.com-access_log
5、Apache不记录指定文件类型日志
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
ErrorLog "logs/test.com-error_log"
SetEnvIf Request_URI ".*\.gif$" p_w_picpath-request
SetEnvIf Request_URI ".*\.jpg$" p_w_picpath-request
SetEnvIf Request_URI ".*\.png$" p_w_picpath-request
SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request
SetEnvIf Request_URI ".*\.css$" p_w_picpath-request
SetEnvIf Request_URI ".*\.js$" p_w_picpath-request
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined env=!p_w_picpath-request
[root@www www]# apachectl graceful