My first step in learning Symfony is to go through the Getting Started Big Picture tutorial.
I followed the instructions to install Symfony, but immediately ran into a problem when I tried to execute the new
Symfony command. I got a ‘permission denied’ error. I had to change the permission to 755 on the
/usr/local/bin/Symfony file before it would work. I had to do this on both my iMac and my MacBook.
I created ‘myproject’ using the command
Symfony new myproject
This worked great and I now have a ‘myproject’ folder with the code inside.
I tried to run the php server as they suggested using:
$ cd myproject/ $ php app/console server:run
but, I kept getting an error:
[Symfony\Component\Debug\Exception\ContextErrorException] Warning: date_default_timezone_get(): It is not safe to rely on the system' s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those me thods and you are still getting this warning, you most likely misspelled th e timezone identifier. We selected the timezone 'UTC' for now, but please s et date.timezone to select your timezone. in /Users/cindy/sites/myproject/v endor/monolog/monolog/src/Monolog/Logger.php line 233
This is just a warning, but the server doesn’t start running. Since I’m using MAMP, I bypassed this step and set up the server in MAMP instead.
UPDATE: I figured this out later in the tutorial and explain how I fixed it at the bottom of this article.
I set up MAMP to create ‘myproject’ as the host and pointed it to the ‘web’ folder inside the project. After starting the MAMP Apache and MySQL servers, I tried to go to ‘myproject’ in my browser. I got this error:
Looking a little farther down in the tutorial I noticed a link to ‘Setting up Permissions’. I clicked on it to see if I could figure out where I was supposed to be going in my browser instead – or what might be wrong. This took me to the documentation to the current Symfony book. Just underneath the permissions section I found a reference to
http://localhost/app_dev.php/, so I tried
myproject/app_dev.php. That was it! My first Symfony page showed up and looked just like the page in the tutorial.
A little further down in the tutorial, it references this page about setting up your server which may be helpful if you are still having problems getting Symfony to work on your computer.
A quick look in the web folder shows that no index.php file exists. I assume I’ll learn why a little later, so I’m going to move forward with the tutorial. I also assume that the tutorial was probably written for an earlier version and things have probably changed a bit.
The next section of the tutorial discusses the fundamentals and lists several paths to the demo page. These paths don’t exist in my code, so I’m still assuming that the tutorial hasn’t been updated for my current version.
After reading the sections about ‘Actions and Controllers’ and ‘Routing’ and finding none of the paths to match, I almost gave up. But, then I discovered that if I use
http://myproject/app_dev.php as the base url, I could get the demo to work.
The code above gave me the demo page, however, the page kept loading for quite a bit. I thought at first it was my internet connection, but it just kept spinning and other pages were loading fine. Maybe this is because I’m using the dev file (app_dev.php) to load the page which also loads all the debugging tools.
Since the code is not the same as what I now have on my computer, I just read through the tutorial to see what’s changed since I last used Symfony. If I had never used Symfony, I’m not sure how much sense this tutorial would make since my code looks nothing like that in the tutorial. I suppose it would be enough to give me the overall picture of Symfony.
I would like to warn Symfony ‘newbies’ not to be too concerned if they don’t understand this tutorial. I believe if we just keep hanging in there, it will begin to make sense. Hopefully, it will make more sense when we start working through the book. I do still think reading through this tutorial will be beneficial to beginners. If nothing else, you will at least begin to see and familiarize yourself with the jargon used by Symfony developers.
Here are a couple of things I noticed as I read through the tutorial:
- Symfony now uses PHP Annotations to set up the Routes. That’s cool. Nice option!
- Symfony is now using Twig for templating. I’m anxious to learn Twig. I’ve seen a presentation on Twig at a PHP user’s group before and found it to be very interesting. I’m always excited about learning something new!
- I love the new debug tools that I find at the bottom of the page. I’m anxious to see how these work.
Next, we’ll dive into ‘The View’ tutorial. My guess is that the code will not match up with the code I have for myproject, but I’ll still read through it to get an idea of how Symfony works and make notes of some of the things I find interesting. After the tutorial, I’ll dig into the Symfony2 book under the ‘Documentation’ tab. Are we having fun yet?