How to install Apache 2 PHP 5 MYSQL 5


How to install Apache 2, PHP 5 & MySQL 5 in one go.

Today I will show you how to get a web server up and running in no time on Ubuntu Linux including extra packages that most professional web host companies would have enabled.

You will be hosting websites in no time!

NOTE: Please read this page as a reference before continuing on. As it may help, some references might relate to Ubuntu Linux.

Package Descriptions:

  • Apache 2: Apache is a software that allows you to run a web service on a UNIX server. Apache is very popular and provides access to most web sites on the internet
  • PHP 5: PHP is a computer scripting language originally designed for producing dynamic web pages. The name PHP is a recursive initialism for PHP: Hypertext Preprocessor. PHP is used mainly in server-side scripting
  • MySQL 5: MySQL is a multi threaded SQL database management system, the basic program runs as a server providing multi-user access to a number of databases.
  • php5-mysql: modules for MySQL database connections directly from
    PHP scripts

Lets get started on installing, In console:

sudo apt-get install apache2 php5 mysql-server php5-mysql

You can now just copy over your website to the location "/var/www/" and enter http://localhost/ into your browser to see your website. To internet, your URL would be http://youripnumber/ if you wanted to show someone.

You are done at this point for the basic web server unless!
>You want to serve your web site contents out of another location in your file sytsem.
>If you want the extra packages that professional webhosting companies would have installed.
Then continue reading!

Serving content out of another directory:
Now onto the editing the default configuration file, "/etc/apache2/sites-enabled/000-default":

sudo nano /etc/apache2/sites-enabled/000-default

First, 4 lines of the default configuration file, you will see "DocumentROOT /var/www/":

DocumentROOT /var/www/

Change that location to where your web site files are are located.

Restarting Apache 2 to take effect:

sudo /etc/init.d/apache2 restart

How to install extra packages section!

  • php5-gd: a module for handling graphics directly from PHP
    scripts. It supports the PNG, JPEG, XPM formats as well as Freetype/ttf fonts.
  • php5-imagick: a software suite to create, edit, and compose images. (most PHP photo gallery's packages use this)
  • php5-mcrypt: a file encryption tool
  • phpmyadmin: to handle the administration of MySQL databases over the WWW.

Time to install them:

sudo apt-get php5-gd php5-imagick php5-mcrypt phpmyadmin

Restart apache 2 afterwards for the packages to take effect:

sudo /etc/init.d/apache2 restart

Note: To use phpmyadmin, open your web browser to http://localhost/phpmyadmin

Enjoy your web server :)