Poetry of Programming

Because coding is art
  • rss
  • Główna
  • Wyszukiwanie

Konfiguracja web serwera tak by zyskał dostęp do katalogu symfony_data/web/sf/

Krzysztof Karolczak | 08.12.2008

Radość z uruchomienia pierwszego projektu w Symfony bardzo często rozwiewana jest następującym komunikatem wyświetlanym na stronie:

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.

Prawidłowa konfiguracja serwera www wydaje się najbardziej problematyczną częścią instalacji tego frameworka. Całe szczęście nie jest ona tak trudna jak może się wydawać. Ten krótki przewodnik opisuje dwie metody pozwalające szybko i sprawnie ustawić Apacha tak by polubił Symfony ;) .

Zakładam że posiadacie poprawnie zainstalowaną Symfony (jeśli nie opis instalacji znajduje się tu). Ja osobiście pracuje na serwerze www zainstalowanego z paczki WAMP (Apache+MySQL+PHP) i taką instalację odzwierciedlają ścieżki, którymi posługuję się w przykładach.

Sposób 1 – ustawianie virtual hosta

Stworzenie dla każdego swojego projektu w Symfony wirtualnego hosta wydaje się najlepszym sposobem ich zarządzania w fazie tworzenia.

Zatem do dzieła – najpierw potrzebujemy znaleźć katalog zawierający pliki konfiguracyjne Apacha (u mnie będzie to C:\wamp\bin\apache\apache2.2.6\conf) i otworzyć httpd-vhosts.conf (który jest w podkatalogu extra – C:\wamp\bin\apache\apache2.2.6\conf\extra). W nim należy usunąć lub zakomentować (dodając ‘#’ na początku linijki) wszystkie linie co do których nie mamy pewności co robią ;) – jeśli nie my je napisaliśmy to są to pewnie tylko przykłady konfiguracji vhostów).

W Symfony 1.2 (1.1 może też?) przykładowy plik z konfiguracją vhosta jest tworzony dla każdego projektu który wygenerujesz. Można go znaleźć pod config/vhost.sample – i oczywiście może być on wykorzystany zamiast kodu który znajduje się w przykładzie poniżej.

Zatem na końcu naszego pliku dodajemy następujące linijki (oczywiście to tylko jeden z wielu sposobów konfiguracji – można znaleźć masę innych przykładów ustawień vhostów – wszystke są dobre, jeśli tylko działają, prawda? :) ):

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>

Oczywiście w linijkach ” Alias /sf “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf” ” i ” <Directory “c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf”> ” należy zastąpić ścieżki poprawną ścieżką do katalogu symfony data. Analogicznie w linijkach ” DocumentRoot “c:\wamp\www\your_project\web” ” oraz ” <Directory “c:\wamp\www\your_project\web”> ” należy umieścić ścieżkę do katalogu web swojego projektu.

Powinniśmy też określić własną nazwę wirtualnego hosta umieszczając ją zamiast your_server_name w linijce ‘ServerName your_server_name’.

Teraz musimy upewnić się, że w pliku httpd.conf (główny plik konfiguracyjny Apacha, który u mnie znajduje się w katalogu   C:\wamp\bin\apache\apache2.2.6\conf) linijka ‘Include conf/extra/httpd-vhosts.conf‘ nie jest zakomentowana (nie ma ‘#’ przed nią).

Pozostaje nam już tylko zadeklarować własną domenę lokalnie przez dodanie linijki ‘127.0.0.2 your_server_name’ (oczywiście zamiast your_server_name wpisz wcześniej zdefiniowaną nazwę wirtualnego hosta) ma końcu pliku host (C:\WINDOWS\system32\drivers\etc) . Linijka ‘127.0.0.1 localhost‘ powinna być pierwszą linijką pliku host. A BTW – jego edycja może wymagać uprawnień administratora.

Teraz – po zresetowaniu Apacha – jeśli wpiszemy w przeglądarce http://your_server_name/ nasza strona powitalna Symfony powinna zawierać wszystkie obrazki.

Sposób 2 – zamrażanie projektu

Możemy otrzymać gotową do wdrożenia paczkę z naszym projektem przez użycie komendy ‘freeze‘ – kopiuje ona wszystkie pliki Symfony do naszego projektu, również te “brakujące” z katalogu web/sf. Wystarczy w katalogu projektu wykonać polecenie:

symfony freeze [c:/sciezka/do/katalogu/symfony/data]

Freeze zmienia także niektóre scieżki określone w konfiguracji, więc nasz projekt teraz będzie odwoływał się do bibliotek Symfony umieszczonych w naszym projekcie a nie tych globalnych. Oczywistym minusem tego rozwiązania jest konieczność zrobienia unfreeze (polecenie przeciwne do freeze) i ponownego freeze dla wszystkich swoich projektów po uaktualnieniu Symfony. Mogą się pojawić również problemy ze ścieżkami jeśli nasz projekt nie będzie znajdował się głównym katalogu naszego serwerwa WWW.

Sposób 3 – ten głupi ;)

Jeśli żadna z powyższych metod nie działa dla Ciebie – zawsze można spróbować skopiować zawartość katalogu ścieżka_do_symfony_data/web/sf/ do  twój_projekt/web/ (zatem w moim wypadku byłoby to przeniesienie plików z katalogu C:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf do C:\wamp\www\twoj_projekt\web). Nie jest to oczywiście najczystsze rozwiązanie – jednym z miusów jest to, że po updacie Symfony może się okazać, że będziemy musieli przekopiować ten folder ręcznie do wszystkich swoich projektów i pojawią się zapewne problemy ze ścieżkami – przy korzystaniu z zasobów pluginów lub przy bezwględnym adresowaniu zasobów (choć jeśli zawsze będziemy korzystać z helperów symfony do generowania ścieżek nie powinno to być żadnym problemem).

Kategorie
Instalacja, Symfony
Tags
PHP, Symfony 1.0, Symfony 1.1, Symfony 1.2, vhost
Komentarze rss
Komentarze rss
Trackback
Trackback

« Rozwiązanie problemu z “Maximum execution time exceeded” w PHP 10 krótkich odpowiedzi do najczęściej zadawanych pytań na temat Symfony »

14 odpowiedzi

Oh, thank you. I had to resort to Method 2 (the

Mark | 08.10.2008

Oh, 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 | 06.11.2008

Thank 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 | 10.12.2008

As 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 | 22.12.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 | 29.12.2008

I 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 | 01.01.2009

I 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 | 13.03.2009

Thanks 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 | 06.10.2009

Thank 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 | 08.10.2009

Thanks 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 | 08.10.2009

ok, 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 | 10.10.2009

I 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 | 23.11.2009

I 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 | 14.02.2010

Thanks 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 | 14.02.2010

Thanks 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

Napisz komentarz

Możesz używać następujących tagów : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">



Język

  • English
  • Polski

Navigation

  • css
  • PHP
  • Symfony
    • Instalacja

Blogroll

  • Symfony

Tags

css (1) eclipse (1) framework (2) PDT (1) PHP (5) Symfony 1.0 (4) Symfony 1.1 (3) Symfony 1.2 (3) tips (2) vhost (1)
rss Komentarze rss valid xhtml 1.1 design by jide powered by Wordpress get firefox