我正在开始学习 PHP 课程,该课程需要自己的网页,我不想与我现有的工作发生冲突。Ubuntu 说明如下:HTTPD——Apache2 Web 服务器
请参阅我新文件中的以下代码“/etc/apache2/sites-available/RecipeCenter”。旧文件“/etc/apache2/sites-available/000-default.conf”仍然存在。两个版本之间的唯一区别是文档根目录的行,新文件中的行从“/var/www/html”更改为“/var/www/RecipeCenter”,如下所示。按照说明操作后,我还运行了更新程序并重新启动。没有生成任何错误消息。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/RecipeCenter
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
在 Firefox 浏览器中输入“localhost/RecipeCenter/testph2.php”不起作用。但是,作为测试,我确实将 RecipeCenter 文件夹复制到与我的默认文件夹相同的文件夹中,这样我就能够让“localhost/RecipeCenter/testph.php”工作。虽然这解决了问题,但我仍然对为什么新的 .conf 文件不起作用感到疑惑。
答案1
您应该将 /etc/apache2/sites-available/RecipeCenter 符号链接到 /etc/apache2/sites-enabled/100-RecipeCenter.conf。(数字并不重要,尽管文件是按字母顺序包含的,因此无论您为符号链接选择什么名称,它都应按字母顺序位于 000-default.conf 之后。)
Apache 实际上包含来自 /etc/apache2/sites-enabled 的 vhost 配置文件。它不包含 sites-available。结构如此构成,允许您通过在 /etc/apache2/sites-enabled 中创建/删除符号链接轻松启用/禁用站点,而无需移动或删除文件。