Need help?

I'm available for remote short term contracting or consultancy work. Please check out my LinkedIn profile for more details on my experience.

Please feel free to use the form below to contact me.

Symfony on CPanel (Shared hosting)

In this tutorial, I'm going to go through the process of setting up a Symfony project on a shared host (CPanel). I was unfortunately faced with this same problem, but was lucky enough to find the answers (after quite a bit of searching), so I thought an article would be in order. This article will also assume that you already have a database setup, with data in it.

Before we get started, you can find most of these steps on the Symfony site -

You can download the Symfony library files here:

Once you have those, lets unzip and move them to a central location - for this tutorial, I'm going to be putting them in '~/www/libs/Symfony/', but you can change that to whatever you want.

Now that we got all that out of the way, lets get started with the project.

First thing we'll need to do is create the project directory - for this example, I'm going to put my project in this directory: ~/symfony_projects/myproject/

Now, from the project home directory (~/symfony_projects/myproject/), lets run this:

php ~/www/libs/Symfony/data/bin/symfony generate:project myproject

This should of now created all your project directories and generated config files. The next step is to check that the Symfony library path is correct in 'config/ProjectConfiguration.class.php' - if you're happy with that then we can move along. It should be pointing to '~/www/libs/Symfony/', but it will most likely be using the full path, which is fine.

Lets move back into the main project directory (you should already be there), and configure the database:

php symfony configure:database "mysql:host=localhost;dbname=database_name" username password

We're now ready to generate our app, which will house all the modules.

php symfony generate:app frontend

Alright, we're moving right along now - if you haven't gotten any errors, then you're doing it all right. The next thing we'll need to do is change the permission on the cache and log directories - lets change it to '777', so it's accessible by anyone.

chmod 777 cache/ log/ 

Now we're going to move on to the database model setup. The next command will generate a schema file, which will be built based on your database that you specified earlier. Symfony will use this file to generate the models and any other database related stuff - this is using an ORM library called Doctrine. You can read more about Doctrine here:

php symfony doctrine:build-schema

Alright, now that our schema is built, lets build the rest of the stuff using doctrine, from within the project directory:

php symfony doctrine:drop-db   (deletes db and all records with it)
php symfony doctrine:build-db   (re-creates db)
php symfony doctrine:build-model
php symfony doctrine:build-forms
php symfony doctrine:build-filters
php symfony doctrine:build-sql
php symfony doctrine:insert-sql

Alternatively, you can run all the doctrine commands I just spoke of with one command (but this will also run the first 2, which I mentioned would wipe your data). Do not run this if you want to keep your database records - this will wipe them ALL and recreate your tables (empty tables!).

php symfony doctrine:build --all --no-confirmation

Okay, this is where this tutorial is going to differ a bit from the official one by Symfony - we won't be modifying the httpd.conf, like they said you should. We're assuming that you are setting this up on a shared host, so therefore you probably won't have access to much. Lets assume that your web root directory is ~/public_html and under that you have a bunch of virtual hosts for each website under your account (ie. ~/public_html/ and ~/public_html/ For this we're going to assume that you want ~/public_html/ to be used for your Symfony project.

To do this, we're going to create symbolic links, which will be created within ~/public_html/ and point to ~/symfony_projects/myproject/ (the first symbolic link is only needed if you want to display the default page properly):

ln -sf ~/public_html/libs/Symfony/data/web/sf ~/symfony_projects/myproject/web/sf
ln -sf ~/symfony_projects/myproject/web/* ~/public_html/ 

There is just one last thing we need to do before this works properly - unfortunately I noticed that when creating the symbolic links, it doesn't create one for the .htaccess file, so we'll need to copy that from ~/symfony_projects/myproject/web/ to ~/public_html/

cp ~/symfony_projects/myproject/web/.htaccess ~/public_html/

That's it, it's pretty much all setup now. The last little part now is to create our first module. For this I'm using a table of mine called TblBlog and calling the module 'blog', which will be put under the app 'frontend'.

php symfony doctrine:generate-module --with-show --non-verbose-templates frontend blog TblBlog

Alright, you should now have a working Symfony project, and should be accessible from and

jon | February 04, 2011 | Comments (0)


Name (required)
Email (will not be published) (required)