禁止 – 与Apache的PHP网站,虽然它不应该

我无法从我的自定义位置运行一个PHP

$ cat /etc/apache2/sites-available/000-default.conf <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/alex/Documents/var_www_html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet $ ls -l ~/Documents/var_www_html total 52 drwxr-xr-x 2 alex alex 4096 Oct 25 16:37 dir1 drwxr-xr-x 2 alex alex 4096 Oct 25 16:37 dir2 -rwxr-xr-x 1 alex alex 493 Oct 25 16:37 file1.inc.php drwxr-xr-x 3 alex alex 4096 Oct 25 16:37 css -rwxr-xr-x 1 alex alex 3638 Oct 25 16:37 favicon.ico drwxr-xr-x 2 alex alex 4096 Oct 25 16:37 images -rwxr-xr-x 1 alex alex 2091 Oct 25 16:37 index.php drwxr-xr-x 3 alex alex 4096 Oct 25 16:37 js drwxr-xr-x 2 alex alex 4096 Oct 25 16:37 lib -rwxr-xr-x 1 alex alex 1081 Oct 25 16:37 LICENSE -rwxr-xr-x 1 alex alex 719 Oct 25 16:37 README.md drwxr-xr-x 2 alex alex 4096 Oct 25 16:37 tpl drwxr-xr-x 3 alex alex 4096 Oct 25 16:37 website_itself $ ls -ld ~/Documents/var_www_html drwxr-xr-x 10 alex alex 4096 Oct 25 16:37 /home/alex/Documents/var_www_html 

错误是:

 Forbidden You don't have permission to access / on this server. Apache/2.4.7 (Ubuntu) Server at localhost Port 80 

怎么来的?

这个错误是由于没有像你在VirtualHost或块等内的语句,或者像这样的任何其他块:

 Options Indexes MultiViews FollowSymLinks 

允许列出目录内容,因为没有find默认文件。 您可以在类似的区域中指定一个默认文件(例如下面的语句)(所以在VirtualHost,Location等中:

 DirectoryIndex index.php index.html index.html.gz error.php idx.php index.html index.cgi index.pl index.php index.xhtml 

你有没有加载mod_php? 你有没有想过在FCGI下使用perl,一般来说它更安全一些。