November 17, 2010

Installing Apache, PHP5 and MySQL in Ubuntu


I have been using Java for years. Now, there is an open source PHP project (using CodeIgniter) I need to study and modify. Although I have studied and tried the basics of PHP and CodeIgniter before graduating in college, I already forgot most of it by now. This means I need to study and review the basics and learn some advanced topics, especially those I would need. To start with this, I need to install Apache and PHP. Here are the steps I did to install Apache, PHP and MySQL. I also enumerated the steps I did to map folders outside the /var/www directory.

Installing Apache, PHP and MySQL in Ubuntu

  • Install Apache
  • Open the terminal and execute the command sudo apt-get install apache2. After that, apache will now be installed automatically.

  • Install PHP
  • Open the terminal and execute the command sudo apt-get install php5 libapache2-mod-php5(This installs PHP5).

  • Restart Apache
  • Execute the command sudo /etc/init.d/apache2 restart

  • Test the installation of PHP and Apache
  • Go to the /var/www directory (This is the directory where you should put your PHP files). Create a file, like test.php and add in it. Then open the URL http://localhost/test.php in your web browser. You should see the text "Hello World!". If not, maybe something was wrong in the installation.

  • Installing MySQL
  • Execute the command sudo apt-get install mysql-server

  • Installing php5-mysql
  • Execute the command sudo apt-get install php5-mysql

  • Restart Apache
  • After installing mysql-server and/or php5-mysql, restart the apache server again. Apache, PHP and MySQL are now installed.

Mapping folders outside of the /var/www directory

Instead of using the /var/www for your PHP files and projects, you can use other folders other by mapping the directory in an alias in the configuration file. Open /etc/apache2/conf.d/aliasin your text editor (e.g. sudo gedit /etc/apache2/conf.d/alias). Add the aliases using the syntax "Alias /URL-path /location_of_folder/" where "/location_of_folder/" is the directory of the PHP file/project and "/URL-path/" will be its localhost alias. This example would map /location_of_folder/ to http://localhost/URL-path. Restart Apache after inputting the aliases.


No comments:

Post a Comment