`

linux 安装apache和php

阅读更多

 

安装:

 

apache:

 

到apache.org去下载apache

 

# tar -zxvf httpd-2.2.11

# cd httpd-2.2.11

# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite

# make

# make install

 

php:

 

在如下页面下载php的for Linux 的源码包

http://www.php.net/downloads.php ;

 

# tar -zxvf php-5.2.9.tar.gz

# cd php-5.2.8

# ./configure --prefix=/user/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql=/usr/local/mysql --with-system-regex --with-zlib

# make

# make install

# cp php.ini-dist /usr/local/lib/php.ini

 

配置:

 

# ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd

# vi /usr/local/apache/bin/apachectl 

修改此文件,将以下两行加入到 文件的第二行(包括#号)

 

# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server 

 

# vi /usr/local/apache/conf/httpd.conf

修改此文件,更改以下指令为:

DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3
ServerName  12.34.56.78:80  //这里的ip和端口号视实际情况而定

Options FollowSymLinks MultiViews //为安全起见,去掉"Indexes"

 

找到AddType处,并添加以下2行:

AddType application/x-httpd-php .php .php3 .phtml .inc
AddType application/x-httpd-php-source .phps

 

vi /usr/local/lib/php.ini

更改以下指令为:

#register-golbals = On

 

 

添加到开机自启动

chkconfig --add httpd

 

 

测试:

 

/etc/init.d/httpd start

 

如果顺利,那么可以从其他机器上的浏览器上连接到你的机器并将看到Apache的欢迎页面。

 

测试php:

 

新建 test.php文件,内容如下:

<? phpinfo() ;?>

将此文件存放在apache的默认文件目录中,

在/usr/local/apache/conf/httpd.conf 中 找到 DocumentRoot  此项设置就是文件访问目录

一般为 /usr/local/apache/htdocs


正常的话,应该能看到php的信息了,恭喜你的Apche+Mysql+PHP安装成功。

 

 

如果无法访问,有可能是防火墙的原因

 

通过/etc/init.d/iptables status命令查询是否有打开80端口,如果没有可通过两种方式处理:
1.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

2.关闭防火墙
/etc/init.d/iptables stop
#start 开启
#restart 重启
永久性关闭防火墙chkconfig --level 35 iptables off

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics