Setting the web server to gain access to symfony_data/web/sf/ directory
Krzysztof Karolczak | Monday December 8th, 2008The happiness of running the first Symfony project is very often spoiled by a message displayed on the first Symfony-based web page:
Congratulations! You have successfully created your symfony project.
Project setup successful
This project uses the symfony libraries. If you see no image in this page, you may need to configure your web server so that it gains access to the symfony_data/web/sf/ directory.
The proper configuration of the web server seems to be the most troublesome part of Symfony installation. But fortunately there are several quick ways to solve that problem. This short guide will describe three of them from the perspective of an Apache web server user.
I’m assuming that you have Symfony already properly installed (if not – the installation guide is here). I’m working on a WAMP installation of Apache+MySQL+PHP, so the directory paths in my examples will reflect that (but the guide should work for any Apache based configuration).
Method 1 – setting a virtual host
This is the most recommended method of setting up your working environment (in fact it is the only real method out there – the other described below are just workarounds ) – you should always create a virtual host for every application. This guide will teach you how to configure your web server to cope with one project (a multi-application vhost example is coming up soon
).
First – find your apache config directory (in my WAMP install it’s C:\wamp\bin\apache\apache2.2.6\conf\) and open the httpd-vhosts.conf (which is in the sub-directory extra – C:\wamp\bin\apache\apache2.2.6\conf\extra). Delete or comment out all the lines (by adding ‘#’ at the beginning of each one) if you’re not sure what they do (if you haven’t written them they are probably just examples of vhost configuration).
In Symfony 1.2 (1.1 also?) a sample vhost config file is created automatically for every project you generate. It can be found in config/vhost.sample – feel free to copy/paste that code instead of the below example.
Now add at the end of the file your virtual host config which should look similar to this (it’s just one of possible ways of configuring a vhost – you may find other configurations that achieve the same thing but look different – they all are correct as long as they work, right?
):
NameVirtualHost *:80
Listen 127.0.0.2:80
<VirtualHost 127.0.0.2:80>
ServerName your_application_name
DocumentRoot “c:\wamp\www\your_project\web”
DirectoryIndex index.php
<Directory “c:\wamp\www\your_project\web”>
AllowOverride All
Allow from All
</Directory>
Alias /sf “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf”
<Directory “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf”>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
In lines ‘ Alias /sf “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf” ‘ and ‘ <Directory “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf”> ‘ replace my path with the path to your symfony/web/sf dir. And do the same with lines ‘ DocumentRoot “c:\wamp\www\your_project\web” ‘ and ‘ <Directory “c:\wamp\www\your_project\web”> ‘ changing the path to one that points to the web directory in your project.
And you should also specify the name of your virtual server by modifying ‘your_application_name’ in the ‘ServerName your_application_name’ line.
Make sure that in the httpd.conf file (main Apache config file located in a directory like C:\wamp\bin\apache\apache2.2.6\conf) the line ‘Include conf/extra/httpd-vhosts.conf‘ is uncommented (no ‘#’ before it).
Now we need to declare our own domain locally, by adding a line like ‘127.0.0.2 your_application_name’ to the host file (located in C:\WINDOWS\system32\drivers\etc). Just make sure that you add your line after ‘127.0.0.1 localhost‘ (which should be in fact the first line). You may also need admin privileges to modify that file.
Now – after an Apache restart – if you type in your browser http://your_application_name/ your Symfony welcoming page should have all the graphics displayed correctly.
Method 2 – project freezing
You can obtain a ready-to-deploy package from your Symfony project by using the freeze command. If you execute in the root of your project:
symfony freeze [c:/path/to/your/symfony/data/dir]
All Symfony core files will be copied to the current project, including the ones that where missing in the web/sf directory. The freeze command also changes some paths in your project configuration so it will now address the Symfony libraries that were also copied to your project not the global ones. The main drawback is that if you want to upgrade Symfony you’ll have to unfreeze (command opposite to freeze) and freeze again all your projects or copy/overwrite files manually. And there may be some path issues if your project is not in the web root of your web server directory.
Method 3 – the stupid way
If the above methods are not working for you – just go ahead and copy the symfony_data_path/web/sf/ directory to your_project_path/web/ (so in my case that would be copying C:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf to the C:\wamp\www\your_project\web directory). As before the downside of this workaround is that after updating Symfony you will have to manually recopy that folder again to all your projects and there probably will be some path issues when accessing plugin assets or when using absolute paths in links (but you probably won’t even notice if you’ll always use symfony helpers for handling your links).






Oh, thank you. I had to resort to Method 2 (the
Mark | Wednesday October 8th, 2008Oh, thank you.
I had to resort to Method 2 (the stupid way) but it did work.
I am a Mac convert (from Windows) since summer, 2007. When I initially set up my machine and struggled to get MySQL and PHP and PEAR working, my document root was set in a different folder from the default ‘Sites’ (don’t ask me how). AND, I do a number of prototypes, none prior to the latest are Symfony-based, each of which lives in a different folder. So changing httpd.conf to look at virtual hosts broke other things.
Someday I hope to get back to the standard OSX folder configuration for localhost, but thanks to your help I am running today!
mark
Thank you for the 15 minute guide to install Symfony
D. Zook | Thursday November 6th, 2008Thank you for the 15 minute guide to install Symfony on a WAMP platform. It worked great. I am using PHP 5.2.6 and had the data access error described on this page. Method one did not work for me. I followed the directions exactly but did not quite understand the process so there was probably something I typed incorrectly.
The stupid way worked fine though.
Thanks for the help.
As every body thanks for this HUGE help! and as
Mary | Wednesday December 10th, 2008As every body thanks for this HUGE help! and as D. Zook i’m using PHP 5.2.6 and first method not work for me either. thanks you add the stupid way that works perfect!
thanks over and over again
[...] See my guide on configuring apache to work hand
Install Symfony - Windows XP / Vista + WAMP | Poetry of Programming | Monday December 22nd, 2008[...] See my guide on configuring apache to work hand in hand with your Symfony aplications. [...]
I could not find the /data directory. So I am
rajen | Monday December 29th, 2008I could not find the /data directory. So I am unable to follow any of the above tips.
I am using wampserver V 2.0 having php 5.2.8 and symfony 1.2.1
if this images displaying won’t harm the project I will better leave this ..
please help me out..
thank you.
I copied web folder from sf_sandbox and kept in the
rajen | Thursday January 1st, 2009I copied web folder from sf_sandbox and kept in the the new project …
so the images is seen now..
thank you every one…
Now i am trying to find the way how to do coding…. like hello word
…
Thanks for this great tip. A few advices for those like
ghismo | Friday March 13th, 2009Thanks for this great tip.
A few advices for those like me who would have made a copy-paste of your code : take care of the quotes (replace “ and ” by “).
If you are under Vista, and you want to edit your host file, follow this extra steps :
http://www.mvps.org/winhelp2002/hostsvista.htm
Thank you! I was able to get this going well
Elmer Thomas | Tuesday October 6th, 2009Thank you! I was able to get this going well using method 3 in Mac OSX.
Except I used a symbolic link like so:
ln -s [path_to_sf_subdirectory] ./
from within my projects “web” sub-directory.
Cheers!
Thanks for this nice guide! Unfortunatly I also have problems to
martin | Thursday October 8th, 2009Thanks for this nice guide!
Unfortunatly I also have problems to locate this path on my installation:
c:\wamp\bin\php\php5.2.8\PEAR\data\symfony\web\sf”
I find: C:\wamp\bin\php\php5.2.8\PEAR\symfony, not /data as a subfolder in PEAR dir.
I have wamp 2.0 – php 5.2.8 with PEAR installed. I can see the welcome page on project without any images/graphics.
When I search my C: I can`t find any directory with symfony\web\sf , neither can I find the picture src=”/sf/sf_default/images/sfTLogo.png” that should show up in welcome page.
What to do??
ok, I got it. I found the path in: c:\wamp\bin\php\php5.2.8\data\symfony\web\sf I got
martin | Thursday October 8th, 2009ok, I got it.
I found the path in: c:\wamp\bin\php\php5.2.8\data\symfony\web\sf
I got problems when I pasted you above lines in httpd-vhosts.conf. Wamp made a yellow symbol so something had to be wrong.
After removeing Listen 127.0.0.2:80 it works like a charm. Dunno why
I have dir in Alias /sf “C:\php5\pear\data\symfony\web\sf” this work and not forget
bolec | Saturday October 10th, 2009I have dir in
Alias /sf “C:\php5\pear\data\symfony\web\sf”
this work and not forget restart apache
I hope this helps someone. I was having the same
ce | Monday November 23rd, 2009I hope this helps someone.
I was having the same problem. At first I could not find the “data\symfony\web\sf”. Then after banging my head against the wall I noticed that the installation had added a NEW directory on C:\php5. Inside this directory you will find the “sf” directory.
I had installed WAMP on C drive. c:wamp
after installing symfony through PEAR it had installed another copy of its own php5 on c:php5 which I was not aware(It never asked me at least I don’t remember). As a result I could not find the “sf” directory. I was looking in the PATH C:\wamp\bin\php\php5.3.0 in which you will never find if you installed the way I did (i followed the installation on this site).
Then opened the httpd.conf file ( C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf )
and appended this code:
AllowOverride All
Allow from All
ServerName myproject.localhost
DocumentRoot “C:\wamp\www\myproject\web”
DirectoryIndex index.php
Alias /sf C:\php5\pear\data\symfony\web\sf
AllowOverride All
Allow from All
Must restart apache.
if everything goes well it should work.
Thanks for this help. I post this comment, because after I
jibux | Sunday February 14th, 2010Thanks for this help.
I post this comment, because after I used your copy method, I found another way.
With my wamp 2.0, it’s easy to add an alias with pop-up menu for apache.
For jobeet tutorial you have to add some information in it.
This is my alias file
Alias /jobeet/sf “C:\dev\sfproject\jobeet\lib\vendor\data\web\sf”
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Alias /jobeet “C:\dev\sfproject\jobeet\web”
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Thanks for this help. I post this comment, because after I
jibux | Sunday February 14th, 2010Thanks for this help.
I post this comment, because after I used your copy method, I found another way.
With my wamp 2.0, it’s easy to add an alias with pop-up menu for apache.
For jobeet tutorial you have to add some information in it.
This is my alias file
Alias /jobeet/sf "C:\dev\sfproject\jobeet\lib\vendor\data\web\sf"
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Alias /jobeet "C:\dev\sfproject\jobeet\web"
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all