Version: 1.1.4 Last Modified: 2025-06-17
This document outlines the guidelines for configuring a new VPS/Cloud server, specifically focusing on Debian 12 (or Ubuntu 24.04 as an alternative). If using a different distribution, commands may vary, and you will need to adjust accordingly.
Before proceeding with any configuration, always ensure the system is up to date.
sudo apt update
sudo apt upgrade
If sudo
is not installed, switch to root user:
su -
Then check for updates and upgrade the system.
apt update
apt upgrade
By default, sudo
is not installed on Debian. First, switch to root user (if current user is not root):
su -
Then, install sudo
:
apt install sudo -y
It is best practice to avoid using the root user for server operations. Create a new user and add them to the sudo
group:
adduser admin
usermod -aG sudo admin
You can find more details here.
UFW (Uncomplicated Firewall) is our preferred choice for managing firewall rules. UFW automatically installs iptables
and netfilter
as dependencies, but if needed, you can install them manually:
apt install iptables
apt install ufw
Check if UFW meets the system requirements:
/usr/share/ufw/check-requirements
If something fails, reboot the server and recheck:
reboot now
List available applications:
ufw app list
Allow OpenSSH to ensure SSH access after the firewall is enabled:
ufw allow OpenSSH
Enable UFW:
ufw enable
Note: You may be logged out after enabling UFW. Log back in to continue.
Check the UFW status:
ufw status
Logout and relogin as the new sudo user (admin
):
logout
Install PHP-FPM (FastCGI Process Manager) and necessary PHP extensions:
sudo apt install php-fpm php-mbstring php-xml php-bcmath php-curl php-gd php-mysql php-zip
To verify PHP installation:
php -v
To list installed PHP extensions:
php -m
To serve web applications, install Nginx:
sudo apt install nginx
Nginx integrates with UFW and offers several profiles. List available UFW profiles:
sudo ufw app list
Enable the "Nginx Full" profile, which allows both HTTP and HTTPS traffic:
sudo ufw allow 'Nginx Full'
Check the UFW status:
sudo ufw status
-
Check Nginx service status:
sudo systemctl status nginx
-
Enable Nginx to start on boot:
sudo systemctl enable nginx
-
Restart Nginx:
sudo systemctl restart nginx
-
Reload Nginx configuration without stopping the server:
sudo systemctl reload nginx
You can find more details here.
MariaDB is a popular, open-source database system. Follow the steps below to install and configure MariaDB on your Debian 12 server.
First, install the MariaDB server package using the following command:
sudo apt install mariadb-server
Once MariaDB is installed, run the security script to configure it securely:
sudo mysql_secure_installation
You will be prompted with several questions during the process:
-
Enter current root password:
Since no password is set yet, simply pressENTER
to proceed. -
Switch to unix_socket authentication:
Typen
and pressENTER
to skip this step. -
Change the root password:
Typen
and pressENTER
. -
Afterward, press
Y
andENTER
to accept the defaults for the remaining prompts. These steps will remove anonymous users, disable remote root logins, and remove the test database, securing your MariaDB setup.
To manage the database securely, it is recommended to create a new administrative user with full privileges. First, access the MariaDB shell:
sudo mariadb
Then create a new user with root privileges:
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
Be sure to replace 'admin'
and 'password'
with your desired username and password.
You can find more details here.
Once MariaDB is installed and secured, you can create a new database and user for your application. Follow the steps below to create a database and assign a user to manage it.
-
Access the MariaDB shell:
sudo mariadb
-
Create a new database named
example_db
with theutf8
character set andutf8_unicode_ci
collation:CREATE DATABASE example_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-
Create a new user
example_user
with a secure password:CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'example_pw';
-
Grant all privileges on the
example_db
database to the newly created user:GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
-
Apply the privilege changes by flushing the privileges:
FLUSH PRIVILEGES;
-
Exit the MariaDB shell:
exit;
Make sure to replace example_db
, example_user
, and example_pw
with your desired database name, username, and password.
Create the directory where your Laravel project will reside:
sudo mkdir /var/www/sub.example.com
Take ownership of the directory:
sudo chown -R $USER /var/www/sub.example.com
Navigate to the directory and clone the desired branch from your repository:
cd /var/www/sub.example.com
git clone -b <branchname> <remote-repository-url>
After cloning, install the required Composer dependencies:
composer install
Set appropriate ownership for storage
and bootstrap/cache
directories:
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
Set permissions for files (644) and directories (755):
sudo find /var/www/sub.example.com/ -type f -exec chmod 644 {} \;
sudo find /var/www/sub.example.com/ -type d -exec chmod 755 {} \;
Grant read, write, and execute permissions for storage
and bootstrap/cache
:
sudo chmod -R ug+rwx storage bootstrap/cache
Copy the .env.example
to .env
, set up the necessary environment variables, generate an app key, link storage, and run migrations:
cp .env.example .env
php artisan key:generate
php artisan storage:link
php artisan migrate
Update the following command: