How to Install LAMP and WordPress on Ubuntu

LAMP (Linux, Apache, MySQL and PHP) is a package name for the installation of Apache server, MySQL database and PHP performed on a Linux machine. Similar packages (also available as application) named as WAMP and MAMP are available for Windows and Mac operating systems respectively. To install and use a server based application like WordPress (for development and testing purpose) on a local machine, you need to first install these packages on the machine. Recently, I installed LAMP and WordPress on couple of Ubuntu machines and here is what I did.

Installing LAMP first!

Open the terminal on Ubuntu. Execute below commands to complete the tasks mentioned,

1. Install Apache

sudo apt-get install apache2

2. Install MySQL

sudo apt-get install mysql-server

3. Install PHP

sudo apt-get install php5 libapache2-mod-php5

4. Restart Apache Server

sudo service apache2 restart

Now open any web browser e.g. Firefox and open the URL http://localhostand it should show a message saying ‘It Works’.

Install WordPress

As the Apache server is running on your Ubuntu machine, now it is time to go ahead and start with the installation of WordPress on localhost. Follow the steps below,

1. Download the latest version of WordPress

wget http://wordpress.org/latest.tar.gz

Unzip the same,

tar -xzvf latest.tar.gz

Unzipped folder ‘wordpress’ should appear inside the Home directory of Ubuntu.

Create Database and User

For the installation of WordPress, you need to create a database in MySQL and also assign a username and associated password with full authority of that database to the user.

Login to MySQL shell to execute MySQL commands from terminal,

mysql -u root -p

Execute below commands one by one on terminal,

CREATE DATABASE wordpress;

CREATE USER wordpressuser@localhost;

SET PASSWORD FOR wordpressuser@localhost=
PASSWORD("password");

GRANT ALL PRIVILEGES ON wordpress.* TO
wordpressuser@localhost
IDENTIFIED BY 'password';

FLUSH PRIVILEGES;

exit

Now you are out of MySQL shell. It’s time to move on.

Create wp-config.php file (Configuration File)

WordPress packages comes with wp-config-sample.php and by editing the content of this file, we can create wp-config.php. Execute following command on terminal to create a copy of the sample file.

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Open wp-config.php for editing,

sudo nano ~/wordpress/wp-config.php

Update Database, Username and Password in wp-config.php file then save and exit.

Time to move the ‘wordpress’ folder to /var/www/ folder. Execute following command on terminal.

sudo rsync -avP ~/wordpress/ /var/www/

Change permission for the folder ‘wordpress’. first go inside the folder,

cd /var/www/

Give read-write permission to the Apache user,

sudo chown username:www-data /var/www -R
sudo chmod g+w /var/www -R

Done. Go ahead and open the URL http://localhost/wordpress/wp-admin on browser.

If you are seeing the error message as “Your PHP installation appears to be missing the MySQL extension which is required by WordPress“, then go ahead and execute the following command on terminal,