Bringing Up Symfony Application into Linux Shared Hosting

Our application development has been finished, now the time we put the application alive on the web. On shared hosting, directory structure for a html files has already been specified according to the server.

First step, is to figure out what it looks like and where to put html files. Below is a sample:

root/                         <- your hosting root
      www/                    <- this is where html files reside,
                                 it can also be html instead www

As we know, the only published part of symfony application is the web folder. So be prepared to put the symfony library and our application files into a folder. You can put the files in home folder for example, or in the public folder (see structure). Lets assume we are using the public folder. The directory structure should looks like:

root/                         <- your hosting root
    myproject/                <- here are our application files
    symfony/                  <- the symfony library
      www/                    <- this is where html files reside,
                                 it can also be html instead www

Before transferring all those files, make sure your project config file include the symfony library using relative path.

Symfony 1.0 (myproject/config/config.php):


// symfony directories
$sf_symfony_lib_dir  = realpath(dirname(__FILE__).'/../../symfony/lib');
$sf_symfony_data_dir = realpath(dirname(__FILE__).'/../../symfony/data');

Symfony 1.1 and up (myproject/config/ProjectConfiguration.class.php):


require_once dirname(__FILE__).'/../../symfony/lib/autoload/sfCoreAutoload.class.php';

class ProjectConfiguration extends sfProjectConfiguration
  public function setup()
    // ...

Transfer all files to those folder using either ftp client, rsync (which I am prefer) , or using your Hosting Control Panel. For Windows users, you can try using CwRsync which already include a ssh client.

The visible files for symfony application are:

  • index.php, production front controller.
  • .htaccess, for url rewriting and others apache stuffs.
  • images, the images folder.
  • css, the stylesheets folder.
  • js, the javascripts folder.
  • sf, the symfony assets folder.
  • uploads, the uploads folder.
  • Plus the plugin assets.

So now you can open a remote shell to symlink all those files and directory to be published under the web using a ssh client. Most of web server hosting already include a secure shell server, but you can check if it's already enabled in your Control Panel. As an alternative client, you can use putty either. Here are the sample command to be issued:

> ssh

$ cd /path/to/sites/
$ ln -s /path/to/public/myproject/web/index.php index.php
$ ln -s /path/to/public/myproject/web/.htaccess .htaccess
$ ln -s /path/to/public/myproject/web/images images
$ ln -s /path/to/public/myproject/web/css css
$ ln -s /path/to/public/myproject/web/js js
$ ln -s /path/to/public/myproject/web/uploads uploads
$ ln -s /path/to/public/myproject/web/sfPlugin sfPlugin <- the plugin assets
$ ln -s /path/to/public/symfony/data/web/sf sf

Repeat the command for all others files needed by your application, for example, plugins assets. Then, let's continue by fixing the file permission.

$ cd /path/to/public/myproject
$ chmod u+x symfony                    <- make symfony executable
$ ./symfony fix-perms                  <- symfony 1.0
$ ./symfony project:permissions        <- symfony 1.1 and up

Some times, we also must fix the permission for the front controller, 0755 is satisfied.

$ chmod 0755 index.php
$ chmod 0755 .htacess

You're done, try browsing your server.

Most of shared web hosting will redirect error log to stdout neither to a log file, so the error will be visible to the user. To avoid this, you need to comment the error_log() method call in symfony/lib/exception/sfException.class.php and symfony/lib/exception/sfError404Exception.class.php (symfony 1.1 and up).

Next time if you update your application, just transfer the changes (which handled by rsync), fix the permissions, and no need to do symlink again.


  1. thanks pak tutorialnya..
    tapi ada satu pertanyaan :

    klo saya memakai .htaccess kok ada error :

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    trus klo .htaccess tidak saya pakai dia tidak error, hanya saja input data tertentu. ada error. misalkan saya mau menjalankan contact us di frontend.
    error sebagai berikut. :

    The requested URL /contact/contactus was not found on this server.”

    klo saya lihat url : “index.php” jadi hilang, waktu menjalankan action post.
    bagaimana solusinya pak ?

    thank’s – matur suwun 🙂

  2. udah saya comment, tapi waktu akses url tanpa “index.php” error :
    The requested URL /contact/contactus was not found on this server.

    what’s wrong ?

    • Url lainnya bisa nggak? Error tersebut kemungkinan karena web server tidak meredirect request ke front controller symfony. Coba cek log file apache!

  3. Do you know of anyway with htaccess to disable someone from using your domain to point to their own website on the same server? Ex: they use to promote their PHISHING WEBSITE.COM by using this simple URL to send users : YOURDOMAIN.COM/~phishing/file.html

    Any help would be greatly appreciated. Thanks

Leave a Reply