In this tutorial, you will learn how to install and run a WordPress website on your local computer from a virtual machine. Not only will this tutorial show you how to setup WordPress locally, but also how to configure an Nginx server, PHP, and MariaDB database for a complete LEMP server on Ubuntu.
Don’t have a virtual machine yet? Check out this video tutorial to set up an Ubuntu VM for free.
This blog post accompanies the following video tutorial.
1. Install LEMP Server
First, install the Nginx web server, MariaDB (a MySQL server package), and PHP.
sudo apt update sudo apt upgrade sudo apt install nginx mariadb-server php-fpm php-mysql
2. Enable Port Forwarding in VirtualBox
To be able to access the VM’s web server from your local computer, we must open port 80 which is the HTTP port. We can do this in the VM’s settings in VirtualBox under Network > Advanced > Port Forwarding. For the TCP protocol, set the Host Port and Guest Port to 80.
3. Install WordPress
Get the latest version of the official WordPress package and extract it in /var/www/
with the appropriate permissions and ownership.
cd /var/www sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo rm latest.tar.gz sudo chown -R www-data:www-data wordpress sudo find wordpress/ -type d -exec chmod 755 {} \; sudo find wordpress/ -type f -exec chmod 644 {} \;
4. Database Setup
Secure your MySQL installation with the mysql_secure_installation command, accepting the defaults for all prompts. Give the MySQL root user a strong password.
sudo mysql_secure_installation
Access the MySQL console where you can issue MySQL commands directly. Use the password that you just created to login when prompted.
mysql -u root -p
Create a database and user for WordPress. Pick an appropriate username, strong password, and database name.
create database example_db default character set utf8 collate utf8_unicode_ci; create user 'example_user'@'localhost' identified by 'example_pw'; grant all privileges on example_db.* TO 'example_user'@'localhost'; flush privileges; exit
5. Configure the Nginx Web Server
Nginx configuration files are stored at /etc/nginx/sites-available/
, so let’s go there.
cd /etc/nginx/sites-available/
Confirm the version of PHP FPM that your system is running. You will need this information when creating the Nginx config file next.
ls /var/run/php/php*-fpm.sock
In my case, I am running PHP 8.1, so I will specify this in my new Nginx config file at /etc/nginx/sites-available/wordpress.conf
.
upstream php-handler { server unix:/var/run/php/php8.1-fpm.sock; } server { listen 80; server_name localhost; root /var/www/wordpress; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass php-handler; } }
Create a symbolic link from /etc/nginx/sites-available/wordpress.conf
to /etc/nginx/sites-enabled/wordpress.conf
to enable this Nginx configuration. Then test the configuration and restart the Nginx server to apply the changes.
sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
6. Set Up WordPress
In a web browser on your local computer, go to http://localhost and finish the WordPress setup. Part of this is telling WordPress about the MariaDB that we set up earlier in this tutorial.
Now you have a fresh WordPress installation. You can access your site at http://localhost and your WordPress admin console at http://localhost/wp-admin where you can design your website.
As you are getting your website ready for the public, make sure you do these 15 important things after installing WordPress.
One Response
Almost works! Thanks for your help with this. I ran in to one small issue, though. When attempting to access the WordPress site for the initial config, I only get the default nginx site. Any ideas? Symlink seemed to work ok, and I’ve double-checked my steps several times.