Symfony2 Jobeet Day 1: Starting Up The Project: Ent Ert Ainment, New S, Soft W Are

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Search

ENS
Entertainment, New s, Softw are

Home

Web Development

About ENS

Contact

Posted on March 22, 2012

Previous Next

Symfony2 Jobeet Day 1: Starting up the Project


Today we will setup the development environment, install Symfony2 and display a page of the application in a web browser. First of all, you need to check that your computer has a friendly working environment for web development. At a minimum, you need a web server (Apache, for instance), a database engine (MySQL), and PHP 5.3.2 or later. Download and install Symfony2 Prepare a directory on your web server where you want to install the new project. We will name this directory jobeet as the name of our future website. Then go to http://symfony.com/download, choose Symfony Standard (the version with vendors) and download it (at the moment of writing this tutorial, the latest Symfony version was 2.0.11). After downloading, unpack the archive and copy the contents of Symfony dir to your project directory. You should now have something like this:

Web Server Configuration A good web practice is to put under the web root directory only the files that need to be accessed by a web browser, like stylesheets, JavaScripts and images. By default, its recommended to store these files under the web/ sub-directory of a symfony project.

converted by Web2PDFConvert.com

To configure Apache for your new project, locate and open the httpd.conf configuration file and add the following configuration at the end:
<VirtualHost *:80> ServerName jobeet.local DocumentRoot /home/dragos/work/jobeet/web DirectoryIndex app.php ErrorLog /var/log/apache2/jobeet-error.log CustomLog /var/log/apache2/jobeet-access.log combined <Directory "/home/dragos/work/jobeet/web"> AllowOverride All Allow from All </Directory> </VirtualHost>

Change the above configuration to reflect your setup and then restart your web server. This is the standard way to define a new virtual host in Apache. Depending on your server configuration or Apache version, some things might be slightly different. For example in Ubuntu you have to create a new file in the folder /etc/apache2/sites-enabled/ named jobeet with the above content. The domain name jobeet.local used in the Apache configuration has to be declared locally. If you run a Linux system, it has to be done in the /etc/hosts file. If you run Windows, this file is located in the C:\WINDOWS\system32\drivers\etc\ directory. Add in the following line:
127.0.0.1 jobeet.local

Test the Symfony2 Installation After restarting Apache, open a browser window and type in http://jobeet.local/app_dev.php. You should see the following page:

To avoid some headaches further down the line, check that your configuration can run a Symfony2 project smoothly by requesting the following URL: http://jobeet.local/config.php. Make sure you dont have any Major Problems listed, and follow the optional recommendations listed (if any). Symfony2 console Just like Symfony 1.x, Symfony2 comes with the console component tool that you will use for different tasks. To see a list of things it can do for you type at the command prompt:
php app/console list

Creating the Application Bundle As you know, a Symfony2 project is made up of bundles. Even the Symfony framework is a bundle. To create a new bundle for our application run from the command line:
converted by Web2PDFConvert.com

php app/console generate:bundle --namespace=Ens/JobeetBundle --format=yml

The generator will ask you some questions before generating the bundle. Here are the questions and the answers (all except one are the default answers): Bundle namespace [Ens/JobeetBundle]: Ens/JobeetBundle Bundle name [EnsJobeetBundle]: EnsJobeetBundle Target directory [/home/dragos/work/jobeet/src]: /home/dragos/work/jobeet/src Configuration format (yml, xml, php, or annotation) [yml]: yml Do you want to generate the whole directory structure [no]? yes Do you confirm generation [yes]? yes Confirm automatic update of your Kernel [yes]? yes Confirm automatic update of the Routing [yes]? yes Clear the cache after generating the new bundle with:
php app/console cache:clear --env=prod php app/console cache:clear --env=dev

The new Jobeet bundle can be now found in the src directory of out project: src/Ens/JobeetBundle. The bundle generator made a DefaultController with an index action. You can access this in your browser: http://jobeet.local/hello/jobeet or http://jobeet.local/app_dev.php/hello/jobeet The Environments As Symfony 1.x, Symfony2 also has different environments. If you look in the projects web directory, you will see two php files: app.php and app_dev.php. These files are called front controllers; all requests to the application are made through them. The app.php file is for production environment and app_dev.php is used by web developers when they work on the application in the development environment. The development environment will prove very handy because it will show you all the errors and warnings and the Web Debug Toolbar the developers best friend. Thats all for today. See you on the next day of this tutorial when we will talk about what exactly the Jobeet website will be about! Symfony2 Jobeet Day 2: The Project
This entry w as posted in English, PHP, Web Development by Dragos Holban. Bookmark the permalink.

Leave a Reply
Your email address will not be published. Required fields are marked *

Name

Email

Website

Comment

Post Comment
converted by Web2PDFConvert.com

Proudly powered by WordPress

converted by Web2PDFConvert.com

You might also like