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
- Update your system:
sudo apt update && sudo apt upgrade -y
- Install Apache, MySQL, and PHP:
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
2. Set Up MySQL Database
- Secure MySQL installation:
sudo mysql_secure_installation
- Set a root password (if prompted).
- Answer
Y
(yes) to all security questions.
- Log in to MySQL:
sudo mysql -u root -p
- Create a database for WordPress:
CREATE DATABASE wordpress_db;
- 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;
3. Configure Virtual Host
- Create a directory for your WordPress site:
sudo mkdir -p /var/www/yourdomain.com
- Set permissions:
sudo chown -R $USER:$USER /var/www/yourdomain.com
- Create a virtual host configuration file:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
- 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>
- Enable the site and reload Apache:
sudo a2ensite yourdomain.com.conf
sudo systemctl reload apache2
4. Install WordPress
- Download WordPress:
cd /tmp && wget https://wordpress.org/latest.tar.gz
- Extract WordPress to your site directory:
sudo tar -xvzf latest.tar.gz -C /var/www/yourdomain.com --strip-components=1
- Set permissions:
sudo chown -R www-data:www-data /var/www/yourdomain.com
5. Configure WordPress
- Open your browser and go to
http://yourdomain.com
. - Follow the WordPress setup wizard:
-
Database Name:
wordpress_db
-
Username:
wordpress_user
-
Password:
your_password
-
Database Host:
localhost
-
Table Prefix:
wp_
(default)
-
Database Name:
- 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
:
- Open the hosts file:
sudo nano /etc/hosts
- Add this line:
127.0.0.1 yourdomain.com
- 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! 🚀
Top comments (0)