Ubuntu下配置Apache2 和php的步骤
1.sudo apt-get install apache2
2.sudo apt-get install php5
我的系统环境是Ubuntu14.04所以系统会自动安装下面这个链接用于Apache2解析php
sudo apt-get install libapache2-mod-php5
重点在这儿,但是这种情况下依然会出现Apache无法解析php的情况
这种情况下需要在目录 /etc/apache2下的apache2.conf
文件里面添加如下两行配置(我是在末尾添加的):
AddHandler php5-script .php .html
AddType text/html .php. html
然后记得重启Apache2
sudo /etc/init.d/apache2 restart
这种情况下就解决了无法解析php的问题。
题外话:如果需要更改apache的目录,需要在 apache2.conf
下和 /etc/apache2/site-available目录下的
000-default.conf 修改为你需要的目录.
在apache2.conf 找到apache2的默认目录 /var/www
和000-default.conf里面的 DocumentRoot
/var/www 改为你需要的目录即可。
更改完毕重启Apache2
sudo /etc/init.d/apache2 restart