Latest LQ Deal: Linux Power User Bundle
Go Back > Blogs > beachboy2
User Name


Rate this Entry

Installing WordPress on a Linux (LAMP) Server

Posted 03-16-2017 at 10:15 AM by beachboy2
Updated 03-19-2017 at 11:47 PM by beachboy2

Install an Apache2 web server on Linux with PHP 7.0 (mod_php) and MySQL support. Then install WordPress and create your own website or blog, either just for testing/learning, or live transmission via a web host.

is short for Linux, Apache, *MySQL, PHP.
A LAMP setup is perfect for a Content Managed System like Wordpress:

(*Alternatively, you can use MariaDB from the original developers of MySQL. It is guaranteed to stay open source).

It is a good idea to test your WordPress website locally, using localhost (http:/, before uploading it later to your live server, hopefully without any errors, bugs or security flaws.

To move your website later, I recommend Method 2 on “How To Move Your WordPress Website From localhost To Live Server”:

You may prefer to just run a WordPress “test” website on a LAMP server using a spare PC/laptop via localhost and never actually go “live” on a hosted production server.

I first installed Linux Mint 18.1 MATE as the base Linux distribution, as opposed to Ubuntu Server 16.04.2, CentOS or Debian etc. The choice is entirely yours.

Install Apache

To install Apache, enter:

sudo apt-get install apache2
Enable and start your apache (as root):

sudo su
systemctl enable apache2
systemctl start apache2
systemctl status apache2
Test Apache:

Open your web browser and navigate to http://localhost/ (localhost is http:/

Install MySQL (or MariaDB):

sudo apt-get install mysql-server mysql-client
During installation, you will be asked to setup the MySQL “root” user password. Enter the password myrooting874tootING?! and click OK. Repeat.

MySQL is being installed now.

You can verify the MySQL server status using command:

sudo systemctl status mysql
Next, harden the security on MySQL using the following configuration script:

sudo /usr/bin/mysql_secure_installation
Apart from the current root password, which is retained, select Y (Yes) to everything else.

Install PHP 7.0

Install PHP with following commands:

sudo apt-get update 
sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Restart apache2:

sudo systemctl restart apache2
Then test your php:

To test PHP, create a sample “testing.php” file in the Apache document root folder, which is: /var/www/html

sudo nano /var/www/html/testing.php
Copy and paste the following lines to the file:

Save the changes by using Ctrl+O, then pressing Enter. Exit using Ctrl+X.

Restart apache2 service:

sudo systemctl restart apache2
Navigate to http://localhost/testing.php

It will display all the details about php such as version, build date and commands etc.
Next, for security, remove the “testing.php” file:

sudo rm -f /var/www/html/testing.php
Install phpMyAdmin

sudo apt-get install phpmyadmin
Select the web server that should be automatically configured to run phpMyAdmin. In my case, it is apache2.

Use the spacebar to insert * inside brackets for apache2, press Tab and Enter. Ignore lighttpd.

The phpMyAdmin must have a database installed and configured before it can be used. This can be optionally handled by dbconfig-common.

Select ‘Yes’ to configure database for phpmyadmin with dbconfig-common.

Enter MySQL application password (rarely used) for phpmyadmin: somethingorother
(NOT myrooting874tootING?! which is the root MySQL password).
Re-enter password.

Success! phpMyAdmin installation is installed.

If you followed all steps carefully, phpMyAdmin should work just fine.
In case phpMyAdmin is not working, please do the following:
Open terminal, and type:

sudo nano /etc/apache2/apache2.conf
Add the following line at the end:
Include /etc/phpmyadmin/apache.conf
Save and Exit.

Restart apache service:
sudo systemctl restart apache2
Access phpMyAdmin Web Console

Navigate to:
http://localhost/phpmyadmin/ from your browser.

Enter your MySQL username and password which you have given in previous steps. In this case: root and myrooting874tootING?!

You will be redirected to phpMyAdmin main web interface.
From here, you can manage your MySQL databases from phpMyAdmin web interface.
Your LAMP stack is ready to use.
Wordpress Database Initialisation

NB wp-config is located at: /var/www/html/wordpress/wp-config.php

Create the database for Wordpress as follows:

Login to the MySQL database as root user:

sudo mysql -u root -p
Type the MySQL root password myrooting874tootING?! and press Enter.

At the mysql > prompt create a database with:

Name: fredjdb
Database user: fredj and the
Database password: amotv769TZG?$

THIS IS STEP 2 (referred to later when installing WordPress).

At the mysql > prompt, enter the following prompts, including the semi-colon (;) at the end, separately and press Enter:

CREATE USER fredj@localhost IDENTIFIED BY 'amotv769TZG?$';
GRANT ALL PRIVILEGES ON fredjdb.* TO fredj@localhost;
Then exit the MySQL shell using the following commands and pressing Enter:

Next, restart services using:

sudo systemctl restart apache2
sudo systemctl restart mysql
Install WordPress

Go to:
Download wordpress-4.7.3.gz to Desktop and then extract the wordpress folder:

cd Desktop           
tar zxf wordpress-4.7.3.tar.gz
Move the extracted wordpress folder on Desktop to /var/www/html/ using:

sudo mv /home/fred/Desktop/wordpress/ /var/www/html/
Now DELETE index.html.

If both index.html and index.php are present, index.html loads first overriding the index.php file:
Remove the index.html file from the html folder containing wordpress:

sudo rm -r /var/www/html/index.html
Now set appropriate permissions for the wordpress directory. NB You MUST be root user to do this!

sudo su
chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
Next, create the uploads directory beneath the wp-content directory at our document root. This (wp-content) will be the parent directory of our content:

sudo mkdir -p /var/www/html/wordpress/wp-content/uploads
We need to allow the web server itself to write to this directory. We can do this by assigning user and group ownership of this directory to our web server user www-data.

This will allow the web server to create files and directories under this directory, which will permit us to upload content to the server.
Proceed like this, as root user:

sudo su
chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads
Now proceed to the web installation of Wordpress.

Go to the URL http://localhost/wordpress/ in your web browser. The WordPress installer will show up.

Select English language and press Continue:

The Welcome screen shows up in the selected language. Click on Let's go and type in the Login details of the WordPress database that was created in STEP 2 previously.

The database host is "localhost" and the prefix can be left at its default. Then click on the "Submit" button.

Wordpress saves the database configuration details to the file:

Click on "Run the install" to proceed to the next part of the installer.

Now enter some details for the Blog like website title, admin username, password and email address.

Site Title = Fred’s Blog
Admin Email = fred@some_email_address
Username = Fred
Admin password = wqm97168LV

Press InstallWordpress to finish the installation.

Next, access the login page by pressing LogIn:

Type in the credentials that you selected during WordPress installation above. The WordPress Dashboard will then appear.

Later, access your live WordPress website via:

For Reference

sudo systemctl start apache2
sudo systemctl start mysql
WP LOGIN: localhost/wordpress/wp-login.php

Welcome page: localhost/wordpress/index.php/welcome/

Useful links (thanks to all, especially Till Brehm on HowToForge)



Ubuntu Server guides:

Wplift Guide:


How to Forge:

Ubuntu Desktop LAMP Development server:

Hardening WordPress Security:

MySQL Security (very important):

Installing LAMP from source code:

LAMP Server with WordPress (Raspberry Pi):

How To Move Your WordPress Website From localhost To Live Server:

Useful WordPress Plugins


Akismet Anti-Spam:

PDF Embedder:

Easy Updates Manager:

Gallery Manager:
Posted in Uncategorized
Views 139 Comments 1
« Prev     Main     Next »
Total Comments 1


  1. Old Comment
    Useful WordPress Plugins: wordfence

    Good Job!
    Posted 03-16-2017 at 11:26 AM by Habitual Habitual is offline


All times are GMT -5. The time now is 12:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration