For all of you who ever wondered how to install WordPress, configure and secure it on a blank Ubuntu VPS, here's the only tutorial you need.
Prerequisites
- Ubuntu Server VPS: Ensure you have access to a blank Ubuntu server VPS.
- Root or Sudo User Access: Ensure you have root or sudo privileges on your server.
Step-by-Step Guide
1. Update Your Server
First, log in to your Ubuntu server via SSH:
ssh username@your_server_ip
Then, update your package list and upgrade your packages:
sudo apt update
sudo apt upgrade -y
2. Install Apache
Install Apache web server:
sudo apt install apache2 -y
Ensure Apache is running:
sudo systemctl start apache2
sudo systemctl enable apache2
3. Install MySQL
Install MySQL server:
sudo apt install mysql-server -y
Secure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your installation.
4. Install PHP
Install PHP and required extensions:
sudo apt install php php-mysql libapache2-mod-php php-cli php-curl php-zip php-mbstring php-xml -y
Restart Apache to load PHP modules:
sudo systemctl restart apache2
5. Create a MySQL Database and User
Log in to the MySQL root user:
sudo mysql -u root -p
Create a database and a user for WordPress:
CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
6. Download and Configure WordPress
Navigate to the web root directory:
cd /var/www/html
Download the latest WordPress package:
sudo wget https://wordpress.org/latest.tar.gz
Extract the package:
sudo tar -xzvf latest.tar.gz
Move the WordPress files to the web root:
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
Change ownership of the files to the Apache user:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
7. Configure WordPress
Rename the sample configuration file:
sudo mv wp-config-sample.php wp-config.php
Edit the configuration file:
sudo nano wp-config.php
Add your database information:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wordpress_user');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
Save and close the file (Ctrl + X, then Y, then Enter).
8. Complete the Installation via Web Browser
Open your web browser and navigate to your server's IP address or domain:
http://your_server_ip
You will be redirected to the WordPress setup page. Follow the on-screen instructions to complete the installation:
- Choose your preferred language.
- Enter site title, admin username, password, and email address.
- Confirm the installation.
9. Additional Configuration
- Permalinks: Set up pretty permalinks for better SEO and readability:
- Go to Settings > Permalinks in the WordPress dashboard.
- Choose a permalink structure (e.g., Post name).
- Themes and Plugins: Customize your site by installing themes and plugins:
- Go to Appearance > Themes to install and activate a theme.
- Go to Plugins > Add New to install and activate plugins.
Security Tips
- Delete the
wp-config-sample.php
file from your server.
- Regularly update WordPress, themes, and plugins to the latest versions.
- Consider installing security plugins like Wordfence or Sucuri.
Troubleshooting
- Database Connection Errors: Double-check your database credentials in
wp-config.php
.
- File Permissions Issues: Ensure that the WordPress files have the correct permissions (e.g., 755 for directories and 644 for files).
- 500 Internal Server Errors: Check your
.htaccess
file for errors and ensure your server meets WordPress requirements.
Following these steps will help you set up a WordPress site on a blank Ubuntu server VPS. If you encounter any issues, refer to the WordPress documentation or seek help from the community forums.