How to install wordpress on LAMP stack ( Ubuntu 14.04 LTS Server )

In this tutorial we will learn, how to install wordpress on LAMP stack. We are doing this practical on Ubuntu 14.04 LTS Server edition. In our last post, we have written step by step tutorial on “How to setup LAMP stack on Ubuntu 14.04 LTS Server” .

WordPress , a very popular Open Source CMS widely use in Internet Web world. It has been reported that millions of Website and blogs are based on WordPress.

WordPress is written on PHP langauge and for database primarily MySQL is used. You can alternatively also use MariaDB instead of MySQL . For WordPress, it is recommended to use Apache HTTP Server but with the Nginx Web server WordPress performance is awesome and speedy.

At the time of writing this post, WordPress stable version 3.9.1 was available.

In this tutorial we will install WordPress on LAMP stack. Follow the given below steps –

(1) Install Apache, PHP and MySQL Server :

First setup the LAMP stack by installing Apache , PHP and MySQL .In Ubuntu 14.04 LTS , by default Apache version 2.4 will be installed . We will also install PHP 5.x and MySQL Server 5.6 version.

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

During installation, it will ask for setting MySQL root password. Give the root password and reconfirm once again. See the below given screenshot how it appears.

mysql Ubuntu 14.04

MySQL Server 5.6 Ubuntu 14.04

(2) Download latest WordPress :

We will download latest WordPress with the help of command line. Use given below wget command

cd ~
wget wordpress.org/latest.tar.gz

Note: cd ~ command will change directory to currently login user’s home directory. In above we will download the WordPress in user’s home directory

(3) Extract the WordPress tar ball

Now extract the WordPress tarball i.e latest.tar.gz to /var/www/html directory

sudo tar -xvzf ~/latest.tar.gz -C /var/www/html

After extraction you can find the wordpress directory inside /var/www/html

sharad@ubuntu:~$ ls -lhrt /var/www/html/
total 4.0K
drwxr-xr-x 5 www-data www-data 4.0K May 11 05:20 wordpress
sharad@ubuntu:~$

(4) Create MySQL user for WordPress Application

We will create a application user for WordPress in MySQL Database Server . The user will have only access to WordPress database. It is good for security point of view, to create a mysql user which has all privileges to only Application’s database.

First check if mysql service is running. Generally in Ubuntu, just after installation of MySQL, the service started automatically. Yet, we should follow the common practice . ( tip for new Linux System Admins)

sudo service mysql status

In case, the mysql service is stopped. Then start the service .

sudo service mysql start

or

sudo service mysql restart

Login as MySQL root user. It will prompt for password.Give mysql’s root password

mysql -u root -p

After login, you will get mysql prompt like this mysql>

NOTE : In below given commands, you do not have to write mysql> . It is just a mysql prompt

Create database for WordPress. I am giving database name as “wordpress”

mysql> create database wordpress;

Create mysql user for WordPress application and set its password in liner command.
Replace P@ssword with your password

mysql> create user 'wpuser'@'localhost' identified by 'P@ssword' ;

Grant all privileges to WordPress user called “wpuser” which we have created in just above given command.

mysql> grant all on wordpress.* to 'wpuser'@'localhost';

Reload the privileges (do not forget this step at the end)

mysql> flush privileges;

(5) Configuring Apache HTTP Server for WordPress

For this practical we will setup IP Based Virtual hosting in Apache. If you have domain name, you can also configure the Name Based Virtual Hosting in Apache.

First get your server IP address by using ifconfig command.

I will use the IP address 192.168.56.101. You can replace with your IP Address

sharad@ubuntu:~$ ifconfig 
eth0      Link encap:Ethernet  HWaddr 08:00:27:ad:5f:7b  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fead:5f7b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11037 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4446 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12811912 (12.8 MB)  TX bytes:340279 (340.2 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:75:2b:db  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe75:2bdb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7819 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9325 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1027489 (1.0 MB)  TX bytes:10030301 (10.0 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:201 errors:0 dropped:0 overruns:0 frame:0
          TX packets:201 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:19992 (19.9 KB)  TX bytes:19992 (19.9 KB)

sharad@ubuntu:~$ 

Create apache wordpress configuration file. I use vi, you can use your favorite file editor.

sudo vi /etc/apache2/sites-enabled/wordpress.conf

And paste the below given contents in file wordpress.conf and save it.



	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html/wordpress
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined


(6) Restart the Apache HTTP Server

After creating wordpress apache’s configuration file, restart the Apache service

sudo service apache2 restart

(7) Create wp-config.php file :

Now we will create wp-config file in wordpress directory. The short cut method is just copy the wp-config-sample.php file and then give the database information in the wp-config.php file.

sudo cp -p /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Now edit the file wp-config.php . Give the database information in the file.

Database Name: wordpress
Database User’s Name: wpuser
Database User’s password: P@ssword
Database Host Address: localhost (If it is remote Database server, give its IP Address)

Below given is the reference from wp-config.php file

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'P@ssword');

/** MySQL hostname */
define('DB_HOST', 'localhost');

(8) Follow final WordPress installation step from Web interface

Open the Web browser (example: Chrome/firefox/Opera etc.) . Now type the ‘IP Address’ of Server in address bar of web browser.
Here,our IP address of Server was 192.168.56.101. Replace it with your actual IP Address.

Example:

http://192.168.56.101

It will redirect to wp-admin/install.php itself.
Set the values Site Name, Username (for wordpress admin dashbaord), admin password, your email address and check box is conditional in case you want your blog to be listed in search engine (eg. google.com , yahoo.com, bing.com etc. )

Install wordpress Ubuntu 14.04

After filling all the details, press “Install WordPress” button.

Now you will get the below given screen on successful installation.

wordpress installation

Login into WordPress Admin dashboard

To login into WordPress Admin Dashbaord, open web browser and append wp-admin in URL with IP-Address or domain name.

Example. (Replace 192.168.56.101 with your Server IP Address)

http://192.168.56.101/wp-admin

Give WordPress user name and password for login into WordPress Admin dashboard.

Wordpress

After login, you will see many options in admin dashboard. Now you can start creating post,pages,changing theme, adding plugins and much more.

Wordpress installation

Explore the WordPress, it is quite easy. Start creating your blog or website. You can visit wordpress.org for more information .

To see your wordpress blog/website. Simply type the IP Address of server Or domain name in URL field of web browser.

wordpress

5 thoughts on “How to install wordpress on LAMP stack ( Ubuntu 14.04 LTS Server )”

  1. We may need to adjust the permissions however. This depends on how you prefer to work. WordPress will generate the necessary rewrite rules for you. If it has write permissions to this file, it can implement the rules automatically. If it does not, you will have to manually edit this file to add the correct rules.

    Reply
  2. Hello Sharad-

    Many thanks for your instructions! After following all steps you have outlined I’m receiving the following message when trying to update plugins: “To perform the requested action, WordPress needs to access your webserver. Please enter your FTP credentials to proceed.”

    I’m sure this must be a simple fix but I have yet to find a working solution. I’ve tried adding define(‘FS_METHOD’,’direct’); which kind of worked but then I got permissions issue writing to parent folder. Any suggestions?

    Thanks!

    Reply
  3. Hello.. I have done all the steps on my EC2 instance to install wordpress.
    But on step
    ” 8) Follow final WordPress installation step from Web interface
    Open the Web browser (example: Chrome/firefox/Opera etc.) . Now type the ‘IP Address’ of Server in address bar of web browser.”

    I’m still getting the Apache2 Ubuntu Default Page and the message “It works”

    I have also tried putting the http://my-IP/wp-admin/install and get this error:
    The requested URL /wp-admin/install was not found on this server.

    Or http://my-IP/wordpress/
    get this error: Error establishing a database connection

    Please advice on what I’m missing. I have follow the details on this tutorial step by step.
    Thanks

    Reply
    • Hello Manuel,

      When we get the error : Error establishing a database connection
      Check following things –

      1) database Username and password in wp-config.php
      2) Database Host in wp-config
      3) Check the mysql server is running
      4) With the help of command line , use all db credential info and try to connect to mysql server

      Regards
      Sharad

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.