我无法从自定义位置运行 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
怎么会?
答案1
该错误是由于您的 VirtualHost 或块等中没有如下语句或任何其他类似这样的块导致的:
Options Indexes MultiViews FollowSymLinks
允许列出目录内容,因为未找到默认文件。您可以在类似区域(例如在 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,通常它更安全一些。