Symfony on CentOS 5

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Deprecated

This guide has been deprecated and is no longer being maintained.

Create a Linode account to try this guide with a $100 credit.
This credit will be applied to any valid services used during your first 60 days.

Symfony is a PHP web application framework, providing the classes and tools required to build and enhance both simple and complex applications. Featuring easy AJAX integration, an admin interface generator, and more, Symfony has become a very popular choice for web application development.

Before installing Symfony, it is assumed that you have followed our Setting Up and Securing a Compute Instance. If you are new to Linux server administration, you may be interested in our introduction to Linux concepts guide, beginner’s guide and administration basics guide.

Basic System Configuration

First, update all of the base packages:

yum update

Install make, as it will be required for installation of the other packages:

yum install make

Since CentOS does not include the latest version of PHP 5.2 (which is required for the Symfony Framework), you’ll need to add an external repository. Add the webtatic repository:

rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname -i`/webtatic-release-5-0.noarch.rpm

Edit the file /etc/yum.repos.d/webtatic.repo. Under [webtatic] add the following line:

File: /etc/yum.repos.d/webtatic.repo
1
exclude=php\*5.3\*

This will ensure that no PHP 5.3 packages will be installed, as Symfony does not use any features of PHP 5.3.

Install Required Packages

Install the Apache web server with devel package:

yum --enablerepo=webtatic install httpd httpd-devel

Install the MySQL database server:

yum --enablerepo=webtatic install mysql mysql-server

Install PHP 5.2 with the packages required for the Symfony:

yum --enablerepo=webtatic install php php-mysql php-pear php-devel php-xml php-posix php-mbstring

Install the compiler packages, as we will need them for the installation of the APC accelerator:

yum install gcc

Install the APC accelerator using PECL:

pecl install apc

Answer “yes” to all questions. After the installation complete, execute the following command to add the APC module to the web server:

echo extension=apc.so > /etc/php.d/apc.ini

Set the MySQL server to start on boot and start it:

/sbin/chkconfig --levels 235 mysqld on
service mysqld start

Set the root password for the MySQL server and apply the security necessities:

mysql_secure_installation

Edit /etc/php.ini and find the following line:

File: /etc/php.ini
1
short_open_tag = On

Replace it with this line:

File: /etc/php.ini
1
short_open_tag = Off

Set the web server to start on boot and start it:

/sbin/chkconfig --levels 235 httpd on
service httpd start

Download the Symfony system configuration check file and run it:

wget http://sf-to.org/1.4/check.php
php check_configuration.php

You should get “OK” for all the tests.

Create Your First Symfony Project

Create a project folder under /home. We will use sfproject as our project name:

mkdir /home/sfproject
cd /home/sfproject

Create lib/vendor folder under the /home/sfproject:

mkdir -p lib/vendor
cd lib/vendor

Download the latest Symfony release:

wget http://www.symfony-project.org/get/symfony-1.4.5.tgz

Extract it and rename it:

tar zxpf symfony-1.4.5.tgz
rm symfony-1.4.5.tgz
mv symfony-1.4.5 symfony

Go to the project root and generate the project:

cd /home/sfproject
php lib/vendor/symfony/data/bin/symfony generate:project sfproject

Now, Symfony has created all necessary files/folders for the project. You can have a look at them.

There is now a symfony executable shortcut under /home/sfproject. From now on you can use the ./symfony shortcut (when you are in the /home/sfproject directory) to execute Symfony commands.

Configure the database, entering your MySQL root password for “pass”:

./symfony configure:database "mysql:host=localhost;dbname=dbname" root pass

Generate the frontend application:

./symfony generate:app frontend

Now, we need to configure the web server to serve our new project.

Edit /etc/httpd/conf/httpd.conf and add at the end:

File: /etc/httpd/conf/httpd.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot "/home/sfproject/web"
  DirectoryIndex index.php
  <Directory "/home/sfproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
  <Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Restart the web server:

service httpd restart

Using your browser, browse to your Linode’s IP address. You should now see the Symfony Project Created page. From now on, you can easily follow the official Symfony tutorial.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.