How to setup local WordPress environment on Ubuntu

This article will teach you how to set up a Linux development machine so you can work on your WordPress site using the same tools as your server i-e: setup local WordPress environment on ubuntu.
Although most WordPress websites are hosted on a Linux server, many developers will create their sites using a Windows PC using software like WAMP.
It’s best to utilize a Linux computer, in my view, so that your development environment closely resembles the production server.
We’ll assume you’re running Ubuntu 16.04 as your workstation for this guide (either physical or as a virtual machine). You’ll learn how to set up Apache, MySQL, PHP, and Postfix, as well as how to build a WordPress test site.

Install the Apache Web Server – wordpress environment on Ubuntu

Because many WordPress plugins function best with Apache, we’ll be utilizing it instead of NGINX. This is due to the fact that they require access to the .htaccess file. To install Apache, follow the steps below.

sudo apt-get update
sudo apt-get install apache2

Apache should now be installed, and you should be able to serve HTML pages from the /var/www/html document root.

You may check this on your local PC by going to

wordpress environment on Ubuntu img1

By substituting with the Ubuntu system’s IP address, you should be able to view the site from a distant machine on your network.

wordpress environment on Ubuntu img2

Install the MySQL Database Server

It’s time to install MySQL now that we’ve got the Apache webserver up and running. MySQL is a relational database management system that we’ll use to build a database for our WordPress site later on.

Using the terminal, type the following command to install MySQL.

sudo apt-get install mysql-server

The package setup screen will appear when the installation has begun. You’ll be prompted to change the root MySQL user’s password. To complete the installation, type a password, hit Enter, repeat the password, and then press Enter again.

Install the PHP Runtime

WordPress would not operate if we copied the WordPress files into the default document root folder since it requires PHP to render dynamic content. We’ll install the PHP runtime and test that Apache can render PHP scripts in the steps that follow.

Run the following command to install PHP:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Make the following modifications to Apache:

sudo service apache2 reload

PHP scripts should now be allowed to run. We can test this by generating a new file named info.php and putting it in the root directory of the default website.

sudo vim /var/www/html/info.php

Save the file after adding the following to it:


On the local system, go to to test if the PHP script is displayed.

wordpress environment on Ubuntu img3

Install WordPress environment on Ubuntu

We’ll install WordPress under the default site’s document root in the stages that follow.

Create the MySQL Database

To use the MySQL command line tool, go to:

mysql -u root -p

You’ll be prompted for the root password (assigned in Step 2). To create the WordPress database, enter the password and then run the following command:


To quit the MySQL command-line tool, type exit and then press Enter.

Install and Configure WordPress

Run the following command to remove any existing files from the default sites document root folder:

sudo rm -Rf /var/www/html/*

Run the command to download and extract the latest WordPress installation files:

sudo wget -qO- | sudo tar xvz -C /var/www/html --strip-components=1

To allow Apache to alter the WordPress files, change the owner and group to www-data:

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

On the local PC, go to and hit the Let’s Go button to begin the WordPress installation.

wordpress environment on Ubuntu img4

Click Submit after entering the name of the database we established earlier wpdemo, the login (root), and the database password.

wordpress environment on Ubuntu img5

To begin the installation process, click the Run the Install option.


After entering the site’s details, click Install WordPress.


WordPress should now be installed, and you should be in the admin area.

Configure Clean URLs

The URLs do not search engine friendly by default. We’ll need to activate the Apache mod rewrite module, alter the virtual host settings, and change the Permalink structure in WordPress to enable clean URLs. Follow the procedures outlined below to do this.

Use the following command to enable the Apache mod-rewrite module.

sudo a2enmod rewrite

Make changes to the default virtual host file.

sudo vim /etc/apache2/sites-enabled/000-default.conf

Just before the ending, add the following.

<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All

To implement the modifications, save the file and restart Apache.

service apache2 restart

Navigate to Settings, then Permalinks, to change the Permalink structure. Then click Save Changes after selecting the Post name choice or the structure you like.


You should now be able to use a search engine-friendly URL to access the hello-world article.


That is all there is to it. You should now be able to work on your WordPress site or create Themes and Plugins using a development environment that closely resembles a Linux production server.


We learned how to install Apache, MySQL, PHP, and Postfix on Ubuntu Desktop in order to set up a Linux development environment for working with WordPress sites in this article. Although the emphasis was on putting up a WordPress site, this configuration could be used for any PHP development.

That’s all for this article if you have any confusion contact us through our website or email us at [email protected] or by using LinkedIn

Leave a Comment