环境:centos6.7,ip地址:192.168.1.174
1、此次操作为首次安装apache,如果之前安装过需要先行将已存在的相关文件删除以免冲突。
2、下载Apache安装包(httpd-2.4.3.tar.gz或httpd-2.2.23.tar.gz),下载地址:http://httpd.apache.org/
在安装Apache时,只安装了2.4.*版本。
httpd-2.2.23版本编译命令:
./configure --prefix=/usr/local/apache2 (安装目录参数后面可以不加任何参数,直接安装即可) make make install
httpd-2.4.3版本编译命令:
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre (除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数) make make install
在编译Apache(在安装httpd-2.4.3时遇到的问题)时分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题,下面就httpd-2.4.3的这些问题解决来实际操作一把。
http://apr.apache.org/download.cgi 下载apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz
http://sourceforge.net/projects/pcre/files/latest/download 下载pcre-8.31.zip
1.解决apr not found问题
[root@localhost bin]# tar -zxf apr-1.4.5.tar.gz [root@localhost apr-1.4.5]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.4.5]# make [root@localhost apr-1.4.5]# make install
2.解决APR-util not found问题
[root@localhost bin]# tar -zxf apr-util-1.3.12.tar.gz [root@localhost apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config [root@localhost apr-util-1.3.12]# make [root@localhost apr-util-1.3.12]# make install
3、解决pcre-config for libpcre not found问题
[root@localhost ~]# unzip pcre-8.31.zip [root@localhost ~]# cd pcre-8.31 [root@localhost pcre-8.31]# ./configure --prefix=/usr/local/pcre [root@localhost pcre-8.31]# make[root@localhost pcre-8.31]# make install
•启动Apache:/usr/local/apache2/bin/apachectl start
•停止Apache:/usr/local/apache2/bin/apachectl stop
•重启Apache:/usr/local/apache2/bin/apachectl restart
网站放在/usr/local/apache2/htdocs目录下
配置文件(/usr/local/apache2/conf)中做了如下修改
将serverName的注释去掉并设置为本机的ip地址(192.168.1.174)
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName 192.168.1.174:80
在浏览器中通过192.168.1.174:80,如果看到页面中显示“It works!”字样,则代表Apache验证通过。如果网站的index后缀是PHP格式的,则要修改httpd.conf配置文件(/usr/local/apache2/conf),在DirectoryIndex增加 index.php。
若希望浏览器能够接卸CGI程序,比如hello.py(此文件在/usr/local/apache2/cgi-bin目录中)
需要配置文件中进行如下修改:
找到指定行添加: AddHandler cgi-script .cgi .py
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny 主要为此行
Require all granted
</Directory>
浏览器中输入 http://192.168.1.174/cgi-bin/hello.py
如果出现:You don't have permission to access /cgi-bin/hello.py on this server.
建议进行权限方面的问题排查。
注:笔者有些偷懒,故部分内容直接借鉴了他人的博客,其地址为:http://www.cnblogs.com/zhuque/archive/2012/11/03/2763352.html#