How to install Symfony in a WAMP server project and make it work?

Posted on June 25, 2014, 6:30 am by about-dev.com


When you code using a Linux OS things are quite easy, but when you are a beginner and use Windows OS and WAMP server for PHP applications things aren't so easy smiley. That's way in this post I intend to guide you through the process of installing Symfony framework on WAMP server and make it work.

Step 1: Install composer:

For a detailed description of this process you can check this link.

The easiest way of installing something this days is to use composer, that's way the first step you have to take is to install composer.

INFO: I've installed it in the document root path of the server because it's possbile to use it to other projects too.

Windows does not have a curl processor like unix so you need to use this command to install composer:

C:\wamp\www>c:\wamp\bin\php\php5.4.12\php.exe -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

, or (if you have added PHP to your PATH and php is a recognized command)

C:\wamp\www>php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

Possible errors

PHP Warning:  file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. file_get_contents() Command line code:1
PHP Warning:  file_get_contents(https://getcomposer.org/installer): failed to open stream: Invalid argument in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. file_get_contents() Command line code:1
PHP Warning:  file_get_contents(https://getcomposer.org/installer): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, 
or established connection failed because connected host has failed to respond.In Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. file_get_contents() Command line code:1

Possible solutions:
Activate curl and openssl extensions from PHP and activate the ssl module from Apache. You can achieve these very easy using WAMP server interface.

But, the activation of the PHP extensions is made on the php.ini file from the Apache (C:/wamp/bin/apache/ApacheVERSION/bin/php.ini). 
You have to activate the ones from the PHP extension itself (C:/wamp/bin/php/phpVERSION/bin/php.ini), because you will use CLI.

Restart the server from the interface.

Step 2: Install Symfony version 2.3 (because it has long-term support)
To download Symfony version 2.3 you can access this link. For more installation instructions you should check this link.

For our scope it's enough to run the following command in the path where you want to install the framework:

C:\wamp\www\aplicatie>c:\wamp\bin\php\php5.4.12\php.exe composer.phar create-project symfony/framework-standard-edition . "2.3.*"

For possible errors read this post: "How to fix Symfony after installation problems"

Step 3: Symfony welcome page
After Symfony framework installation you will have for sure a 404 Not Found error, because, by default you will access the application like this:
http://localhost/aplicatie/web
, and in this case the application will look for the app.php file, which is normally used for a production environment.

In this case, the easiest method to solve the problem is to change the environment from prod to dev at line 19 in the app.php file (but, keep in mind that this is not a good practice smiley)

From this: $kernel = new AppKernel('prod', false);
To this: $kernel = new AppKernel('dev', false);

The other way (the correct way) is to create a virtual host (http://aplicatie.localhost) where you should point to the app_dev.php file. This file is used for the development environment. Usually, you should "prepare" your project using the development environment (pointing to the app_dev.php file) and then move on to the production environment (pointing to the app.php file).

After you fix the possible errors you should see the symfony welcome page: 

That's it! For further questions and clarifications dont' hesitate to use the form below.

Related articles:


Leave a Comment:

User
Email
Website

Blog Search

Popular Blog Categories

Newsletter

Want to be informed about latest posts? Subscribe to our newsletter