- 安装mysql
cd /usr/local/src/ #源码包默认放在这个位置
wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
注意:上面的地址是32位机器用的,如果你的机器是64位,下载这个包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安装方法是一样的。
tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz #解压
mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql #移动并改名
useradd -s /sbin/nologin mysql #建立mysql用户
cd /usr/local/mysql
mkdir -p /data/mysql #创建datadir,数据库会放到这里
chown –R mysql:mysql /data/mysql #更改权限
./scripts/mysql_install_db –user=mysql –datadir=/data/mysql
#–user表示定义数据库的所属主,–datadir表示定义数据库的安装目录(建议放到大的空间上)。这一步很关键,如果接下来看到两个”OK”,说明执行正确。
cp support-files/my-large.cnf /etc/my.cnf #复制配置文件
cp support-files/mysql.server /etc/init.d/mysqld #复制启动脚本文件并修改其属性
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld #修改启动脚本中的“datadir=/data/mysql”(前面初始化数据库时定义的目录)。
chkconfig –add mysqld #启动脚本加入系统服务项
chkconfig mysqld on #开机启动时启动mysql
service mysqld start #启动mysql
如启动不了,请到/data/mysql/目录下,查看错误日志,这个日志通常是主机名.err。检查mysql是否启动的命令为:
Ps -aux |grep mysqld
- 安装apache
wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zvxf httpd-2.2.16.tar.gz
cd httpd-2.2.16
./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so --enable-deflate=shared --enable-expires=shared
--eanble-rewrite=shared
--with-included-apr --with-pcre
#–prefix指定安装目录,–enable-so表示启用DSO,#–enable-deflate=shared表示以共享的方式编译deflate.
make && make install
#可以先 make ,然后用echo $?看是不是显示0,如果是0则表示没有问题,不是0则有问题。同理make install后用echo $?看是否为0。
要安装gcc套件。
#检测apache是否满足配置条件时用以下命令:
/usr/local/apache2/bin/apachectl -t 正常应该为ok。
重启apache命令如下:
/usr/local/apache2/bin/apachectl restart 或者
/usr/local/apache2/bin/apachectl graceful
- 安装php
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
tar zxf php-5.3.28.tar.gz
cd php-5.3.28
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
make && make install
- 配置apache结合php
vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
- 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:
<?php
echo “php解析正常”;
?>
保存后,继续测试:
curl localhost/1.php
- 下载discuz!
mkdir /data/www
cd /data/www
wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
unzip Discuz_X3.2_SC_GBK.zip
mv upload/* .
- 配置第一个虚拟主机
删除httpd.conf中的这行前面的警号
#Include conf/extra/httpd-vhosts.conf
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
加入如下配置:
<VirtualHost *:80>
DocumentRoot “/data/www”
ServerName www.123.com
</VirtualHost>
- 配置mysql,给Discuz!增加一个账户
给mysql root账户设置密码,然后命令行进入mysql,创建新的库,并创建一个新的帐号对该库有所有权限:
> create database discuz;
> grant all on dicuz.* to ‘lipeng’@’localhost’ identified by ‘123456lipeng’;
> quit
- 安装Discuz!
先绑定hosts
192.168.11.190 www.123.com
浏览器输入:
www.123.com/install/
根据提示,修改对应目录的权限
cd /data/www
chown daemon:daemon data uc_server/data uc_client/data config // 让这几个目录支持apache运行帐号可写
- 为某个虚拟主机配置用户认证
在相应的虚拟主机配置文件段,加入
<Directory *>
AllowOverride AuthConfig
AuthName “自定义的”
AuthType Basic
AuthUserFile /data/.htpasswd # 这里的/data/.htpasswd你可以随便写一个路径或名字,没有限制
require valid-user
</Directory>
保存后,然后
创建apache的验证用户
htpasswd -cm /data/.htpasswd test
增加第二个用户的时候,就不要加-c了,因为-c是创建的意思,如果加上会把这个文件重写。
- 配置域名跳转
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain1.com$
RewriteRule ^/(.*)$ http://www.domain2.com/$1 [R=301,L]
</IfModule>
如果是多个域名,可以这样设置:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com [OR]
RewriteCond %{HTTP_HOST} ^www.domain1.com$
RewriteRule ^/(.*)$ http://www.domain2.com/$1 [R=301,L]
</IfModule>
- 配置apache的访问日志
ErrorLog “|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-error_%Y%m%d.log 86400”
SetEnvIf Request_URI “.*\.gif$” image-request
SetEnvIf Request_URI “.*\.jpg$” image-request
SetEnvIf Request_URI “.*\.png$” image-request
SetEnvIf Request_URI “.*\.bmp$” image-request
SetEnvIf Request_URI “.*\.swf$” image-request
SetEnvIf Request_URI “.*\.js$” image-request
SetEnvIf Request_URI “.*\.css$” image-request
CustomLog “|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-access_%Y%m%d.log 86400” combined env=!image-request
- 配置静态文件缓存
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif “access plus 1 days”
ExpiresByType image/jpeg “access plus 24 hours”
ExpiresByType image/png “access plus 24 hours”
ExpiresByType text/css “now plus 2 hour”
ExpiresByType application/x-javascript “now plus 2 hours”
ExpiresByType application/x-shockwave-flash “now plus 2 hours”
ExpiresDefault “now plus 0 min”
</IfModule>
- 配置防盗链
SetEnvIfNoCase Referer “^http://.*\.yourdomin\.com” local_ref
SetEnvIfNoCase Referer “.*\.yourdomin\.com” local_ref
SetEnvIfNoCase Referer “^$” local_ref
<filesmatch “\.(txt|doc|mp3|zip|rar|jpg|gif)”>
Order Allow,Deny
Allow from env=local_ref
</filesmatch>
#要把网站的IP地址配进去,要不然通IP访问就不会显示图片,本人遇到过此问题。
- 访问控制
<Directory /data/www/>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
针对请求的uri去限制
<filesmatch “(.*)admin(.*)”>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</filesmatch>
某个目录下禁止解析php
<Directory /data/www/path>
php_admin_flag engine off
<filesmatch “(.*)php”>
Order deny,allow
Deny from all
</filesmatch>
</Directory>
本人虚拟主机中的配置
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot “/data/www”
ServerName www.1.com
ServerAlias www.a.com www.b.com
#用户认证
# <Directory /data/www>
# AllowOverride AuthConfig
# AuthName “fddddfdfdfddfdf”
# AuthType Basic
# AuthUserFile /data/.htpasswd
# require valid-user
#</Directory>
#域名跳转
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.a.com [OR]
RewriteCond %{HTTP_HOST} ^www.b.com$
RewriteRule ^/(.*)$
http://www.1.com/$1 [R=301,L]
</IfModule>
#伪静态(放在上面的</IfModule>中间就可以)
RewriteRule ^/topic-(.+)\.html$ /portal.php?mod=topic&topic=$1&%1
RewriteRule ^/article-([0-9]+)-([0-9]+)\.html$ /portal.php?mod=view&aid=$1&page=$2&%1
RewriteRule ^/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteRule ^/group-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=group&fid=$1&page=$2&%1
RewriteRule ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2&%1
RewriteRule ^/blog-([0-9]+)-([0-9]+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteRule ^/archiver/(fid|tid)-([0-9]+)\.html$ /archiver/index.php?action=$1&value=$2&%1
RewriteRule ^/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ /plugin.php?id=$1:$2&%1
#日志
ErrorLog “|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/oem.discuz.qq.com-error_%Y%m%d.log 86400”
SetEnvIf Request_URI “.*\.gif$” image-request
SetEnvIf Request_URI “.*\.jpg$” image-request
SetEnvIf Request_URI “.*\.png$” image-request
SetEnvIf Request_URI “.*\.bmp$” image-request
SetEnvIf Request_URI “.*\.swf$” image-request
SetEnvIf Request_URI “.*\.js$” image-request
SetEnvIf Request_URI “.*\.css$” image-request
CustomLog “|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/oem.discuz.qq.com-access_%Y%m%d.log 86400” combined env=!image-request
#配置静态文件缓存
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif “access plus 1 days”
ExpiresByType image/jpeg “access plus 24 hours”
ExpiresByType image/png “access plus 24 hours”
ExpiresByType text/css “now plus 2 hour”
ExpiresByType application/x-javascript “now plus 2 hours”
ExpiresByType application/x-shockwave-flash “now plus 2 hours”
ExpiresDefault “now plus 0 min”
</IfModule>
#配置防盗链
SetEnvIfNoCase Referer “^http://www.1.com” local_ref
SetEnvIfNoCase Referer “www.a.com” local_ref
SetEnvIfNoCase Referer “www.b.com” local_ref
SetEnvIfNoCase Referer “192.168.88.105” local_ref
SetEnvIfNoCase Referer “^$” local_ref
<filesmatch “\.(txt|doc|mp3|zip|rar|jpg|gif)”>
Order Allow,Deny
Allow from env=local_ref
</filesmatch>
#访问控制
# <Directory /data/www/>
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
# </Directory>
#ErrorLog “logs/dummy-host.example.com-error_log”
#CustomLog “logs/dummy-host.example.com-access_log” common
</VirtualHost>
装Discuz时,不能访问时,/usr/local/apache2/conf/httpd.conf文件中上面最后改为Allow from all就会出现安装界面了。