This is the first post of two where you will end up configuring a PHP development environment in Ubuntu and using Eclipse. This first post is for installing and configuring Apache, MySQL and PHP in Ubuntu.
From a fresh installation of Ubuntu follow these steps:
1. Refresh your Ubuntu package index, executing the following command: sudo apt-get update
2. Install the lamp server: sudo apt-get install lamp-server^. Note the caret (^) at the end. That is required to let apt-get to install the lamp-server without using tasksel (another tool for installing common packages that are used together).
During installation you will be informed that 119MBs are required for the installation. And also you will be asked for the MySQL root password.
Now, to finally configure apache2, run the following commands:
2. sudo service apache2 restart
To test that apache is running, go to http://localhost/, and if you see on you browser the message “It works!”, then you are OK. The default document root in Ubuntu is /var/www/html. So, when you navigate with http://localhost/, you should see the content of the file /var/www/html/index.html.
Here is a sample command of how to deal with the apache service:
sudo service apache2 [start|stop|restart]
Create a file called /var/www/html/test.php, and inside it paste the following code:
<?php phpinfo(); ?>
Then go to http://localhost/test.php and verify that you see the php information page.
PHP5 comes with two configuration files, one for development and other for production. You will find them in the following locations: /usr/share/php5/php.ini-development and
/usr/share/php5/php.ini-production. To configure the one for development, first do a backup copy of the current one and then, create a symbolik link, running the following two commands:
sudo mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
sudo cp -s /usr/share/php5/php.ini-development /etc/php5/apache2/php.ini
Debug in PHP
In order you can debug PHP applications, you have to install xDebug. Run the following commands:
sudo apt-get install php5-xdebug
sudo gedit /etc/php5/apache2/php.ini
# Added for xdebug
Then, restart the apache service: sudo service apache2 restart
You can enter to the mysql console, typing: mysql -u root -p. Or you can install MySQL-Workbench running the following command: sudo apt-get install mysql-workbench. After that to start mysql workbench, just type in a console: mysql-workbench.
Now that you have LAMP installed, configured and tested, you can read the Eclipse/PHP post to install and configure Eclipse to start developing.