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.
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.
1 | sudo 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.
1 | sudo pear channel-discover pear.symfony-project.com |
2 | sudo 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.
4 | symfony generate:project myproject |
5 | symfony 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 >”
2 | ln -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
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.
1 | sudo vi /etc/apache2/sites-enabled/000-default |
and just add
03 | Options Indexes FollowSymLinks MultiViews |
09 | Alias /myproject "/var/www/myproject/web" #<-- Add this |
11 | ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ |
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!
Now was that easy or what?!?
Stay tuned for more Symfony joy.