apache2开启重写模块


Ubuntu LAMP 如何配置Apache

1. 修改文件夹读写权限

PHP网络服务器根目录默认位置:/var/www,默认属性只允许root用户执行操作,但是在Ubuntu中因为安全性的考虑默认关闭了 root账户。为了可以在这个文件夹新建修改php、html文件等等,可以通过终端命令行修改文件夹的这个属性:

C代码   收藏代码
  1. sudo chmod 777 /var/www  

 

2. 启用 mod_rewrite 模块

C代码   收藏代码
  1. #终端命令:  
  2. sudo a2enmod rewrite  
  3.   
  4. #重启Apache服务器:  
  5. sudo /etc/init.d/apache2 restart   

 

Apache重启后我们可以测试一下,在/var/www目录下新建文件test.php,写入代码:  保存,在地址栏输入http://127.0.0.1/test.php 或 http://localhost/test.php ,如果正确出现了php 配置信息则表明LAMP Apache已经正常工作了(记得重启Apache服务器后再测试)。

 

如何测试是否已经开启地址重写?查看这里

 

如果还是不行的话,可以考虑编辑  /etc/apache2/apache2.conf

C代码   收藏代码
  1.   
  2. AllowOverride All  
  3.   
  4.   

 

同时还需要考虑的文件是:your site virtual host file or edit the 000-default in the /etc/apache2/sites-enabled/

 

Add this lines:

C代码   收藏代码
  1.   
  2. AllowOverride all  
  3.   
 
after this block:
C代码   收藏代码
  1.   
  2. Options FollowSymLinks  
  3. AllowOverride None  
  4.   

 

If you get a 500 type of error trying to view your site don’t panic!

This happens because the rewrite module doesn’t come enabled by default for security reasons.

Create a new file called rewrite.conf in _/etc/apache2/mods-enabled_
in the file put this line LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Reload one more time the server.

 

3. 设置Apache支持.htm .html .php

C代码   收藏代码
  1. sudo gedit /etc/apache2/apache2.conf  
  2. #或  
  3. sudo gedit /etc/apache2/mods-enabled/php5.conf  
在打开的文件中加上
AddType application/x-httpd-php .php .htm .html 即可。

原地址: http://justcoding.iteye.com/blog/1565170

你可能感兴趣的:(服务器运维,apache2重写)