Setting up a VPS (Virtual Private Server) might seem like a daunting task, but with the right guidance, you can have your own server running in no time. Below, I will show you how to do it simply and effectively, including the basic setup of Apache, MySQL, Certbot, and security measures.
1. Choose a VPS Provider
The first step is to select a VPS provider. There are several options available in the market, such as DigitalOcean, Linode, and Vultr. Each one offers different plans and pricing.
Tips for Choosing:
- Technical Features: Check if the provider offers resources that meet your needs.
- Technical Support: Opt for a provider that offers 24/7 assistance.
- Ease of Use: Some providers have more intuitive control panels.
2. Create Your VPS
After choosing your provider, the next step is to create your VPS. This process usually includes selecting the operating system and server specifications.
Steps to Create Your VPS:
- Select an Operating System: Choose Ubuntu 20.04 LTS for its ease of use.
- Choose the Right Plan: Select a plan that fits your performance requirements.
- Configure Security: Enable the security options that the provider offers.
3. Access Your VPS
Once your VPS is created, you will need to access it via SSH (Secure Shell).
How to Access:
- Open your terminal or use an SSH client like PuTTY.
- Type the following command:
bash
ssh root@your_ip_address
- Enter your password when prompted.
4. Initial Server Configuration
Once inside your VPS, perform some initial configurations to ensure security and functionality.
Initial Configuration Steps:
- Update the System: Run the following commands:
bash
sudo apt update sudo apt upgrade -y
- Create a New User: It’s recommended not to use the root user. Create a new user and grant sudo privileges:
bash
adduser new_user usermod -aG sudo new_user
5. Install Apache and MySQL
Now it’s time to install Apache and MySQL. Apache is the web server, and MySQL is the database management system.
Installing Apache:
sudo apt install apache2 -y
Verify that Apache is working by accessing your IP address in a browser.
Installing MySQL:
sudo apt install mysql-server -y
After installation, secure your MySQL:
sudo mysql_secure_installation
This will guide you through securing your MySQL installation.
6. Install Certbot for SSL
To ensure your website’s security, it’s crucial to have an SSL certificate. We will use Certbot to obtain a free certificate from Let’s Encrypt.
Installing Certbot:
sudo apt install certbot python3-certbot-apache -y
Obtain the SSL Certificate:
Run the following command, replacing your_domain.com with your domain name:
sudo certbot --apache -d your_domain.com -d www.your_domain.com
Follow the on-screen instructions to complete the setup.
7. Configure the Firewall and Security
Finally, make sure your server is protected. Set up the firewall using UFW and enable only necessary traffic.
Firewall Configuration:
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable
Additional Security Measures:
- Disable Root Access via SSH: Edit the SSH configuration file:
bash
sudo nano /etc/ssh/sshd_config
Change
PermitRootLogin yes
toPermitRootLogin no
. - Set Up Fail2Ban: To protect against brute force attacks:
bash
sudo apt install fail2ban -y
Setting up a VPS may seem complex, but by following these steps, you can have your own server ready to go in no time. From the basic installation of Apache and MySQL to implementing security measures, each step is essential for ensuring a safe and efficient environment.