How To Install WordPress with LAMP Stack on Ubuntu 16.04

How to Install WordPress with LAMP stack on Ubuntu 16.04

WordPress is one of the world’s most popular content management systems (CMS). It is a free and open-source platform, which is used by millions of people for running blogs, business websites, e-commerce stores and much more.

It is a powerful and very easy to use website creation tool. With a large variety of plugins and themes to choose from, it provides very high customization options and almost endless possibilities for you to develop and make a unique, one of a kind website.

In this tutorial, we will show you how to install the latest WordPress version on your Ubuntu 16.04 VPS. We will also show you how to install and configure a fully functional LAMP stack, consisting of Ubuntu 16.04 operating system, Apache web server, MySQL database server and PHP 7. Let’s get started.

Requirements:

  • For the purposes of this tutorial, we will use an Ubuntu VPS. Our Ubuntu 16.04 VPS already comes preinstalled with a fully working LAMP stack. However, we will still go through all the necessary steps and show you how to install and configure the LAMP stack yourself, in case you are doing this on a clean server.
  •  Full SSH root access or a user with sudo privileges is also required
  • A valid domain name for accessing your WordPress site (optional)

Step 1: Connect to your server and update your system

Before we begin, let’s connect to your VPS via SSH as user root and update your system software to the latest available version.

To connect to your server via SSH as user root, use the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.

Once logged in, make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

If this is your first time logging into your brand new Ubuntu VPS, you can also check our First Steps After Getting An Ubuntu VPS tutorial for some additional basic initial server setup and security tips.

Step 2: Install the Apache Web Server

In this section, we will show you how to install the Apache Web Server on your VPS. Apache is a fast and secure web server and one of the most popular and widely used web server in the world.

To install the Apache web server, run the following command:

apt-get install apache2

After the installation is complete, you should start and enable Apache to start automatically upon server reboot with:

systemctl start apache2
systemctl enable apache2

To check the status of your Apache server and make sure it is up and running, you can run the following command:

systemctl status apache2

To verify that Apache is running, you can also open your web browser and enter your server IP address, (e.g. http://your_server_ip_address). If Apache is successfully installed you should see the Apache default welcome page.

Step 3: Install the MySQL Database server

The next step is to install the MySQL database server which will be used for the data storage of your WordPress site. MySQL is one of the most popular database management systems. To install MySQL on your system, execute the following command and press Y to continue:

apt-get install mysql-server

During the installation, you will be asked to enter a password for the MySQL root user. Make sure you enter a strong password.

In order to improve the security of your MySQL server, we recommend that you run the mysql_secure_installation script by typing the following command:

mysql_secure_installation

This script will help you to perform important security tasks like setting up a root password, disable remote root login, remove anonymous users etc.

After you have answered all the questions you can now go ahead and start the database server and enable it to automatically start upon boot, with:

systemctl start mysql
systemctl enable mysql

Step 4: Install PHP

The last step of our LAMP stack setup is to install PHP. WordPress is a PHP based CMS, so we need PHP for processing the dynamic content of our WordPress site.

We will also include some additional modules, in order to help PHP to connect with our Apache and MySQL, as well as some additional modules which will be required by our WordPress site.

To do this, type the following command:

apt-get install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-mbstring php7.0-gd php7.0-xml php7.0-xmlrpc php7.0-intl php7.0-soap php7.0-zip

In order to test if PHP is working properly, we can place a file called info.php inside your Apache web server root directory (/var/www/html/).
You can create the file with the nano text editor:

nano /var/www/html/info.php

Enter the following content inside the file and save it:

<?php
phpinfo();
?>

Finally, restart the Apache server by typing:

systemctl restart apache2

When this is done, you can navigate to this page: http://your_server_ip_address/info.php in your web browser, and you will see the following page showing your current PHP configuration (you can remove this file after you verify your PHP installation):

Install WordPress with LAMP Stack on Ubuntu 16.04

That means PHP is working properly. Additionally, you can also install phpMyAdmin which will allow you to manage your MySQL databases using a graphical user interface (GUI), through your web browser.
Make sure that you check our How to Install phpMyAdmin on Ubuntu 16.04 tutorial.

With this last step, our LAMP stack installation and configuration has been completed. You are also encouraged to check out our How to Secure Your LAMP server tutorial, for some additional tips and instructions on how to secure your LAMP stack.

Step 5:  Install WordPress

We can now move on to the WordPress installation. We will download and place the WordPress installation in the default web server document root directory (/var/www/html).

Let’s move to this directory with:

cd /var/www/html

And download the latest WordPress installation from the official wordpress.org site with wget:

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

Then, extract the file with:

tar -xzvf latest.tar.gz

All the WordPress files will be now placed in the wordpress directory in /var/www/html/wordpres

We also need to set the correct permissions of this directory so our Apache web server can access these files. To give ownership of the WordPress files to our Apache web server, run the following command:

chown -R www-data:www-data /var/www/html/wordpress

Step 6: Create a database for WordPress

Now, we will create our MySQL database for our WordPress site. Login to your MySQL server with the following command and enter your MySQL root password:

mysql -u root -p

To create a new database for our WordPress installation, run the following commands:

CREATE DATABASE wordpress_db;
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
exit;

You can replace the database name (wordpress_db) and the MySQL user name (wordpreess_user) with your own names. Also, make sure to replace “PASSWORD” with an actual, strong password.

Once the database is created, we will need to add this information to the WordPress configuration file.

Make sure you are inside the /var/www/html/wordpress directory and run the following command to rename the sample configuration file:

mv wp-config-sample.php wp-config.php

Now open the wp-config.php file with your favourite text editor, for example:

nano wp-config.php

And update the database settings, replacing database_name_here, username_here and password_here with your own details:

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

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

/** MySQL database password */
define('DB_PASSWORD', 'PASSWORD');

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

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Save and exit the file.

Restart your Apache and MySQL server with:

systemctl restart apache2
systemctl restart mysql

With this being done, you can now access your WordPress and finish the installation by following the on-screen instructions in your browser at http://your_server_ip_address/wordpress

Step 7: Apache Virtual Host Set Up

If you have a valid domain name, and you want to use it to access your WordPress, you will need to create a new Apache virtual host file. Let’s say we want to access our WordPress with the mydomain.com domain name.

First, run the following command to create the virtual host configuration file :

nano /etc/apache2/sites-available/mydomain.com.conf

And add the following content to the file (you can replace mydomain.com with your actual domain name):

<VirtualHost *:80>

ServerAdmin admin@mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/wordpress

ErrorLog ${APACHE_LOG_DIR}/mydomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/mydomain.com_access.log combined

</VirtualHost>

To enable the virtual host we have just created, run the following command:

a2ensite mydomain.com.conf

Another alternative way to do this is by creating a symbolic link for your virtual host in /etc/apache2/sites-enabled:

ln -s /etc/apache2/sites-available/mydomain.com.conf /etc/apache2/sites-enabled/

Once you enable the virtual host, using either of above methods, you will need to restart the Apache web server:

systemctl restart apache2

If the DNS records are properly configured, and your domain is pointed to your server, you can use it to access your WordPress installation by typing http://mydomain.com in your browser and see the following screen:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Installing WordPress with LAMP Stack

Choose your language and click “Continue”.

Enter your preferred information at the main installation screen, such as site title, username, pasword and email, and click on “Install WordPress”:

Installing your WordPress with LAMP Stack on Ubuntu 16.04

You will be informed that WordPress has been successfully installed and you can now log in to your administration dashboard using the information you have set up previously.

WordPress installation with LAMP Stack on Ubuntu 16.04

How to Install WordPress with LAMP on Ubuntu 16.04

After a successful login, you will be greeted by the WordPress dashboard page:

How do you Install WordPress with LAMP on Ubuntu 16.04

Congratulations! WordPress has been successfully installed on your server. You can now start building and customize your site according to your needs.


Of course, you don’t have to install WordPress with LAMP Stack on Ubuntu 16.04, if you use one of our Optimized WordPress Hosting services, in which case you can simply ask our expert system administrators to install WordPress on Ubuntu 16.04 for you, using the LAMP stack or any other web hosting stack of your choice. They are available 24×7 and will take care of your request immediately. For more updates, you can also check our guides on How to Install WordPress with LAMP Stack on Ubuntu 18.04 and How to Install WordPress with LAMP Stack on Ubuntu 20.04.

PS. If you liked this post, on how to install WordPress with LAMP Stack on Ubuntu 16.04, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

8 thoughts on “How To Install WordPress with LAMP Stack on Ubuntu 16.04”

  1. Great guide. I would like to learn more amazing ideas from your blog.Subscribed.. ! Love to be here. Thanks for a beautiful update.

    Reply
  2. hello thank you for this tutorial I have a problem can you help me I have not managed to configure my domain name in the hosts file with apache2 when I want to go to my site I use the ip / wordpress address to see my site you have a solution

    Reply
    • Can you help with migrating a WordPress site from hosting to local server I have all the files and database I was wondering if there is a guide or easy instructions to follow like you have created for building everything from scratch which is great. I have followed your guide on bringing a lamp server online . So if I have WordPress folders, sql database information what is the easiest way to bring everything back online on my own server?

      Reply
      • You can try this tutorial: https://www.rosehosting.com/blog/migrate-your-wordpress-website-to-a-new-virtual-server/

        Reply

Leave a Comment