Ubuntu LAMP 如何配置Apache
1. 修改文件夾讀寫權限
PHP網絡服務器根目錄默認位置:/var/www,默認屬性只允許root用戶執行操作,但是在Ubuntu中因爲安全性的考慮默認關閉了 root賬戶。爲了可以在這個文件夾新建修改php、html文件等等,可以通過終端命令行修改文件夾的這個屬性:
- sudo chmod 777 /var/www
2. 啓用 mod_rewrite 模塊
- #終端命令:
- sudo a2enmod rewrite
- #重啓Apache服務器:
- 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
- <tt><Directory /your/path>
- AllowOverride All
- </Directory>
- </tt>
同時還需要考慮的文件是:your site virtual host file or edit the 000-default in the /etc/apache2/sites-enabled/
Add this lines:
- <Directory /var/www/mysite/>
- AllowOverride all
- </Directory>
- <Directory />
- Options FollowSymLinks
- AllowOverride None
- </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
- sudo gedit /etc/apache2/apache2.conf
- #或
- sudo gedit /etc/apache2/mods-enabled/php5.conf
AddType application/x-httpd-php .php .htm .html 即可。