1. Home
  2. Linux
  3. Ubuntu
  4. How to Install LAMP on Ubuntu 16.10/16.04 and Linux Mint 18

How to Install LAMP on Ubuntu 16.10/16.04 and Linux Mint 18

How to Install LAMP on Ubuntu 16.10/16.04 and Linux Mint 18
How to Install LAMP on Ubuntu 16.10/16.04 and Linux Mint 18

In this tutorial we will teach you how to install LAMP stack before progressing to Install WordPress

Step 1: Install Apache Web Server

Install the Apache web server and type in the command shown below.

$ sudo apt-get install apache2 apache2-utils

You will need to enable Apache2 web server for it to start up at system boot time and, as well, startup the service as follows.

$ sudo systemctl enable apache2
$ sudo systemctl start apache2

To check if the server is running, open up your browser and enter the following: ‘http://server_address’.
The Apache2 default page will show up if the web server is up and running.
Remember: The Apache default root directory is located in ‘/var/www/html’, and all of your web files will be stored in this directory.

Step 2: Install MySQL Database Server

For this next step, you must install the MySQL database server by typing in the following command.

$ sudo apt-get install mysql-client mysql-server

While the package is being installed, you will be prompted to choose the root user password for MySQL. Type in a secure password before pressing the OK button twice to continue further.
The database server deployment is not quite secure yet. For that reason, type in the below command to maximize its security.

$ sudo mysql_secure_installation

First, you will be requested to install the ‘validate_password’ plugin. You will need to type in ‘Y/Yes’ and press Enter as well as choosing the default password strength level.
It is important to note that, if you do not want to change the root password, type ’N/No’ when requested to do so. Answer ‘Y/Yes’ for the next subsequent questions.

Step 3: Install PHP and Modules

For this step, install PHP and a few other modules in order for it to work with the web and database servers using the below command.

$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd

Next, to test if php is working along with the web server, you will have to create an ‘info.php’ file inside ‘/var/www/html’.

$ sudo vi /var/www/html/info.php

Copy & paste the following command into the file, save it and exit.


When you are done with that, open the web browser and type in the address ‘http://your_server_address/info.php’.
You will be able to view the php info page below as confirmation.

Step 4: Install WordPress CMS

In this step you will need to download the latest WordPress package and extract it by typing the following commands into the terminal.

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

Next, move the WordPress files from the extracted folder to the Apache default root directory ‘/var/www/html/‘.
Then, set the right permissions on the website directory which will give ownership of the WordPress files to the web server as shown in the following command.

$ sudo chown -R www-data:www-data /var/www/html/
$ sudo chmod -R 755 /var/www/html/

Step 5: Create WordPress Database

Type in the command below and the root user password, then press Enter to pass to the MySQL shell.

$ mysql -u root -p

In the MySQL shell, you will need to type in the below commands before pressing ‘Enter’ after every line of a MySQL command.
Do not forget to use your own, correct, values for ‘database_name’, ‘databaseuser’, as well using a strong and secure password instead of ‘databaseuser_password’.

mysql> CREATE DATABASE wp_myblog;
mysql> GRANT ALL PRIVILEGES ON wp_myblog.* TO 'your_username_here'@'localhost' IDENTIFIED BY 'your_chosen_password_here';
mysql> EXIT;

Move to the ‘/var/www/html/‘ directory and rename the existing.
wp-config-sample.php to wp-config.php:

$ sudo mv wp-config-sample.php wp-config.php

Then, update your database information in the MySQL settings section.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** 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', '');

Next, restart the web server and MySQL service with the following command.

$ sudo systemctl restart apache2.service
$ sudo systemctl restart mysql.service

Open your browser and go to your server address: ‘http://server-address’ and you will get the welcome page.
Read the page and then click on ‘Let’s go!’ to go further and fill all requested information.

Updated on December 23, 2018

Was this article helpful?

Related Articles


Leave a Comment

[apsl-login-lite login_text='Please login with a social account']