How to configure Apache to have two symfony projects in the same domain (without using subdomains)?

symfony 4 nginx config
symfony local web server
how to run symfony project in localhost
install symfony
install symfony ubuntu
symfony server production
symfony apache docker
symfony project download

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 get 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

Configuring a Web Server (Symfony Docs), Configuring a Web Server: The preferred way to develop your Symfony When using Apache, you can configure PHP as an Apache module or with FastCGI using PHP FPM. <VirtualHost *:80> ServerName domain.tld ServerAlias www.​domain.tld 1 2 3 4. <Directory /var/www/project/public> Require all granted # . I have 2 completely different projects I would like to host from the same domain name "mysimpledomainname.com" with ip address xx.xx.xxx.xx (not local) The 2 projects are located at Project 1) /var/www/html/project1 Project 2) /var/www/html/project2. I would like to have the 2 projects resolve like this. Project 1. mysimpledomainname.com. project 2

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>

Tagged symfony - Page 1, After seting up a symfony project and altering hosts file, the non-symfony projects aren't to possess two symfony projects within the same domain (without needing subdomains)? Apache configuration for Symfony website with virtual hosts  Multiple domains on same Symfony app. In your symfony routing configuration you can then parse the hostname. Use multiple domain to load content from main

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.

Login issues with multiple sites in the same domain (session cookie , Two sites on the dev server: 1. projects/cvs/drupal 2. It is recommended to use the same exact domain specified * in $base_url. @dan_aka_jack: try without the dot. but if you do not have subdomain, you could just set installer (and updater)? Both the session name and cookie domain are essentially  Multiple applications within one project. During the course of project design, you will meet one day or another the problem of multiple applications access. For instance, in our myproject project, you might have a myapp application for the public and an admin application o manage the content (usually called a back-office). How to authorize

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

Problems configuring vhost for multiapplication server · Issue #3805 , Projects 1 Still I tried using the vhost configuration file from the docs for the sake of 2.3.4 and 2.3.2 (the latter for the package); How did you install wallabag? If you have a domain name mydomain.tld that redirects to your server, the address https://wallabag.yourdomain.tld/ (https)? There is no "by  Symfony Local Web Server¶. You can run Symfony applications with any web server (Apache, nginx, the internal PHP web server, etc.). However, Symfony provides its own web server to make you more productive while developing your applications.

Problems installing maven - java ‍⚕️ ‍🤝‍ , At an MS-DOS prompt, set PATH=path_to_maven/bin;%PATH% You may need to restart your computer for the changes to the PATH to take I installed Maven 2 on my computer and I had problems calling mvn -version from How to configure Apache for two symfony projects in one domain (without using subdomains)?. We have now the application files in place, but we still need to install the project dependencies and configure the application parameters. Symfony is built to work well across different environments. By default, it will use development settings, which influences the way it handles cache and errors.

setcookie - Manual, Setting this to a subdomain (such as 'www.example.com') will make the cookie available to An associative array which may have any of the keys expires, path, domain, secure, If the samesite element is omitted, no SameSite cookie attribute is set. Consider explode() to set one cookie with multiple names and values. In this configuration, when you are pointing two websites (with different ip-address) to the server that runs Apache, that physical server should have two different ip-address configured. This means that the server should have two ethernet cards, each one of them configured to the ip-address of the corresponding website that Apache virtual host

parse_url - Manual, This function parses a URL and returns an associative array containing any of the various Example #2 A parse_url() example with missing scheme. <?php Using the ServerPath directive. We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correct Host: header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the client tried to reach (and serves the request from the primary vhost).

Comments
  • this is interesting to me... i actually prefer "complex" domain names myself ;-) Anyhow what is your expected startegy for accessing th individual apps in each project - is it backend.domain.com/project or is it more like domain.com/project/backend.php? That will make a difference in how you go about it i think.
  • the idea is to access the backend app via domain.com/project/backend/