Deploying Laravel on Contabo VPS: A Step-by-Step Guide
As a developer, you're probably no stranger to the importance of choosing the right hosting solution for your Laravel application. With so many options available, it can be daunting to decide which one to go with. In this article, we'll be exploring how to deploy Laravel on a Contabo VPS, a highly-reliable and affordable solution that's perfect for developers of all levels.
Introduction to Contabo VPS
Before we dive into the deployment process, let's take a brief look at what Contabo VPS has to offer. With plans starting at €4.50/mo for their Cloud VPS 10 (4vCPU, 8GB RAM), and their best-seller VPS 20 (6vCPU, 12GB RAM) at €7/mo, it's clear that Contabo is committed to providing high-quality hosting at an affordable price. Additionally, Contabo offers unlimited traffic, 11 server locations, and a 99.9% uptime guarantee, making it an excellent choice for developers who want a reliable and flexible hosting solution.
Step 1: Setting up Your Contabo VPS
To get started, you'll need to sign up for a Contabo VPS account and deploy a new VPS instance. Once your VPS is online, you'll receive an email with your server's IP address, username, and password. Make sure to save this information securely, as you'll need it to access your server.
Step 2: Connecting to Your VPS via SSH
To connect to your VPS, you'll need to use an SSH client. On Linux and macOS, you can use the built-in ssh command in your terminal:
ssh root@your-vps-ip
On Windows, you can use an SSH client like PuTTY.
Step 3: Updating Your Server and Installing Dependencies
Once you're connected to your VPS, it's essential to update your server and install the necessary dependencies for Laravel:
apt update && apt upgrade -y
apt install -y nginx mysql-server php7.4-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring
This command will update your server, install Nginx, MySQL, and the required PHP extensions.
Step 4: Configuring MySQL
Next, we need to configure MySQL to work with our Laravel application. Run the following command to secure your MySQL installation:
mysql_secure_installation
Follow the prompts to set a strong password for the root user, remove anonymous users, and disable remote root login.
Step 5: Creating a New MySQL Database and User
Create a new MySQL database and user for your Laravel application:
mysql -u root -p
Then, run the following queries to create a new database and user:
CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'%' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'%';
FLUSH PRIVILEGES;
Make sure to replace strong_password with a secure password.
Step 6: Configuring Nginx
Create a new Nginx configuration file for your Laravel application:
nano /etc/nginx/sites-available/laravel.conf
Add the following configuration to the file:
server {
listen 80;
server_name your-domain.com;
root /var/www/laravel/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
}
Replace your-domain.com with your actual domain name.
Step 7: Deploying Laravel
Clone your Laravel repository to the /var/www/laravel directory:
git clone https://github.com/your-username/your-repo-name.git /var/www/laravel
Run the following commands to install the required dependencies and configure the application:
cd /var/www/laravel
composer install
php artisan key:generate
php artisan migrate
Step 8: Restarting Nginx and PHP-FPM
Restart Nginx and PHP-FPM to apply the configuration changes:
service nginx restart
service php7.4-fpm restart
That's it! Your Laravel application should now be up and running on your Contabo VPS. You can access your application by visiting http://your-domain.com in your web browser.
Conclusion
Deploying Laravel on a Contabo VPS is a straightforward process that requires some basic knowledge of Linux and Nginx. By following the steps outlined in this article, you can have your Laravel application up and running in no time. With Contabo's reliable and affordable VPS solutions, you can focus on developing your application without worrying about the underlying infrastructure. Whether you're a seasoned developer or just starting out, Contabo VPS is an excellent choice for hosting your Laravel application.
🚀 Want to try it yourself?
I run this on Contabo VPS — best value for money VPS I've found:
| Plan | Price | Specs |
|---|---|---|
| Cloud VPS 10 | €4.50/mo | 4 vCPU, 8GB RAM, 200GB SSD |
| Cloud VPS 20 ★ | €7.00/mo | 6 vCPU, 12GB RAM, 400GB SSD |
| Cloud VPS 30 | €14.00/mo | 8 vCPU, 24GB RAM, 800GB SSD |
✅ Unlimited traffic ✅ 11 server locations ✅ 99.9% uptime ✅ DDoS protection
👉 Check Contabo VPS pricing here
Disclosure: This is an affiliate link. I get a small commission if you sign up via this link — no extra cost to you.
Top comments (0)