How to Install WordPress on VPS in 2 Ways?
You just got a VPS. Now you want to run your own WordPress site. The thought of typing commands might make you pause. I understand that feeling. But installing WordPress on a VPS is not complicated. You just need a clear path. I’ll show you three practical methods.
Why Choose VPS for WordPress?
Shared hosting feels like a cheap apartment with thin walls. When your neighbor gets a traffic spike, your site slows down. A VPS gives you isolated resources. All the CPU, RAM, and SSD storage belong to you alone. That translates into faster load times and a smoother experience for your visitors.
You also get full control. Do you need a particular PHP version? Install it. Want to fine‑tune a caching rule? Go ahead. This level of customization is impossible on cramped shared plans. And from a security perspective, you own the environment. You can set up a firewall exactly how you like it, add an SSL certificate, and monitor everything. That’s a powerful foundation for earning trust with both users and search engines.
Cost is often a pleasant surprise. A basic VPS costs about the same as a monthly streaming subscription. For that price, you receive root access, predictable performance, and room to grow. Why keep stuffing your site into a tiny box when a VPS opens the door to real reliability?
Method 1. How to Install WordPress on VPS with LAMP
The LAMP stack—Linux, Apache, MySQL, PHP—has powered the web for decades. It’s stable, well‑documented, and runs on almost any VPS. I’ll use Ubuntu 22.04 LTS because it is the most common choice.
1. Log into your server via SSH as a user with sudo privileges.
2. Make sure your system is up to date. Run sudo apt update && sudo apt upgrade -y. This pulls the latest package lists and applies any pending fixes.
3. Install the Apache web server with sudo apt install apache2 -y. After the installation finishes, you want to confirm Apache is listening on port 80. If your VPS has a firewall enabled (some images turn on UFW by default), you need to open that port. Run sudo ufw allow 80/tcp.
4. Open your browser and enter your VPS IP address. You should see the Apache default welcome page. That means your server is already serving content.
5. Now let’s set up MySQL. Install it by typing sudo apt install mysql-server -y. Once that completes, run sudo mysql_secure_installation to lock down the database server. You’ll be asked to validate the password component and to set a root password. Follow the prompts.
6. When you log in to MySQL, use sudo mysql (if your system still uses socket authentication) or sudo mysql -u root -p and enter the password you just created.
7. Inside the MySQL prompt, create a database for WordPress with full Unicode support:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
8. Create a dedicated user and grant permissions:
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'a_strong_password_here';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
9. The database is ready. Now we need PHP and its companion extensions. Ubuntu 22.04 ships PHP 8.1, which works beautifully with WordPress. Install the core packages with this command (notice that we intentionally leave out php-xmlrpc because it doesn’t exist in this PHP version and isn’t needed):
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip -y
Each extension has a purpose. php-mysql handles database connections, php-curl fetches external resources, php-gd processes images, php-mbstring deals with multi‑byte strings, php-xml parses XML, and php-zip unzips files. After the installation, restart Apache so it picks up the new module: sudo systemctl restart apache2.
10. It is time to download WordPress. Change to the temporary directory: cd /tmp. Get the latest archive:
curl -LO https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
11. Copy the extracted files into Apache’s document root:
sudo cp -a /tmp/wordpress/. /var/www/html
12. Now fix the ownership and permissions. WordPress needs to be writable by the web server:
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
13. This sets directories to 755 and files to 644, which is the recommended secure baseline. Enable the Apache rewrite module (used for pretty permalinks) and restart once more:
sudo a2enmod rewrite
sudo systemctl restart apache2
Everything is in place. Open your VPS IP address in a browser again. This time, you will see the WordPress setup wizard—not the Apache default page. The wizard detects that no wp-config.php exists yet and, because the web server owns the directory, it can create that file automatically. Choose your language, and on the next screen enter the database name, user, and password you defined earlier. Click Submit, and WordPress will connect to MySQL. Fill in your site title, admin username, a strong password, and your email. Finally, hit Install WordPress. You’ve just built a self‑managed WordPress site the classic way.
Method 2. How to Install WordPress on VPS with Docker
Docker wraps your entire application into lightweight containers. You skip the manual installation of Apache and MySQL because they run inside isolated boxes. This keeps your VPS clean and makes moving the site to another server trivial. The only prerequisite is a working Docker installation.
1. On Ubuntu 22.04, run:
sudo apt install docker.io -y
sudo systemctl enable --now docker
2. Also install Docker Compose (the docker-compose package in the repositories works fine for our simple stack):
sudo apt install docker-compose -y
3. Create a directory for the project and move into it:
mkdir ~/wordpress && cd ~/wordpress
4. Now we will define the stack in a docker-compose.yml file. Open a text editor, such as nano, with nano docker-compose.yml, and paste the following configuration:
version: '3.1'
services:
wordpress:
image: wordpress
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: AStrongPassword
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: AStrongPassword
MYSQL_ROOT_PASSWORD: SomeRootPassword
volumes:
- db_data:/var/lib/mysql
volumes:
wp_data:
db_data:
5. Save and exit. This file tells Docker to run two services: wordpress and db. The credentials in the environment section are shared automatically, so you won’t need to enter them during setup. The volumes ensure that your theme, plugins, and database survive container restarts.
6. Launch the whole stack in detached mode:
sudo docker-compose up -d
Docker pulls the required images and starts the containers. Give it about a minute, then visit your VPS IP address in a browser. The WordPress installation screen is already waiting. Because Docker pre‑linked the database, you skip the database‑configuration step entirely. Just select a language, set up your admin account, and you are done.
Managing the containers is straightforward. Use sudo docker ps to see what is running. If you ever need to stop everything, sudo docker-compose down brings the stack offline without deleting your data (the volumes stay). This method is clean, portable, and ideal if you plan to run multiple services on the same VPS.
How to Install WordPress on VPS FAQs
Q1: I changed my domain and now the site shows a white screen. What should I do?
Access your database via a tool like phpMyAdmin or Adminer, go to the wp_options table, and update the siteurl and home rows to your new domain—then clear your browser cache.
Q2: Can I install WordPress without a domain name during testing?
Yes, simply use the VPS IP address in the browser during setup and later point a domain to the server while updating the site URL.
Q3: How do I speed up WordPress on a VPS with low RAM?
Install a caching plugin like W3 Total Cache, enable a CDN, and add swap space—run sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile then make it permanent with echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab.
Conclusion
WordPress on a VPS puts you in total control. You can handcraft the LAMP stack, containerize with Docker, or coast on a one‑click app. Each method ends with a site you truly own. Final touches like SSL, a firewall, and backups wrap it in solid protection. Take the leap, enjoy the performance, and build something remar