在搭建了LAMP環境的基礎上安裝Dscuz
php
1、下載並解壓Discuz_X3.2css
[root@www ~]#mkdir /data/www -p
[root@www ~]#cd /data/www/html
[root@www www]# mv /usr/local/src/Discuz_X3.2_SC_GBK.zip .
mysql
[root@www www]# unzip Discuz_X3.2_SC_GBK.zipweb
[root@www www]# ls
Discuz_X3.2_SC_GBK.zip readme upload utilitysql
[root@www www]# mv upload/* ./
[root@www www]# rm -rf readme/ utility/ upload/ Discuz_X3.2_SC_GBK.zip
數據庫
2、修改http配置文件,打開虛擬主機配置
apache
[root@www www]# vim /etc/httpd/httpd.conf
vim
400 # Virtual hosts
401 Include /etc/httpd/extra/httpd-vhosts.confwindows
3、配置虛擬主機文件,修改配置
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
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
</VirtualHost>
[root@www www]# /usr/local/apache2/bin/apachectl -t
Syntax OK
4、在windows主機下的hosts文件添加兩個測試域名解析
192.168.1.21 www.test.com www.aaa.com
5、出現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 <Directory />
120 Options FollowSymLinks
121 AllowOverride None
122 Order deny,allow
123 allow from all
124 </Directory>
[root@www www]# /usr/local/apache2/bin/apachectl graceful
6、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
7、安裝Discuz
[root@www www]# chown -R daemon config/ data/ uc_client/ uc_server/
第一次安裝選全新安裝
8、配置MySQL相關
一、建立discuz數據庫
mysql> create database discuz;
Query OK, 1 row affected (0.07 sec)
二、建立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)
三、繼續安裝discuz
安裝完成
9、Apache相關配置
一、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
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
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
<Directory "/data/www/abc">
AllowOverride AuthConfig
AuthName "自定義的"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</directory>
</VirtualHost>
[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
二、默認虛擬主機
[root@www www]# mkdir /tmp/123
[root@www www]# chmod 600 /tmp/123
增長如下虛擬目錄,用於拒絕訪問
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/tmp/123"
ServerName 11111.com
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
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
<Directory "/data/www/abc">
AllowOverride AuthConfig
AuthName "users"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</directory>
</VirtualHost>
[root@www www]# apachectl graceful
訪問測試:www.222.com或直接訪問IP,只有test和aaa能夠訪問
三、域名301跳轉
修改虛擬主機配置文件,增長域名跳轉模塊
[root@www www]# vim /etc/httpd/extra/httpd-vhosts.conf
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.aaa.com$
RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]
</IfModule>
[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
四、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
五、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