I'm trying to configure Apache to have to different symfony projects (each with his own installation of the framework) under the same domain, but I can't ge开发者_如何转开发t it to work using folders.
This is what I would like to have:
- mydomain.com/projectone/
- mydomain.com/projecttwo/
I can make it work using subdomains, but is not the preferred solution for me, because I end up having crazy subdomains like:
- projectone.mydomain.com
- backend.projectone.mydomain.com
- projecttwo.mydomain.com
- backend.projecttwo.mydomain.com
I'm using this configuration in Apache to make it work with subdomains:
<VirtualHost 127.0.0.1:8080>
ServerName projectone.mydomain.com
DocumentRoot "/home/projectone/web"
DirectoryIndex frontend.php
<Directory "/home/projectone/web">
Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
AllowOverride None
Allow from All
RewriteEngine On
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ frontend.php [QSA,L]
</Directory>
Alias /sf /home/projectone/lib/vendor/symfony/data/web/sf
<Directory "/home/projectone/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Any idea on how to achieve the folders solution?
Thanks in advance, Eneko
I do this all the time. Here's the relevant Apache config. I also set up custom error handlers for each symfony app.
# make sure your symfony install dir is available
<Directory "/var/www/symfony1.4">
AllowOverride All
Allow from all
</Directory>
# each app under http://mysite/myapp gets a section like this
Alias /myapp/sf "/var/www/symfony1.4/data/web/sf"
Alias /myapp "/var/www/vhosts/myvhost/sf_apps/myapp/web"
<Directory "/var/www/vhosts/myvhost/sf_apps/myapp/web">
AllowOverride All
Allow from all
ErrorDocument 404 /myapp/default/error404
ErrorDocument 500 /myapp/myThemePlugin/errors/error500.php
</Directory>
You also need to hack this line in your web/.htaccess
file.
# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /myapp
I have tried this code and seems to work. Since I haven't tested it I am not sure about this being error free, but it can be a hint for you.
<VirtualHost 127.0.0.1:8088>
Alias /badger /home/amqs/proyectos/sales/nuevo/salesprime/web
DocumentRoot "/home/amqs/proyectos/sales/nuevo/salesprime/web"
DirectoryIndex frontend_dev.php
<Directory "/home/amqs/proyectos/sales/nuevo/salesprime/web">
AllowOverride All
Allow from All
</Directory>
Alias /sales /home/amqs/proyectos/sales/salesprime2/web
DocumentRoot "/home/amqs/proyectos/sales/salesprime2/web"
DirectoryIndex frontend_dev.php
<Directory "/home/amqs/proyectos/sales/salesprime2/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
You can use the setWebDir method in your ProjectConfiguration to specify a unique web directory to serve out of in each project. This will allow you to host the project files (apps, config, lib, plugins, etc) in any directory you'd like (/home/projectone) while moving the files normally in web/ to a completely different location (/home/mydomain/web/projectone). You have the option of adjusting your entire project's web directory from your root ProjectConfiguration in config/ProjectConfiguration.class.php
:
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->setWebDir('/home/mydomain/web/projectone');
}
}
or if you'd like each of your applications to have a different web directory (/projectone/ for the front-end and /projectone/backend/ for the back-end) you can set the web directory from each of the application configurations in apps/myapp/config/myappConfiguration.class.php
:
class myappConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->setWebDir('/home/mydomain/web/projectone');
}
}
Hope that helps.
Try this configuration.
This work for symfony 2 and 3.
<VirtualHost 127.0.0.1:8080>
Alias /app1 /var/www/public_html/app1/web
DocumentRoot "/var/www/public_html/app1/web"
DirectoryIndex app.php
<Directory "/var/www/public_html/app1/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Documentation: https://symfony.com/doc/3.3/setup/web_server_configuration.html
精彩评论