DEV Community

Cover image for Steps to Set Up Virtual Host and MySQL for WordPress Development on Linux
Rajon Dey
Rajon Dey

Posted on

1

Steps to Set Up Virtual Host and MySQL for WordPress Development on Linux

Simple guide for setting up a virtual host and MySQL for WordPress development. This is tailored for Ubuntu/Debian-based distributions.


Steps to Set Up Virtual Host and MySQL for WordPress Development on Linux


1. Install Required Software

  1. Update your system:
   sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode
  1. Install Apache, MySQL, and PHP:
   sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
Enter fullscreen mode Exit fullscreen mode

2. Set Up MySQL Database

  1. Secure MySQL installation:
   sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode
  • Set a root password (if prompted).
  • Answer Y (yes) to all security questions.
  1. Log in to MySQL:
   sudo mysql -u root -p
Enter fullscreen mode Exit fullscreen mode
  1. Create a database for WordPress:
   CREATE DATABASE wordpress_db;
Enter fullscreen mode Exit fullscreen mode
  1. Create a MySQL user and grant privileges:
   CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password';
   GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
   FLUSH PRIVILEGES;
   EXIT;
Enter fullscreen mode Exit fullscreen mode

3. Configure Virtual Host

  1. Create a directory for your WordPress site:
   sudo mkdir -p /var/www/yourdomain.com
Enter fullscreen mode Exit fullscreen mode
  1. Set permissions:
   sudo chown -R $USER:$USER /var/www/yourdomain.com
Enter fullscreen mode Exit fullscreen mode
  1. Create a virtual host configuration file:
   sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Enter fullscreen mode Exit fullscreen mode
  1. Add the following content:
   <VirtualHost *:80>
       ServerName yourdomain.com
       DocumentRoot /var/www/yourdomain.com

       <Directory /var/www/yourdomain.com>
           AllowOverride All
       </Directory>

       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
   </VirtualHost>
Enter fullscreen mode Exit fullscreen mode
  1. Enable the site and reload Apache:
   sudo a2ensite yourdomain.com.conf
   sudo systemctl reload apache2
Enter fullscreen mode Exit fullscreen mode

4. Install WordPress

  1. Download WordPress:
   cd /tmp && wget https://wordpress.org/latest.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Extract WordPress to your site directory:
   sudo tar -xvzf latest.tar.gz -C /var/www/yourdomain.com --strip-components=1
Enter fullscreen mode Exit fullscreen mode
  1. Set permissions:
   sudo chown -R www-data:www-data /var/www/yourdomain.com
Enter fullscreen mode Exit fullscreen mode

5. Configure WordPress

  1. Open your browser and go to http://yourdomain.com.
  2. Follow the WordPress setup wizard:
    • Database Name: wordpress_db
    • Username: wordpress_user
    • Password: your_password
    • Database Host: localhost
    • Table Prefix: wp_ (default)
  3. Complete the installation.

6. Test Your Setup

  • Visit http://yourdomain.com to see your WordPress site.
  • Log in to the WordPress admin dashboard at http://yourdomain.com/wp-admin.

Optional: Local Domain Setup

If you’re working locally, edit your /etc/hosts file to map yourdomain.com to 127.0.0.1:

  1. Open the hosts file:
   sudo nano /etc/hosts
Enter fullscreen mode Exit fullscreen mode
  1. Add this line:
   127.0.0.1   yourdomain.com
Enter fullscreen mode Exit fullscreen mode
  1. Save and exit.

Summary

  • Installed Apache, MySQL, and PHP on Linux.
  • Created a MySQL database and user.
  • Set up a virtual host for your domain.
  • Installed and configured WordPress.

You’re now ready for WordPress development on Linux! 🚀

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or a friendly comment!

Okay.