Installation and configuration of Apache / PHP / MySQL in Ubuntu

You have just installed the latest version of Ubuntu 13.04 and want to install additional software for learning web programming and running frameworks like Symfony 2, yii, zend, etc.? Then you've come to the right place. Let's go through 10 simple steps to achieve this. We will start with the installation of a web server and then move on to Symfony.

But first, some details:

  • This article is a brief guide that summarizes all the steps required to set up your server with subsequent installation of Symfony 2.
  • I assume you want to create a website accessible at http://symfony URL and the site content will be placed in the directory /Home/MyName/WWW/symfony/. You can always change this.
1. Install Apache
sudo apt-get install apache2
2. Install MySQL
sudo apt-get install mysql-server mysql-client
3. Install PHP 5
sudo apt-get install php5
4. Install PHPMyAdmin
sudo apt-get install phpmyadmin
During the installation, you might be asked two questions: 1) How do you want to configure PhpMyAdmin to work with your server? Choose apache2. 2) Configure database with PhpMyAdmin DBCONFIG? Choose No.

5. Install necessary Apache/PHP modules for Symfony 2

The first one is mod_rewrite, which allows you to use URL rewriting in .htaccess:

sudo a2enmod rewrite
6. Install useful PHP modules
sudo apt-get install php5-intl

sudo apt-get install php-apc

sudo apt-get install php-pear

sudo apt-get install php5-dev sudo pecl install xdebug

7. Configure PHP

Change the PHP parameters by editing the following lines in /etc/php5/apache2/php.ini:

short_open_tag = Off

date.timezone = Europe/Ukraine

Then configure the modules again:

APC

Edit the file /etc/php5/conf.d/20-apc.ini and add the following lines:

apc.shm_size = 128M
XDebug

Create the file /etc/php5/conf.d/20-xdebug.ini:

zend_extension = /usr/lib/php5/20100525/xdebug.so
xdebug.max_nesting_level = 250
8. Configure local site

8.1 Host file

sudo nano /etc/hosts
Add the following line:
127.0.0.1 symfony
8.2 Virtual Host

Create a new VirtualHost for our site:

sudo nano /etc/apache2/sites-available/symfony
In the editor, insert this configuration, replacing the /Home/MyName/WWW/Symfony/Web/ directory with the directory where you want to place your site:
VirtualHost *:80;
ServerAdmin webmaster@localhost
ServerName symfony
DocumentRoot /home/mon_nom/www/symfony/web/

Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all ErrorLog ${APACHE_LOG_DIR}/error-symfony.log LogLevel warn CustomLog ${APACHE_LOG_DIR]/access-symfony.log combined /VirtualHost

Activate the VirtualHost we just created:
sudo a2ensite symfony
The directory where you placed Symfony is ready:
cd ~
mkdir www
Finally, restart Apache:
sudo service apache2 reload
9. Install Composer

First, install the curl module, which allows us to easily install Composer:

sudo apt-get install curl
Then, install Composer:
cd ~
curl -sS https://getcomposer.org/installer | php
To make it convenient to use, let's make it executable anywhere in the system:
sudo mv composer.phar /usr/local/bin/composer
Now, to use composer, simply enter the following in the terminal:
composer
10. Finally, install and configure Symfony2
cd ~/www
composer create-project <code>symfony/framework-standard-edition path/to/install
Update the dependencies:
composer update
Set cache and log permissions:
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

To simply ensure that everything is fine and that Symfony 2 is ready to run, go to the following address in your browser: http://symfony/config.php. You should see a message on a green background saying "Your configuration meets all the requirements to run Symfony. You only need to click on the 'Configure Symfony online' link to complete the installation of Symfony 2."