Php 如何在Apache中与两个不同的域共享一组文件?
我想在两种不同的模式下运行我的网站:开发和测试。我目前已经在Php 如何在Apache中与两个不同的域共享一组文件?,php,apache,Php,Apache,我想在两种不同的模式下运行我的网站:开发和测试。我目前已经在/var/www/mywebsite.com中建立了该网站,并且运行良好。现在我想设置一个指向相同文件的不同url,但只有一个区别:apache的setEnv。我想setEnv APP\u ENV test这样我就可以点击http://test.mywebsite.com/并阅读PHP中的APP_ENV。这可能吗?如果您想要两种不同的Apache设置,最好使用。关键是要有两种不同的配置,但使用相同的DocumentRoot。例如,这将是
/var/www/mywebsite.com
中建立了该网站,并且运行良好。现在我想设置一个指向相同文件的不同url,但只有一个区别:apache的setEnv
。我想setEnv APP\u ENV test
这样我就可以点击http://test.mywebsite.com/
并阅读PHP中的APP_ENV
。这可能吗?如果您想要两种不同的Apache设置,最好使用。关键是要有两种不同的配置,但使用相同的DocumentRoot
。例如,这将是mywebsite.com
的Apache虚拟主机设置:
<VirtualHost *:80>
DocumentRoot /var/www/mywebsite.com
ServerName mywebsite.com
ServerAlias mywebsite.com
ErrorLog /var/log/apache2/mywebsite.com.error.log
CustomLog /var/log/apache2/mywebsite.com.access.log combined
SetEnv APPLICATION_ENV "prod"
<Directory "/var/www/mywebsite.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/mywebsite.com
ServerName test.mywebsite.com
ServerAlias test.mywebsite.com
ErrorLog /var/log/apache2/test.mywebsite.com.error.log
CustomLog /var/log/apache2/test.mywebsite.com.access.log combined
SetEnv APPLICATION_ENV "test"
<Directory "/var/www/mywebsite.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我假设你是在Ubuntu上安装的。因此,我建议将它们放入两个不同的文件中,如下所示:
nano /etc/apache2/sites-available/mywebsite.com
nano /etc/apache2/sites-available/test.mywebsite.com
sudo ln -s /etc/apache2/sites-available/mywebsite.com /etc/apache2/sites-enabled/mywebsite.com
sudo ln -s /etc/apache2/sites-available/test.mywebsite.com /etc/apache2/sites-enabled/test.mywebsite.com
sudo service apache2 restart
然后将配置符号链接到启用的站点,如下所示:
nano /etc/apache2/sites-available/mywebsite.com
nano /etc/apache2/sites-available/test.mywebsite.com
sudo ln -s /etc/apache2/sites-available/mywebsite.com /etc/apache2/sites-enabled/mywebsite.com
sudo ln -s /etc/apache2/sites-available/test.mywebsite.com /etc/apache2/sites-enabled/test.mywebsite.com
sudo service apache2 restart
按如下方式重新启动Apache:
nano /etc/apache2/sites-available/mywebsite.com
nano /etc/apache2/sites-available/test.mywebsite.com
sudo ln -s /etc/apache2/sites-available/mywebsite.com /etc/apache2/sites-enabled/mywebsite.com
sudo ln -s /etc/apache2/sites-available/test.mywebsite.com /etc/apache2/sites-enabled/test.mywebsite.com
sudo service apache2 restart
然后,您应该使用
APPLICATION\u ENV“prod”
和APPLICATION\u ENV“test”
来处理服务器故障,但您可能要寻找的是两个不同的Apache虚拟主机。一个用于mywebsite.com
,另一个用于test.mywebsite.com
。同意,我通过复制常规配置并更改名称,然后像这样进行符号链接:ln-s/var/www/mywebsite.com/var/www/test.mywebsite.com
,这“起作用”是因为我可以curl
新的URL,但是它没有拾取setEnv
。我认为你不需要有一个符号链接来工作。看看我的答案。记录在案,你使用的是什么操作系统?森托斯/雷德哈特?Ubuntu/Debian?