How to Setup a WordPress Development Environment on an Ubuntu Desktop Machine
Most WordPress websites are hosted on a Linux server and yet a lot of developers will use a Windows machine and a program like WAMP to develop their sites. In my opinion, it’s better to use a Linux machine so that your development environment closely matches the production server.
In this tutorial, we will assume you are using Ubuntu 16.04 as your workstation (either physical or as a virtual machine). You will learn how to install Apache, MySQL, PHP and Postfix and then configure a test WordPress site.
Step 1: Install the Apache Web Server
We will be using Apache instead of NGINX because a lot of WordPress plugins work best with Apache. This is because they need the ability to edit the .htaccess file. Follow the instructions below to install Apache.
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 default document root found at /var/www/html.
You should also be able to browse the site from a remote machine on your network by replacing 127.0.0.1 with the IP address of the Ubuntu machine.
Step 2: Install the MySQL Database Server
Now that we have the Apache web server installed and running, it is time to install MySQL. MySQL is a relational database management system and we will use it later to create a database for our WordPress site.
You can install MySQL by running the following command at the terminal.
sudo apt-get install mysql-server
The installation will start and the Package configuration screen will load. You will be asked to enter a new password for the root MySQL user. Type in a password, press Enter, repeat the password and then press Enter again to finish the installation.
Step 3: Install the PHP Runtime
If we were to copy the WordPress files into the default document root folder, WordPress would not work because it requires PHP to render dynamic content. In the following steps we will install the PHP runtime and test to make sure Apache renders PHP scripts.
Change the owner and group of the WordPress files to www-data so that Apache can edit the files:
sudo chown -R www-data:www-data /var/www/html
Start the WordPress installation by browsing to http://127.0.0.1 on the local machine and pressing the Let’s Go button.
Enter the name of the database we created above (wpdemo), enter the username (root) and enter the database password then click Submit.
Click the Run the Install button.
Enter the Site Details and then click Install WordPress.
WordPress should now be installed and you will be logged into the admin section.
Configure Clean URLs
By default the URL’s are not search engine friendly. To enable clean URL’s we will need to enable the Apache mod_rewrite module, modify the virtual host configuration and change the Permalink structure in WordPress. This can be done by following the steps below.
Enable the Apache mod_rewrite module with the following command.
sudo a2enmod rewrite
Modify the default virtual host file.
sudo vim /etc/apache2/sites-enabled/000-default.conf
Add the following just before the closing
Save the file and then restart Apache to apply the changes.
service apache2 restart
Change the Permalink structure by navigating to Settings then Permalinks. Select the Post name option or the structure you like best then click Save Changes.
You should now be able to load the hello-world post using a search engine friendly URL.
That’s it. You should now be ready develop your WordPress site or create Themes and Plugins from a development system that closely matches a Linux production server.
In this tutorial, we learned how to install Apache, MySQL, PHP and Postfix on Ubuntu Desktop so that we could create a Linux development environment for working with WordPress sites. Although, the focus was on setting up a WordPress site, you could use this setup for any kind of PHP development.