安装Apache2
下载httpd-2.0.59.tar.gz,执行
(下面的 xzfv 应该是 zxvf )
sudo tar xzfv httpd-2.0.59.tar.gz
sudo cd httpd-2.0.59
sudo ./configure --prefix=/usr/local/apache2 --enable-module=most --enable-rewrite --enable-shared=max --enable-so
如果提示如下错误:
checking for C compiler default output file name... configure: error: C compiler cannot create executables
原因是未安装libc6-dev ,执行
sudo apt-get install build-essential
就ok了。
然后从新执行:
sudo ./configure --prefix=/usr/local/apache2 --enable-module=most --enable-rewrite --enable-shared=max --enable-so
未报错,接着执行
sudo make
sudo make install
sudo groupadd apache
sudo useradd -g apache apache
sudo passwd apache
sudo chown -R apache:apache /usr/local/apache2
修改apache的配置文件,执行
sudo vi /usr/local/apache2/conf/httpd.conf找到
User nobody
Group #-1
修改成
User apache
Group apache
找到
#ServerName www.example.com:80
改为
ServerName *:80
保存!
执行命令
sudo /usr/local/apache2/bin/apachectl start启动apache.
打开浏览器,访问http://localhost
如果一切顺利,应该可以看到apache的测试页面。恭喜你,apache安装好了!
通过Ubuntu 搭建WEB服务器,必须首先修改apache2的默认80端口,因为这个端口往往会被电信商以保护用户网络完全为由而关闭掉,
值得注意的时,8080端口也有可能被封掉,我就遇到了这个问题,导致我在apache2配置上找了半天原因,可气的服务商!
不管怎样,只要你选择合适的端口(电信商没有封的),进行如下的设置即可:
1, 修改 /etc/apache2/ports.conf 将
NameVirtualHost *:80
Listen 80
改为自己需要的端口
NameVirtualHost *:9000
Listen 9000
2,修改/etc/apache2/sites-available/default 将第一行的
<VirtualHost *:80>
改为自己需要的端口
<VirtualHost *:9000>
3,修改 /etc/init.d/apache2/httpd.conf 添加
Servername localhost
否则重启时会报如下错误
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
4,重启apache
sudo /etc/init.d/apache2 restart
端口修改完毕。apache的端口修改为9000了。
###########################################
修改默认网站目录:
/etc/apache2/sites-available/default
将/var/www 修改位你的路径: /var/www/GMG/
修改默认主页文档:
/etc/apache2/mods-available/dir.conf
将 index.* 替换为 xxx.*