Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony multiple sites

Tags:

php

symfony

I have a Symfony2 core, which is used for domain A and domain B. But, if I update the core, I need to update two times, because I don't know how to configure only one core, with multiple domains with theirs configs/databases.

Suggestions?

like image 733
Gabriel Santos Avatar asked Aug 06 '12 17:08

Gabriel Santos


2 Answers

Make a copy of the "web" directory into the "public_html" folder on each domain (assuming you are running Apache on Linux)

This "web" directory contains the front controllers of your site (app.php and app_dev.php), locate them and edit them on your favorite text editor. Locate this lines:

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

and change the route to the actual relative path where your core is located. It could be something like this:

require_once __DIR__.'/../the_core_is_here/app/bootstrap.php.cache';
require_once __DIR__.'/../the_core_is_here/app/AppKernel.php';

This is flexible, and can be organized as you like, but make sure this two lines have the correct path

Keep in mind that all the assets (JS, CSS, images ...) you include into your HTML are relative to the front controller location, so you will need to link them using the full url of the domain name where they reside or copy them also to the B domain or use assetic

At the end you will have something like:

/
.. home
.. .. DOMAINA
.. .. .. public_html
.. .. .. .. app.php
.. .. .. .. img
.. .. .. .. .. image.png
.. .. DOMAINB
.. .. .. public_html
.. .. .. .. app.php
.. .. .. .. img
.. .. .. .. .. image.png
.. .. the_core_is_here
.. .. .. app
.. .. .. src
.. .. .. bin
.. .. .. vendor

Now you should have 2 entry points for your application. You can even put different CSS and images on each to give them different aspect.

like image 150
ButterDog Avatar answered Nov 05 '22 11:11

ButterDog


Perhaps you could try using Capifony, it's a deployment script written in ruby for Symfony application. I haven't done any setup like what you are trying to achieve, but I use it to deploy both staging & production servers. It can be setup to deploy different instances of the application to one server (eg: different directories), or multiple servers.

Once they are correctly setup, deploying is just a matter of typing:

cap server1 deploy
cap server2 deploy

Everytime you run the command, capifony will pull the latest code from the repository (eg: git), and deploy it. As a bonus, old versions of the application are also saved on the server should you need to return to previous state.

Here is the sample capifony configuration script just to give you an overview:

# deploy.rb
set   :application,   "My App"
set   :deploy_to,     "/var/www/my-app.com"
set   :domain,        "my-app.com"

set   :scm,           :git
set   :repository,    "ssh-gitrepo-domain.com:/path/to/repo.git"

role  :web,           domain
role  :app,           domain
role  :db,            domain, :primary => true

set   :use_sudo,      false
set   :keep_releases, 3

And you can have different configuration scripts, each for a different domain, using the multistage extension for capifony.

like image 25
dezull Avatar answered Nov 05 '22 10:11

dezull