cs@vps-hosting.org

Deploying Applications on a VPS

A VPS gives you full control over hosting and deploying various applications. Whether you’re setting up a WordPress site, a Node.js app, or a Laravel project, this chapter will guide you through the entire process.


5.1 Setting Up a Web Hosting Stack

Before deploying any application, you need a web hosting stack. The most common stacks are:

1️⃣ LAMP Stack (Linux, Apache, MySQL, PHP) – Best for WordPress & PHP Apps

apt install apache2 mysql-server php php-mysql libapache2-mod-php -y  
systemctl enable --now apache2 mysql

Test PHP:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Visit http://your-vps-ip/info.php to confirm PHP is working.

2️⃣ LEMP Stack (Linux, Nginx, MySQL, PHP) – Faster Alternative for PHP Apps

apt install nginx mysql-server php-fpm php-mysql -y  
systemctl enable --now nginx mysql

Edit /etc/nginx/sites-available/default and add:

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}

Restart Nginx:

systemctl restart nginx

3️⃣ Node.js & Nginx – Best for Modern Web Apps

curl -fsSL https://deb.nodesource.com/setup_18.x | bash -  
apt install nodejs -y

Test:

node -v

5.2 Deploying WordPress on VPS

1️⃣ Download & Extract WordPress

wget https://wordpress.org/latest.tar.gz  
tar -xvzf latest.tar.gz
mv wordpress /var/www/html/

Set correct permissions:

chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress

2️⃣ Create a MySQL Database for WordPress

mysql -u root -p

Inside MySQL:

CREATE DATABASE wordpress;  
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

3️⃣ Configure WordPress

Rename the sample config file:

mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Edit the file:

nano /var/www/html/wordpress/wp-config.php

Update these lines with your database details:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');

Restart the web server:

systemctl restart apache2  # or systemctl restart nginx

Now visit http://your-vps-ip/wordpress and complete the WordPress installation.


5.3 Deploying Node.js Applications

1️⃣ Create a Simple Node.js App

mkdir /var/www/nodeapp && cd /var/www/nodeapp  
npm init -y
npm install express

Create server.js:

const express = require('express');
const app = express();

app.get('/', (req, res) => {
res.send('Hello from Node.js on VPS!');
});

app.listen(3000, () => {
console.log('Server running on port 3000');
});

2️⃣ Run the App with PM2 (Keeps It Always Running)

npm install -g pm2  
pm2 start server.js
pm2 save
pm2 startup

3️⃣ Reverse Proxy with Nginx (Public Access)

Edit Nginx config:

nano /etc/nginx/sites-available/default

Add:

server {
listen 80;
server_name yourdomain.com;

location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

Restart Nginx:

systemctl restart nginx

Now, your Node.js app is accessible via http://yourdomain.com.


5.4 Deploying Laravel on VPS

1️⃣ Install Laravel & Dependencies

apt install php-cli unzip curl php-mbstring php-xml composer -y  
composer create-project --prefer-dist laravel/laravel laravelapp

Move to the web directory:

mv laravelapp /var/www/html/
cd /var/www/html/laravelapp

Set permissions:

chown -R www-data:www-data /var/www/html/laravelapp
chmod -R 755 /var/www/html/laravelapp/storage

2️⃣ Configure Database

Edit .env:

nano /var/www/html/laravelapp/.env

Set your database details:

DB_DATABASE=laravel
DB_USERNAME=laraveluser
DB_PASSWORD=yourpassword

Run migrations:

php artisan migrate

3️⃣ Set Up Laravel Virtual Host in Nginx

nano /etc/nginx/sites-available/laravel

Add:

server {
listen 80;
server_name yourdomain.com;
root /var/www/html/laravelapp/public;

index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}

Enable the site and restart Nginx:

ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
systemctl restart nginx

Laravel is now accessible at http://yourdomain.com.


5.5 Enabling HTTPS with Let’s Encrypt

To secure your apps with SSL:

apt install certbot python3-certbot-nginx -y  
certbot --nginx -d yourdomain.com

This will install an SSL certificate and configure automatic HTTPS redirection.


Conclusion

You’ve successfully deployed WordPress, Node.js, and Laravel on your VPS! Your applications are now running securely and optimized for performance.

In the next chapter, we’ll explore Advanced VPS Configurations, including Docker, Kubernetes, and multi-server setups.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Worldwide shipping

On all orders above $50

Easy 30 days returns

30 days money back guarantee

International Warranty

Offered in the country of usage

100% Secure Checkout

PayPal / MasterCard / Visa