Install a Local WordPress Development Environment in Ubuntu

These steps will install a local WordPress development environment, including Apache, MySQL, and PHP, so that you can develop WordPress plugins or themes on your local Ubuntu (or other Linux) computer.

This has been tested on Ubuntu 16.04 LTS, Ubuntu 16.10, and Ubuntu 14.04 LTS. This also works on the LXDE light desktop, or Xubuntu, Lubuntu, etc.

All of the commands on this page (except for one) will be typed into the terminal. Open your terminal with Ctrl + Alt + T.

If you have already installed LAMP locally, then skip down to Create a Database for WordPress. (LAMP stands for “Linux, Apache, MySQL, and PHP,” which is a widely used web server software bundle.)

Install the LAMP server stack (Apache, MySQL, and PHP)

During the installation (which runs with the following commands), you will be prompted to enter a password for MySQL. Write it down since you will need it again.

sudo apt-get update
sudo apt-get install lamp-server^

Set up MySQL

sudo mysql_secure_installation

When it asks you, enter the password which you wrote down above. Then, choose “N” if you don’t want to change your password. Then, choose “Y” for the rest of the questions.

Create a Database for WordPress

mysql -u root -p

When prompted, enter your MySQL password which you created while installing MySQL above.

Create the database. You can change ‘wordpress’ to your desired database name.

CREATE DATABASE wordpress;

Create a database user. You can change ‘wordpressuser’ to your desired username.

CREATE USER wordpressuser@localhost;

Create a password for this user. You can change ‘yourpassword’ to your desired password.

SET PASSWORD FOR wordpressuser@localhost= PASSWORD("yourpassword");

Grant access to the database. Change ‘wordpress’, ‘wordpressuser’, and ‘yourpassword’ accordingly, if you changed them in the previous 3 steps.

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'yourpassword';

Refresh the database:

FLUSH PRIVILEGES;

Exit mysql:

exit

Install WordPress

Move to the local server’s root directory:

cd /var/www/html

Get the latest version of WordPress:

sudo wget https://wordpress.org/latest.tar.gz

Extract WordPress from the package, and create a wp-config.php file.

sudo tar -xzvf latest.tar.gz
sudo cp wordpress/wp-config-sample.php wordpress/wp-config.php
sudo rm latest.tar.gz

Open the wp-config.php file:

sudo gedit wordpress/wp-config.php

You can replace “gedit” above with your text editor of choice, for example, “subl” for Sublime Text.

In the opened file, we’re going to paste in the database name, database username, and database password from the “Create a Database for WordPress” step.

  1. Replace “database_name_here” with your database name. (In the example above, we used “wordpress” as the database name.)
  2. Replace “username_here” with your database username. (In the example above, we used “wordpressuser” as the username for the database.)
  3. Replace “password_here” with your database password.
  4. Save and exit the file.

Move WordPress to the local server’s root directory.

cd ~
sudo rsync -avP /var/www/html/wordpress/ /var/www/html/
sudo rm -rf /var/www/html/wordpress

Grant permissions:

sudo chown -R www-data:www-data /var/www/html
sudo chgrp -R www-data /var/www/html
sudo chmod -R 775 /var/www/html

In your browser, go to localhost/wp-admin/install.php, and complete the WordPress installation steps.

(If the localhost address doesn’t work in your browser, find your local server IP address by right clicking the network icon in your computer’s task bar, then click “Connection Information.” Then, in your browser, type your IP address followed by /wp-admin/install.php, and complete the WordPress installation steps.)

That’s it. Now, you can develop and test WordPress themes and plugins in your own local environment, on your own computer, rather than having to upload everything to an online server/hosting account.

See more: ,

We've 5 Responses

  1. August 11th, 2017 at 11:44 am

    Hello Isabel,
    Thank you for the tutorial.
    In the last step I got thie message:
    “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

    Before I try anything else, I wanted to know if you have a solution for this.

    Thank so much!
    Jorge

    Jorge
  2. November 24th, 2017 at 4:57 am

    Thank you very much, Isabel. Very clear instructions, worked like a charm. This has to be the best tutorial on a WordPress local install on Linux! Keep up the great work!

    Namaste! from Nepal.

    Rajeev Shrestha
  3. January 11th, 2018 at 9:44 am

    Thank you so much for this tutorial, I had been trying with various tutorials in the last few day and could not make it work… Until now

    I just had a couple hiccups:

    1. I could not change the wp-config-sample text error was : “(gedit:3990): WARNING ** Set document metadata failed:…”
    I found a fix which was to enter the command like:

    
    sudo gedit wordpress/wp-config.php &>/dev/null
    
    

    Also, I had to remove the index.html file (added when Apache was installed)

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

    Hope this helps someone out there!

    Capucine

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]