Laravel LEMP
Version: 10.3.1 | OS: Ubuntu 22.04
Overview
Laravel is a modern, open-source PHP framework that simplifies the development of robust web applications. This LEMP (Linux, Nginx, MySQL, PHP) stack deployment provides a secure and scalable environment for Laravel-based development.
Included Software
- Laravel - 10.3.1
- Nginx - 1.18.0
- MySQL - 8.0.32
- PHP - 8.2
- Composer - 2.5.4
- Certbot - 1.21.0
Getting Started
Firewall & Access
Ensure your firewall allows only the required ports:
Port | Service | Purpose |
---|---|---|
22 | SSH (rate limited) | Secure server access |
80 | HTTP | Web access |
443 | HTTPS | Secure web access |
Initial Setup
On deployment:
- MySQL root password is set
mysql_secure_installation
is run- A Laravel user is created with proper database permissions
- The
.env
file is configured with database credentials
You will be logged out with the message:
Please wait until the installation is completed....
Connection to $IPADDRESS closed.
Do not log in for at least 2 minutes.
SSH Access
Log in as ubuntu
, then switch to root:
sudo su -
On first login, the setup script will prompt:
--------------------------------------------------
This setup requires a domain name. If you do not have one yet,
you may cancel this setup, press Ctrl+C.
This script will run again on your next login.
--------------------------------------------------
Enter the domain name for your new Laravel site.
(ex. example.org or test.example.org) do not include www or http/s:
Domain/sub-domain name:
Ensure your domain’s A record is pointed to the server’s IP.
Once completed, you’ll be able to access Laravel via your domain or IP in a browser.
Database & User Info
- MySQL root password:
/root/.mysql_root_password
- Laravel DB credentials:
/root/.laravel_database_details
- Shell user credentials:
/root/.shell_user_passwords
File Paths
- Web root:
/var/www/laravel
- Laravel config:
/var/www/laravel/.env
Nginx Configuration
To host multiple Laravel sites:
- Create a directory for each domain:
mkdir -p /var/www/yourdomain.com/html
- Create an Nginx server block:
nano /etc/nginx/sites-available/yourdomain.com
- Add the following:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/html/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
- Enable site & reload Nginx:
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
systemctl reload nginx
SSL Setup with Certbot
Ensure DNS A records are pointed correctly, then run:
certbot --nginx -d example.com -d www.example.com
Allow port 443 in the firewall. Optionally block HTTP (port 80) after confirming HTTPS.
Best Practices
- Always change default credentials.
- Enable firewalls and fail2ban for added protection.
- Back up your
.env
file securely. - Use Laravel’s built-in environment validation in production.
For assistance, contact Cloud4India Support.