1. Connect to Your VPS
First, you need to connect to your VPS server via SSH.
In the terminal, enter the following command (replace
with your VPS IP address):
ssh root@
If it's your first time connecting, the system will ask you to confirm the connection. Type yes
and press Enter.
2. Update the Server
Before installing any software, make sure all the software packages on your server are up to date:
apt update && apt upgrade -y
3. Install a Web Server (Nginx or Apache)
You can choose either Nginx or Apache as your web server. Below are the steps for installation and configuration.
Install Nginx:
apt install nginx -y
Install Apache:
apt install apache2 -y
Once installed, you can start and enable Nginx or Apache with the following commands:
systemctl start nginx # Start Nginx
systemctl enable nginx # Enable Nginx to start on boot
or
systemctl start apache2 # Start Apache
systemctl enable apache2 # Enable Apache to start on boot
4. Install PHP (if needed)
If your website is built using PHP (e.g., WordPress), you will need to install PHP and its extensions.
Install PHP and common extensions:
apt install php-fpm php-mysql php-cli php-xml php-curl php-mbstring php-zip -y
5. Install MySQL (if needed)
If your website requires a database (e.g., WordPress uses MySQL), you will need to install MySQL:
apt install mysql-server -y
Once installed, start MySQL with the following command:
systemctl start mysql
systemctl enable mysql
Configure MySQL (set root password, create databases, etc.):
mysql_secure_installation
Then log in to MySQL:
mysql -u root -p
Create a new database and user:
CREATE DATABASE mywebsite;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mywebsite.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
6. Configure the Web Server
For Nginx:
- Create a new site configuration file in
/etc/nginx/sites-available/
:
nano /etc/nginx/sites-available/mywebsite
- Example configuration file (replace
/var/www/html
with the directory where your website files are stored):
server {
listen 80;
server_name yourdomain.com; # Replace with your domain
root /var/www/mywebsite; # Directory where your website files are located
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
- Create a symbolic link to enable the site:
ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
- Check if the Nginx configuration is correct:
nginx -t
- Reload Nginx to apply the changes:
systemctl reload nginx
For Apache:
- Create a new site configuration file in
/etc/apache2/sites-available/
:
nano /etc/apache2/sites-available/mywebsite.conf
- Example configuration file:
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com # Replace with your domain
DocumentRoot /var/www/mywebsite # Directory where your website files are located
<Directory /var/www/mywebsite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
VirtualHost>
- Enable the site and reload Apache:
a2ensite mywebsite.conf
systemctl reload apache2
7. Upload Website Files
Upload your website files to the VPS. You can use SFTP, FTP, or command-line tools like scp
.
For example, using scp
to upload your website files to /var/www/mywebsite
:
scp -r /local/path/to/website/* root@:/var/www/mywebsite/
8. Configure the Domain Name
- Log in to your domain registrar’s control panel.
- Go to the DNS settings and set the A record to point to your VPS IP address.
For example, if your VPS IP is
, set the A record for yourdomain.com
to:
yourdomain.com A
9. Test the Website
In your browser, visit your domain (e.g., yourdomain.com
), and you should see your uploaded website.
If you are using a PHP website (e.g., WordPress), make sure you have correctly configured the database connection and completed the installation process.
10. Set Up SSL (Optional)
To improve security, you can install an SSL certificate for your website. Using Let’s Encrypt, you can enable SSL for free.
Install Certbot (Let’s Encrypt tool):
apt install certbot python3-certbot-nginx # For Nginx
or
apt install certbot python3-certbot-apache # For Apache
Then, request the SSL certificate:
certbot --nginx -d yourdomain.com # For Nginx
or
certbot --apache -d yourdomain.com # For Apache
11. Auto-Renew SSL Certificates
Let’s Encrypt certificates are valid for 90 days. You can set up auto-renewal:
crontab -e
Add the following line:
0 0,12 * * * certbot renew --quiet
Conclusion
This is the basic process for deploying a website on a VPS. You can further customize and optimize your server setup, such as configuring a firewall, setting up regular backups, and more. For beginners, it's recommended to try hourly billing VPS options, like LightNode and Vultr, to reduce costs.