I would like to run multiple sites from one FuelPHP installation. The main driver behind this is the ability to share models and database configuration.
I’ve seen a couple of suggestions requiring changes to the FuelPHP directory structure, or through the use of modules.
-
I don’t really want to mess with the directory structure.
-
I don’t think I completely understand how modules can help me, but I think the resulting configuration would be more complex than I need.
The solution I’ve come up with involves a simple change to the .htaccess file located in /public. Whereby I modify the rewrite rule based on the host name. Each site’s controllers and views sit in subdirectories of the main structure.
Original .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Multiple site .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} main.loc
RewriteRule ^(.*)$ index.php/main/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} admin.loc
RewriteRule ^(.*)$ index.php/admin/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} api.loc
RewriteRule ^(.*)$ index.php/api/$1 [L]
</IfModule>
My question is, is this a viable solution? Do you foresee any pitfalls that I might encounter down the line?
My working solution has been to create three FuelPHP applications side by side, then symlink key directories like core, some packages and obviously the model directory.
One gotcha was that my FTP client ignored the symlinks, so I had to recreate them on the staging server. This will not be an issue when I finally get around to automating deployment using SSH.