Installing Apache, MySQL and PHP on Ubuntu


This is a quick guide for installing Apache, MySQL and PHP on Ubuntu 11.10 using Ubuntu’s apt-get command.

The apt-get command is a powerful command-line tool used for working with Ubuntu’s Advanced Packaging Tool (APT) to install new software packages, upgrade existing software packages, update the package list index, and even upgrade the entire Ubuntu system.

1. Update the package list

$ sudo apt-get update

2. Install Apache web server

$ sudo apt-get install apache2

The following NEW packages will be installed:

apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap

If you encounter the following errror:

apache2: Could not determine the server’s fully qualified domain name,
using 127.0.0.1 for ServerName

Then do this:

$ sudo nano /etc/apache2/conf.d/fqdn

Enter: ServerName localhost
Ctrl-X to exit and Yes to save the file.

Restart Apache web server:

$ sudo service apache2 restart

To check and confirm installation, do the following:

If you see “It works!”, which is the content of the file /var/www/index.html , then you have successfully installed Apache.

3. Install MySQL

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Enter the password when prompted.

The following NEW packages will be installed:

apache2-mpm-prefork libapache2-mod-auth-mysql libapache2-mod-php5filter
libdbd-mysql-per libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl
mysql-client-5.1 mysql-client-core-5.1 mysql-server mysql-server-5.1
mysql-server-core-5.1 php5-common php5-mysql

The following packages will be upgraded:

libmysqlclient16 mysql-common

Set an administrative password for the MySQL root user when prompted.

Run the following to confirm MySQL server has successfully started up.

$ sudo netstat -tap | grep mysql

You should see something like:
tcp 0 0 localhost:mysql *:* LISTEN /mysqld

4. Install PHP

$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql

The following NEW packages will be installed:

libapache2-mod-php5 libmcrypt4 php5 php5-cli php5-mcrypt

The following extra packages will be installed:

libmcrypt4 php5-cli

The following packages will be REMOVED:

libapache2-mod-php5filter

After installation has successfully completed, restart Apache web server

$ sudo service apache2 restart

To check and confirm PHP installation, do the following:

In /var/www , create a text file called “phpinfo.php”, i.e. issue the following command:

$ sudo nano /var/www/phpinfo.php

Enter the following in the file:

<? php phpinfo(); ?>

Ctrl-X to exit and save the file.

Open your web browser, and load this page: http://localhost/phpinfo.php. You should see a description of PHP5 configuration.

That’s it! You’ve successfully installed Apache, MySQL and PHP on Ubuntu Server 11.10.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s