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,寫入代碼:  <?php phpinfo(); ?>保存,在地址欄輸入http://127.0.0.1/test.php 或 http://localhost/test.php ,如果正確出現了php 配置信息則表明LAMP Apache已經正常工作了(記得重啓Apache服務器後再測試)。

 

如何測試是否已經開啓地址重寫?查看這裏

 

如果還是不行的話,可以考慮編輯  /etc/apache2/apache2.conf

C代碼  收藏代碼
  1. <tt><Directory /your/path>  
  2. AllowOverride All  
  3. </Directory>  
  4. </tt>  

 

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

 

Add this lines:

C代碼  收藏代碼
  1. <Directory /var/www/mysite/>  
  2. AllowOverride all  
  3. </Directory>  
 
after this block:
C代碼  收藏代碼
  1. <Directory />  
  2. Options FollowSymLinks  
  3. AllowOverride None  
  4. </Directory>  

 

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 即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章