Linux 下安装Apache
网上看到别人的教程,这里简略写一下命令和步奏,具体安装和分析可查看原文。
1. apache 2.2.22 官网下载 http://httpd.apache.org/download.cgi
2. 解压 tar -zxvf httpd-2.2.22.tar.gz
3. 建立目标文件夹(注意以下所有操作都时在root用户下执行的)
mkdir /usr/local/apache2
也就是说等下安装的apache2要安装到这个文件夹里面。
4. 配置
回到原来解压之后产生的文件夹
./configure --prefix=/usr/local/apache2 --enable-module=shared
5. 接下来会有三个错误执行下面三条命令
./configure --with-included-apr
yum(或者apt) install gcc
yum(或者apt) install gcc-c++
6. 编译
make
7. 安装
make install
8. 启动,重启和停止 ,先切换到安装完成后的目录/usr/local/apache2/bin
./apachectl -k start
./apachectl -k restart
./apachectl -k stop
9. 配置文件(满足最基本的配置)
编辑 /usr/local/apache2/conf/httpd.conf 文件
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php(使Apcche支持PHP)
AddType application/x-httpd-php-source .php5
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
添加:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerName localhost:80
记得要去掉前面的“#”
10. 测试
在浏览器里输入http://127.0.0.1
如果出现It Works!说明成功。
11. 修改默认的Web站点目录
默认的目录为 "/usr/local/apache2/htdocs",修改apache的配置文件httpd.conf,比如在新建一个 /home/gyw/WebSite的目录作为apache的站点目录
找到DocumentRoot这一行修改为:DocumentRoot "/home/gyw/WebSite"
找到 <Directory> 这一行修改为:<Directory "/home/gyw/WebSite">
测试:修改到文件夹出现错误:
“You don't have permission to access /index.html on this server.”
解决方法:
更改文件权限;chmod 755 index.html
打开apache配置文件httpd.conf,找到这么一段:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
deny from all
Satisfy all
</Directory>