Check if your symfony application is ready for deployment

Remove .htaccess when possible
  • performance

The .htaccess file is very usefull: it's flexible, it works everywhere and the modifications are processed instantaneously.

But the drawback is that the rules written in it can't be cached by apache, the server has to scan the file for every single request.

If you move the .htaccess rules to your virtual host configuration file, the rules will be cached and apache performance will improve.

Unfortunately, you can't access to the apache configuration files on shared hosts, that's why symfony uses the .htaccess file by default.
So sorry, this tip only works for dedicated server users.

Open your virtual host configuration file

Most often, you'll find the virtual host configurations in the bottom of the httpd.conf, but sometimes, they are moved in some vhosts.conf file.

Your virtual host should look like to something like this:

<VirtualHost *:80>
  DirectoryIndex index.php
  DocumentRoot "/path-to-your-sf-project/web"
  <Directory "/path-to-your-sf-project/web">
    AllowOverride All
    Allow from All
  Alias /sf /path-to-your-sf-project/lib/vendor/symfony/data/web/sf/
  <Directory "/path-to-your-sf-project/lib/vendor/symfony/data/web/sf/">
    AllowOverride All
    Allow from All

You need to add your rules to <Directory "/path-to-your-sf-project/web"> :

<Directory "/path-to-your-sf-project/web">
  AllowOverride None
  Allow from All
  Options FollowSymLinks ExecCGI

  RewriteEngine On

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /

  # we skip all files with .something
  #RewriteCond %{REQUEST_URI} \..+$
  #RewriteCond %{REQUEST_URI} !\.html$
  #RewriteRule .* - [L]

  # 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 ^(.*)$ index.php [QSA,L]

Remove the my_project/web/.htaccess file

Unless you added extra rules in it, the file is now useless. If you don't remove the htaccess, apache will still parse the file on every request

Test the modifications and restart Apache

Apache provides the configtest tool to check that apache configuration files are ok.

On many linux servers, you can access to apache commands by /etc/init.d/apachectl makeMeSandwich.
Rights errors just need the sudo prefix to be fixed: sudo /etc/init.d/apachectl makeMeSandwich

/etc/init.d/apachectl apachectl configtest

If there's no error:

/etc/init.d/apachectl apachectl restart

Document this in a README file

Your project really should have at least one README file where this kind of modifications are reported.

This tip was given by Jérôme Macias on the symfony-check thread.