How to Install WordPress on Ubuntu with Apache, PHP and MariaDB

By default when folks talk about the LAMP stack, they’re usually referring to Linux, Apache2, MySQL and PHP. This is the default stack to runs popular PHP based applications on Linux systems. Today’s post shows you how to install LAMP with MariaDB instead of MySQL database server.

WordPress requires LAMP to function. The LAMP stack is a collection of open source software packages that power majority of the websites online today. It is a acronym for Linux, Apache2, MySQL and PHP.

To get WordPress working you must first install LAMP. To do that, follow the steps below:

Step 1: Install Ubuntu Linux

Ubuntu Linux is my preferred Linux OS. It’s easy use, stable and probably got more support than other Linux distributions. If you’re a new user, you should probably start with Ubuntu. For this tutorial, Ubuntu our Linux preferred distribution.

Get Ubuntu installed with root access and run the commands below to update it.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

Step 2: Install Apache2 Web server

After installing Ubuntu and updating it, run the commands below to install Apache2 web server.

sudo apt-get install apache2

Step 3: Install MariaDB database server

After installing Apache2 web server, run the commands below to install MariaDB database server.

sudo apt-get install mariadb-server mariadb-client

When you’re done installing the database server above, run the commands below to secure it with a root password.

sudo mysql_secure_installation

You’ll get prompted to answer the below questions.. use this guide below to answer.

Enter current password for root (enter for none): PRESS ENTER
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next, continue below to create WordPress database and user account.

Step 4: Create WordPress database and user

After installing MariaDB server, run the commands below to logon to the database server

sudo mysql -u root -p

You’ll be prompted to enter a root password. Type the one you created above for the root user.

Next, run the SQL commands below to create a database called wordpressdb.

CREATE DATABASE wordpressdb;

Run the commands below to create a new user named wpuser with new password, and grant the user access to the wordpressdb databases.

GRANT ALL ON wordpressdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'type_new_password_here';

After that, run the commands below to save your changes and exit.


Step 5: Install PHP and its Modules

After creating WordPress database and user account, run the commands below to install PHP and other modules for WordPress.

sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc

Step 6: Download WordPress content

Now that all the packages and server required by WordPress are installed, go and download WordPress content from online.

Use the commands below to do that.

cd /tmp/ && wget

Then run the commands below to extract the download folder and move WordPress content to Apache2 default document root on Ubuntu servers. The default document root is at /var/www/html.

tar -xzvf latest.tar.gz
sudo cp -R wordpress/* /var/www/html

Next, run the delete Apache2 default index.html file from document root.

sudo rm -rf /var/www/html/index.html

Step 7: Configure WordPress

After Downloading WordPress, follow the steps below to configure WordPress with the database connecting settings created above.

First, run the commands below to create WordPress wp-config.php settings file from its sample.

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

Then open wp-config.php file and make the following highlighted changes to reference the database and user you created above.

sudo nano /var/www/html/wp-config.php

When the file opens, make the changes and save.

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

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

/** MySQL database password */
define('DB_PASSWORD', 'new_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', '');

After configuring WordPress settings, you next step will be to change Apache2 directory permissions so WordPress can function properly. To do that, run the below commands

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

Finally, run the commands below to enable some important Apache2 modules and restart the server

sudo a2enmod headers
sudo a2enmod rewrite

Restart Apache2

sudo systemctl restart apache2

Then open your web browser and browse to the server host name or IP address

You should see WordPress default setup page ready for you to create a user account with password. After that, WordPress should function perfect.

WordPress default setup page


  1. Hello, i did as the tuto said but when i type in my browser, it just say unable to connect what am i suposed to do?

    1. You must replace the IP address in the tutorial with the IP address of your server or computer. On your Ubuntu machine, type ifconfig to see the IP address of the machine.

  2. Perfect explanation !!
    Thx 😉

  3. video downloader

    An attention-grabbing discussion is price comment. I believe that you should write extra on this matter, it won’t be a taboo topic but generally individuals are not sufficient to speak on such topics. To the next. Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

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