To install WordPress on a VPS (Virtual Private Server), you need to follow the below steps:
- Choose a VPS provider and create a VPS instance.
- Log in to your VPS instance using SSH.
- Install Apache web server and PHP:
sudo apt-get update
sudo apt-get install apache2 php php-mysql php-gd libapache2-mod-php php-curl
- Start and enable Apache to start at boot time:
sudo systemctl start apache2
sudo systemctl enable apache2
- Install MySQL database server:
sudo apt-get install mysql-server
- Secure MySQL installation by running the following command and following the on-screen instructions:
sudo mysql_secure_installation
- Create a database and user for WordPress:
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit;
- Download and extract WordPress:
cd /var/www/html
sudo curl -O https://wordpress.org/latest.tar.gz
sudo tar -zxvf latest.tar.gz
- Copy the WordPress sample configuration file and make changes to it:
sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
sudo vi /var/www/html/wordpress/wp-config.php
Replace the following lines with the database, username, and password that you have created:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
- Set proper permissions on the WordPress directory:
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
- Restart Apache:
sudo systemctl restart apache2
You should now be able to access your WordPress installation by visiting your server’s IP address or domain name in a web browser.