2010/09/06

Installing & configuring Symfony Framework in Ubuntu

symfony
Recently I switched my main PHP framework to learn another, Symfony. I am running a Ubuntu server and recently upgraded to the new distribution and was looking into how to set up the Symfony framework. If you are a beginner then the sandbox_sf file will do, but if you are looking to set it up for more than one page below will show how to install and set it up so all websites will use it.
ubuntustraplogo
Before starting you will need to install Apache2, PHP5, and MySQL. In Ubuntu that is an easy task completed by the following command that will pretty much cover all the required packages.
1sudo apt-get install phpmyadmin php-pear
This will handle the php, apache and all the modules as well as MySQL :) So now lets get started with Symfony. Below you will setup the channel where you are going to download Symfony using pear PHP module.

1sudo pear channel-discover pear.symfony-project.com
2sudo pear install symfony/symfony-1.2.7
That is it! You have symfony installed on your system for use. Now lets setup a simple project for personal use. The project name I will use is “myproject”, you can use any name that you prefer.
I will move to the directory which is the document root for apache, create my project directory, initialize a new project with symfony and create a new front end.

1cd /var/www
2mkdir myproject
3cd myproject
4symfony generate:project myproject
5symfony generate:app frontend
Next we have to create a symlink that will allow the new project that we just created to use the Symfony libraries and elements installed earlier. With us still within the “/var/www/< project name >”

1cd web/
2ln -s /usr/share/php/data/symfony/web/sf/
Now you can visit your site to see how everything looks:
http://< ip address >/myproject/web/
If you get the image below
congratulations
the installation was successful, you can now create an alias that will allow you to view the project without having to go to the “web/” directory. For that we will need to add a new alias within the sites-enabled folder for apache. I only have one site on my computer so my file is named “000-Default”, yours might be something totally different.

1sudo vi /etc/apache2/sites-enabled/000-default
and just add

01......
02 <Directory /var/www/>
03                Options Indexes FollowSymLinks MultiViews
04                AllowOverride None
05                Order allow,deny
06                allow from all
07        </Directory>
08
09        Alias /myproject "/var/www/myproject/web"  #<-- Add this
10
11        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
12.......
Save, quit and restart Apache. Now all you have to do is go to your address http://< ip address >/myproject and see the image above and you are DONE! :D Now was that easy or what?!? :)
Stay tuned for more Symfony joy.

1 comment:

  1. Их таалагдаж байна бас асуух зүйл байна

    ReplyDelete

Миний бичсэн бичлэг танд өчүүхэн ч болтугай хэрэг болсон бол сэтгэгдлээ бичиж үлдээхийг хүсье. Баярлалаа :)