Quantcast
Viewing all articles
Browse latest Browse all 10

Tutorial: bootstrapping a Symfony2 project with Ubuntu 12.10 and Github

Italian version here.

Assuming that the operating system has just been installed, this tutorial focuses on bootstrapping a new Symfony2 project under Ubuntu 12.10 and managing it through Github, with the addition of some non-essential but widely used components. For any left out detail, please post a comment below or visit the official documentation.

Let’s start installing some packages before the actual project setup:

  • Install git:
    sudo apt-get install git
  • Install java:
    sudo apt-get install openjdk-7-jre
  • Install node and less (not mandatory if you don’t want to use assetic with the less filter):
    sudo apt-get install g++  
    wget http://nodejs.org/dist/v0.10.0/node-v0.10.0.tar.gz  
    tar xvfz node-v0.10.0.tar.gz  
    cd node-v0.10.0.tar.gz  
    ./configure  
    make && sudo make install  
    sudo npm install less --global
  • Install and configure the LAMP environment:
    sudo apt-get install php5 php5-gd php5-mysql php5-curl php5-mcrypt php5-intl php-pear php5-cli php5-dev libapache2-mod-php5 mysql-client-5.5 mysql-server-5.5
    • Edit /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini:
      • uncomment date.timezone key and set it to your timezone (for a complete list of timezones, check this page). E.g.:
        date.timezone = Europe/Rome
      • set short_open_tag to Off:
        short_open_tag = Off
  • Install APC:
    sudo apt-get install libpcre3-dev  
    sudo pecl install apc  
    echo "extension=apc.so" | sudo tee -a /etc/php5/conf.d/apc.ini

 

We can now actually install our project. We will assume that:

  1. the project folder will be placed in our Ubuntu user home. Some following instructions depends on this assumption; nevetheless the project can be installed anywhere in the filesystem, but the installation instructions would slightly vary.
  2. We’ll call our project mySymfony2Project (such a great imagination I have…). Needless to say this choice is totally arbitrary.
  3. We’ll use the latest version on Symfony2 at the moment of writing this article, namely 2.2.0.
  • Download Composer:
    cd ~
    curl -s https://getcomposer.org/installer | php
  • Initialize the Symfony2 project skeleton:
    php composer.phar create-project symfony/framework-standard-edition mySymfony2Project 2.2.0
    mv composer.phar mySymfony2Project
  • Initialize the git repository and run the first commit:
    cd mySymfony2Project
    git init
    git add .
    git commit -m "Initial commit"
  • Create the project repository on Github and link it to the local one. To do so, go to https://github.com/new and submit the module as in the picture:
    Image may be NSFW.
    Clik here to view.
    New github repository screenshot

    then link the two repositories:
    git remote add origin https://github.com/<username>/mySymfony2Project.git
    git push -u origin master
  • Configure ACL for cache and logs folders:
    sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
    sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
  • Setup the apache virtual host:
    • Deactivate the default one:
      sudo a2dissite 000-default
    • Create the file for the project virtual host at the path /etc/apache2/sites-available/mySymfony2Project with the following content, replacing <user> with your Ubuntu user name:
      <VirtualHost *:80>
        ServerName mysymfony2project.localhost
        DocumentRoot "/home/<user>/mySymfony2Project/web"
        DirectoryIndex app.php
      
        ErrorLog "/var/log/apache2/mysymfony2project.localhost-error.log"
        CustomLog "/var/log/apache2/mysymfony2project.localhost-access.log" common
        TransferLog "/var/log/apache2/mysymfony2project.localhost-transfer.log"
      
        <Directory "/home/<user>/mySymfony2Project/web">
          AllowOverride All
          Allow from All
        </Directory>
      </VirtualHost>
    • Activate the virtual host:
      sudo a2ensite mySymfony2Project
    • Add the host:
      sudo sh -c 'echo "127.0.0.1 mysymfony2project.localhost" >> /etc/hosts'
    • Configure apache ServerName:
      sudo sh -c 'echo "ServerName localhost" >> /etc/apache2/conf.d/name'
    • Restart apache:
      sudo service apache2 restart

That’s all! We can now browse http://mysymfony2project.localhost/app_dev.php and check that our project executes flawlessly. Good developing time to everyone!


Viewing all articles
Browse latest Browse all 10

Trending Articles