how to deploy symfony application to the production server

taking off of the airplane

Deploy Symfony application to production – setting it live

This is a continuation of deploying symfony application to the server part one

Deploy Symfony application to production part two
4. Installing composer dependencies

Be in your symfony app first

cd /apps/symfony-app

The run the installer here

composer install --no-dev --optimize-autoloader

Under most circumstances, this will run without any problem. If there are any problems, composer will log them for you so follow those and solve those. And this will create a vendor folder in the folder you run composer.

5. Permissions for web folder and files under it

The web folder in the symfony app is the one facing public and greater care has to be given on the permission for it. The rule of thumb when you deploy symfony is:
Allow the owner, which would be www-data, to do anything on the folder
All others, group and users to read and execute but not write on the folders
And for all files, we would make 644 => owner can read and write, others can read only

chmod 755 web/folder1
chmod 644 web/file1

This might create a bit of problem when you are working from FTP clients.
But you can loosen a bit while you are working for a brief moment and return it back after you are done. But, the most good method would be creating ssh and log through that.

6. Handling cache and log folders

These are special folders that would require a bit different handling

chmod -R 755 app/cache
chmod -R 755 app/logs

7. Warm up your cache and consolidate your css and JS files

For cleaning and warming the cache:

app/console cache:clean --env=prod --no-debug

And for the css and JS files

php app/console assetic:dump --env=prod --no-debug

** Note, if you are using symfony3, the app folder might not be there and you would find bin folder rather

8. Getting rid of app.php using httaccess file

First thing first, check if mod_rewrite is enabled by doing this simple check on the command line

apache2ctl -M | grep rewrite

Or the most easiest would be to throw one php file with phpinfo() in it and look for rewrite in the page.

if it is not loaded simply run this

sudo a2enmode rewrite
sudo service apache2 restart

And have the following content in the /apps/symfony-app/.htaccess

        Options FollowSymlinks MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.php [QSA,L]

**If the above is not working, check for /etc/apache2/apache.conf or in the /etc/apache2/sites-enabled and look for the configuration of your web root and make sure the AllowOverride is set to All

Finally: Making web folder public accessible

We are on the final step. Now, we need to make the contents of the web file to be accessible for the public. Assuming your public facing folder is in /var/www/html – symlink the folder web to this folder:

cd /var/www/html
sudo ln -s /apps/symfony-app/web/* .

The above steps would prepare your symfony app for the final production release. The rest would be pointing your domain name to your server like adding A-records and the like if you have to go through that.

fos user bundle security validation

$_POST vs $HTTP_RAW_POST_DATA vs php://input and enctype

Deploying Symfony on Production Server

Run single phpunit test

composer install-update killed on vagrant machine

Check if curl is loaded as module in php

One Comment
  1. lords mobile hack android

    Thanks for the excellent info, it really is useful.

Leave a Reply

Your email address will not be published. Required fields are marked *