Hacking Symfony Application in A Shared Hosting

In a shared hosting environment, you may not have a full access to the server. Everything has already been installed. But a least they provide a secure shell (SSH).

I have successfully deploy a syfmony 1.2 application in a shared hosting, surely with a hacking.

PDO Hack

Symfony 1.2 at least need PHP 5.2.4 and above. So if your PHP version is 5.2.0 and you’re using MySQL database, make sure to activate PDO::MYSQL_ATTR_USE_BUFFERED_QUERY for buffered MYSQL Api.

Edit your databases.yml:

      classname:  DebugPDO

    class:        sfPropelDatabase
      dsn:        mysql:dbname=your_db;host=localhost
      username:   root
      password:   your_password
      encoding:   utf8
      persistent: true
      pooling:    true
      classname:  PropelPDO
        MYSQL_ATTR_USE_BUFFERED_QUERY:  {value: on}

Symfony CLI Hack

Usually, we can customize the php.ini file for web server, but not for the PHP CLI. Unfortunately, the PDO extension for PHP CLI is not enabled by default. As in shared hosting environment, there are no write access to system configuration.

Try this:

$ php -i | grep PDO

If you got an output telling about PDO extensions has been enabled then, you don’t need this hack.

First, we can create our own php.ini file to be passed to the PHP CLI, and put in a writable directory, for example in the home directory:

# ~/php.ini

Wrap the symfony command to make sure PHP CLI is using our custom php.ini, create the script and name it symfony.sh. Put in home directory for ease the access:

# ~/symfony.sh
cd /path/to/myproject
php -c ~/php.ini -f symfony -- $*

Make sure the script is executable:

$ chmod u+x ~/symfony.sh

Now you can launch the symfony CLI from within your home directory by issuing:

$ ./symfony.sh [command]

, , , , ,

  1. #1 by customhosting on March 10, 2009 - 11:22 pm

    Really informative!!

  2. #2 by dev_hinvi on May 5, 2009 - 11:30 am

    You are awesome.. I had the same problem, and spent considerable time explaining the requirement to the web-hosting people…who still dont get it 😦 … your hack works perfectly .. probably might want to increase the memory limit from 64M to something higher though. phing quickly uses up all the memory and ends with a memory exhausted option .. Thanks a ton. …

  3. #3 by Alex on December 7, 2009 - 12:57 pm

    Hackers are more intelligent than developers, it would be more secure to use Dedicated application hosting service like one provided by Onthenetoffice.

  4. #4 by djiebrats on January 9, 2010 - 2:51 pm

    apakah itu bisa digunakan di semua share hosting??apakah yang penting ada akses ssh ke server??

    • #5 by tohenk on January 9, 2010 - 2:57 pm

      Ya, harus ada akses SSH.

  5. #6 by Bas on April 7, 2011 - 4:57 pm



    instead of above mentioned {value: on} worked much better for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: