Article

Installing and configuring Symfony2

Getting a Symfony2 project up and running is fairly easy but I did come across a few bumps in the road when I first attempted it so I am hoping to smooth those bumps out a bit for some of you first timers.  The basic process is:-

Step 1 - Create a project directory

Make a folder on your web server for your Symfony2 project.  I will assume we are using /home/chrisshennan/public_html/symfony2.chris.home.internal/ as our root directory for this tutorial.

Step 2 - Download & Extract the Symfony2 project files

Download the Symfony2 Standard Edition without vendors and extract into the your Symfony2 project folder.  When extracting the Symfony2 project it will create a folder called "Symfony".  Move the contents from "Symfony" into the root directory and delete the "Symfony" folder.   You should now have the main project folders located :-

apps = /home/chrisshennan/public_html/symfony2.chris.home.internal/apps

bin = /home/chrisshennan/public_html/symfony2.chris.home.internal/bin

src = /home/chrisshennan/public_html/symfony2.chris.home.internal/src

etc etc

 

Step 3 - Install the vendor libraries

To install the vendor libraries, open a command prompt, change directory to your Symfony2 project directory run the following command below:-

php bin/vendors install

At the time of writing, the above command seemed to intermittently produce errors like the one below

Cloning into /home/chrisshennan/public_html/symfony2.chris.home.internal/vendor/symfony... error: The requested URL returned error: 403 while accessing https://github.com/symfony/symfony.git/info/refs fatal: HTTP request failed

This is easily fixed by editing the deps file in a text editor and doing a search and replace and replacing all instances for "https://" with "git://".  Once this has been done then re-run the command above and it should install the vendor bundles properly.  There is quite a lot of data to download and install so this could take several minutes to complete.

Tada

And that is basically it.  If you have configured your web server to run the Symfony project via https://localhost/web then you should be able to go there now and see:-

symfony2_demo_page.jpg

You can now configure some additional options (like database connection) via the configuration wizard which can be found at https://localhost/web/config.html? The solution I use works in 2 parts:-

  • Set up a local hosts configuration value to resolve symfony2.chris.home.internal to 192.168.0.250
  • Set up a apache vhost of your web server so that it can deal with requests to symfony2.chris.home.internal

Local Hosts Configuration Value

  • If your local machine is running Windows then edit C:\Windows\System32\drivers\etc\hosts
  • If your local machine is Linux or Mac then edit /etc/hosts

In both cases add the following line to the end of the file

192.168.0.250        symfony2.chris.home.internal

Apache vhost Configuration

Next we need to add a vhost configuration for symfony2.chris.home.internal on our web server and I have included an example of this below.  If you need more information on setting up a vhost configuration on your web server then you should have a read of Apache Virtual Hosts on Ubuntu - Part 1.  This will be slightly biased towards Ubuntu configuration but the general configuration is covered well here.

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /home/chrisshennan/public_html/symfony2.chris.home.internal/web
    ServerName symfony2.chris.home.internal<code>

    # Custom log file
    Loglevel warn
    ErrorLog /home/chrisshennan/wwwlogs/symfony2.chris.home.internal-error.log
    CustomLog /home/chrisshennan/wwwlogs/symfony2.chris.home.internal-access.log combined

    <Directory /home/chrisshennan/public_html/symfony2.chris.home.internal/web>
        AllowOverride None

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.html"language-bash">
RewriteRule ^(.*)$ app.html"language-bash">
RewriteRule ^(.*)$ app_dev.html"language-php">
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
    '127.0.0.1',
    '::1',
))) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

to

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1','::1',)) && substr($_SERVER['HTTP_HOST'], -14) != '.home.internal' ) {

    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

And that should be you.  By this point you should be able to:-

  • Install Symfony2 and the vendor libraries
  • Set up a hostname to allow access to your Symfony2 site from a remote web server (or localhost if desired)
  • Set up the development environment as the default environment

I hope this was helpful and I look forward to seeing your comments.

me.jpeg

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Chris's Reading List

Medium

Medium

How a single change boosted organic traffic by 40%

How a single change boosted organic traffic by 40%

The SEO world can sometimes be a confusing maze of contradictions. Read more

verraes.net

verraes.net

Sensible Interfaces

Sensible Interfaces

How did we get from 'Program to an interface, not to an implementation' to 'Just slap an interface on there, it's the fashionable thing to do'? Read more

Moz

Moz

The Linkbait Bump: How Viral Content Creates Long-Term Lift in Organic Traffic - Whiteboard Friday

The Linkbait Bump: How Viral Content Creates Long-Term Lift in Organic Traffic - Whiteboard Friday

A fantastic piece of content can lift your traffic curves to a "new normal." In today's Whiteboard Friday, Rand talks about exactly how that happens, and how you can create content that has that effect. Read more

Loige

Loige

6 Rules of thumb to build blazing fast web applications (server side)

6 Rules of thumb to build blazing fast web applications (server side)

In this post are described 6 extremely important rules you should take under consideration when writing your next web application Read more

SitePoint

SitePoint

Console Wars - PHP CLI Libraries

Console Wars - PHP CLI Libraries

Nicola Pietroluongo compares three popular PHP console libraries, building the same functionality in each. Wondering which one is right for you? Find out! Read more

TechCrunch

TechCrunch

Servers.com Brings Its Bare-Metal Servers To The US

Servers.com Brings Its Bare-Metal Servers To The US

Servers.com, a hosting company with a focus on dedicated bare-metal servers that launched in Europe in 2005, today announced the opening of its first U.S... Read more

Advertisement

Digital Ocean