Want the source code of the blog?

On Sunday 18 July 2010 in Symfony, PHP / AFUP

As a symfony developer and an Open Source fan, I would like to share the code source I produced for this weblog application. I left the source code in a Subversion repository hosted by Google Code. Feel free to checkout the code, to install the application and review the code I wrote. You will probably learn lots of good things and best practices. The content of this post explains how to install and run the application.

Introduction

You are about to install this symfony project. This is an Open Source application released under the MIT license that provides a weblog platform. The project is split in two applications: the frontend and the backend.

The frontend application is the interface dedicated to the public whereas the backend application hosts the weblog management.

Dependencies

This symfony project has several dependencies:

  • PHP 5.2.4 or later
  • Symfony 1.4.x framework
  • sfDoctrineGuardPlugin
  • sfFormExtraPlugin
  • sfEasyMarkdownPlugin
  • sfEasySyntaxHighlighterPlugin

Web Server Installation

To install this project, run the following command:

$ cd /path/to/web/root
$ mkdir blog
$ cd blog/
$ svn co http://symfony-blog.googlecode.com/svn/tags/RELEASE_0.9.0/ .

Create a virtual host in your httpd.conf or httpd-vhosts file:

<VirtualHost *:80>
  ServerName sf-blog.local
  DocumentRoot "/path/to/web/root/blog/web"
  <Directory "/path/to/web/root/blog/web">
    AllowOverride All
    Allow from All
  </Directory>
 
  Alias /sf /path/to/web/root/blog/lib/vendor/symfony/data/web/sf
  <Directory "/path/to/web/root/blog/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Restart your Apache server and add the following entry to your hosts file:

127.0.0.1 sf-blog.local

Configure Databases

First, you will need to configure at least two database connections. The first one is dedicated to the development and production environments. The second will host the test environment.

Configure your database connections in config/databases.yml file. The code below configures two MySQL connections.

test:
  doctrine:
    param:
      dsn:      mysql:host=localhost;dbname=blog_test
      username: my_username
      password: my_password
 
all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:host=localhost;dbname=blog
      username: my_prod_user
      password: secret

Configure the Frontend Application

Then, you will have to change some sensible defaults in the apps/frontend/config/app.yml file as described below:

test:
  bookmarks:
    max_in_sidebar:             3
 
all:
  available:
    cultures:                   [en, fr]         # Available Cultures
  contact:
    email:                      you@example.com  # Contact email
  feeds:
    author:                     John DOE         # Atom feeds author
    email:                      you@example.com  # Atom feeds email
  posts:
    max_per_page:               5     # Max posts per page
  comments:
    max_in_sidebar:             20    # Max comments in sidebar
  bookmarks:
    max_in_sidebar:             20    # Max bookmarks in sidebar
  blogroll:
    max_in_sidebar:             20    # Max blogroll links in sidebar

Update fixtures

Eventually, you can add more fixtures in data/fixtures/prod/*.yml files. The default administrator user is admin and password is secret. You can change this login and password in the data/fixtures/prod/sfGuardUser.yml file.

Build the Project

When your project is configured, run the following command to build everything:

$ cd /path/to/your/project
$ php symfony doctrine:build --all --env=test
$ php symfony doctrine:build --all --and-load="data/fixtures/prod/"

Run the Test Suite

To run the test suite, just execute the command below:

$ php symfony test:all

Deploy Web Assets

Run the following command to deploy plugins' assets:

$ php symfony plugin:publish-assets

Browse your Application

You can navigate the frontend application by browsing the following URIs:

http://sf-blog.local/frontend_dev.php
http://sf-blog.local/index.php

And the backend application with the following URIs:

http://sf-blog.local/backend_dev.php
http://sf-blog.local/backend.php

Comments

Posted by pomeh - about 1 month ago

C'est "juste" excellent comme initiative ! Très très sympa de mettre à disposition un exemple complet de blog sous symfony, lire les sources c'est le meilleur moyen pour apprendre ! Et j'ai encore beaucoup de choses à apprendre avec symfony et doctrine... J'espère que je vais réussir à entrer dans ta logique de code pour ne rien manquer d'intéressant. J'ai déjà fais un petit tour rapide, et j'ai déjà rencontré plein de choses que je ne connaissais pas... Awesome !

J'ai déjà une petite question, mais qui à plus attrait au serveur. Est-ce que tu sais comment on peut configurer un projet symfony sur un serveur mutualisé ? On a pas forcément accès aux fichiers de configurations de apache... Et deuxième petite question, je viens de découvrir que tu utilise ServerGrove qui propose des solutions avec des framework php, est-ce que tu en est content ? Si tu devez en lister les principaux avantages/inconvénients, quels seraient-ils ?


Merci pour ces petites réponse et surtout merci pour ce partage :)

Posted by Hugo Hamon - about 1 month ago

>> Est-ce que tu sais comment on peut configurer un projet symfony sur un serveur mutualisé ?

Ca dépend des hébergeurs mais je sais que sur OVH par exemple la ligne de commande n'est pas disponible ce qui est plutôt problématique. Quand on travaille avec symfony, on doit s'assurer d'avoir un hébergement sur lequel on peut avoir la main. ServerGrove par exemple me fournit un hébergement mutualisé dédié à l'accueil de projets symfony. Je n'ai pas accès directement à la configuration d'Apache mais je dispose d'un backoffice Plesk pour tout administrer ainsi qu'un accès ssh suffisant pour exécuter des commandes symfony.

>> [...] ServerGrove qui propose des solutions avec des framework php, est-ce que tu en est content ?

Plutôt oui pour un service gratuit ^^ ServerGrove m'a offert un plan d'hébergement mutualisé donc je ne me plains pas sur la qualité. Il y'a eu quelques petits désagréments de leur côté lorsqu'ils ont migré mon compte sur un nouveau serveur avec PHP 5.3 mais ça a été très vite réglé car je suis en contact direct avec le CTO chez eux. Je ne suis jamais passé par leur service clientèle.

>> [...] principaux avantages/inconvénients, quels seraient-ils ?

+ Très bon rapport / qualité prix
+ Serveur en PHP 5.3 + MySQL + PostGreSQL + Python
+ Accès SSH pour administrer ses projets symfony
+ Panel de gestion Plesk pour gérer les domaines, les mails, les stats...

- Serveurs américains donc adresses IP américaines (pas très avantageux pour l'indexation sur Google.fr par exemple)
- Configuration de PHP pour les USAs (locale, date / heure ...)

Hugo.

Posted by Sylvain Papet - about 1 month ago

Concernant OVH, il est tout à fait possible d'héberger un projet Symfony en mutu. Par contre les mutus (comme chez d'autres hébergeurs) sont moins adaptés pour des projets Symfony car les librairies sont lourdes et ne sont pas mise en cache (apc) comme ce pourrait être le cas sur un dédié. Les performances sont donc assez moyenne, ça dépend de la taille du projet (nombres de librairies utilisées, etc).

Il est possible d'avoir la console sous OVH mais il faut bidouiller, enfin je ne sais pas si c'est encore le cas car ça fait bien un an que j'ai plus de projets sur un mutu ovh. Avant en tout cas, taper php en console exécutait php4, il fallait donc chopper le path de php5 et lancé un truc du genre "/[path]/php5.2.8 -f symfony"

Posted by David - about 1 month ago

Thank you very much for being so kind!

Posted by NiKo - about 1 month ago

Hey j'avais raté ça, excellent !

C'est juste dommage d'avoir mis ça sur subversion, un ptit dépôt git(hub) te permettrait de recevoir des contributions plus efficacement amha :)

Posted by Hugo Hamon - about 1 month ago

@N1Ko : hé hé merci. Oui c'est prévu le dépôt Github. J'en mettrai un en place quand je maîtriserai davantage Git. Mais c'est clair que Google Code pour les contributions ce n'est pas le top surtout que je peaufine régulièrement l'application pour corriger des pétouilles à droite et à gauche. L'objectif c'était d'abord de partager rapidement le code.

Posted by Hugo Hamon - 23 days ago

I've just fixed a broken file reported by someone in my twitter timeline. The code is now fixed in the trunk or better in the stable tag you can check out here: http://symfony-blog.googlecode.com/svn/tags/RELEASE_0.9.0/

Posted by Serhadrartida - about 7 hours ago

Very Interesting!
Thank You<a href=http://ukegfvkwuergfku.com>!</a>

Posted by Serhadrartida - about 3 hours ago

Very Interesting!
Thank You<a href=http://ukegfvkwuergfku.com>!</a>

Leave a comment

Your comment