Installing Laravel (LEMP) on Ubuntu Server
💡 What You Will Learn in This Guide
You will learn to install the Laravel 11 framework with the LEMP (Linux, Nginx, MySQL, PHP) stack on your Ubuntu server and make it ready for the production environment. All steps, from database configuration to SSL certificate, can be implemented exactly on the GenixNode platform.
🧠 Technical Summary
In this setup:
- PHP 8.2+ and necessary plugins will be installed,
- A secure MySQL database will be created,
- Laravel will be installed with Composer,
- Nginx will be configured and SSL will be added,
- Performance optimizations will be made.
⚙️ 1. Installing PHP and Required Extensions
Laravel 11 requires PHP 8.2 or above.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-mbstring php8.2-xml php8.2-bcmath php8.2-curl php8.2-zip php8.2-gd
This command installs all necessary extensions for PHP 8.2 and Laravel.
Verification:
php -m | grep -E "(mbstring|xml|bcmath|curl|zip|gd)"
🧩 2. Creating a Secure Database
sudo mysql
Create new database in MySQL:
CREATE DATABASE seyahat_listesi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'genix_user'@'localhost' IDENTIFIED BY 'GucluSifre123!';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON seyahat_listesi.* TO 'genix_user'@'localhost';
FLUSH PRIVILEGES;
exit;
Security Note: User can only access from localhost.
Test the connection:
mysql -u genix_user -p
🧱 3. Installing Laravel Application
composer create-project laravel/laravel seyahat-listesi
cd seyahat-listesi
php artisan --version
If you see Laravel 11.x, the installation is complete.
⚙️ 4. Configuring Laravel Environment
nano .env
Edit the following values:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=seyahat_listesi
DB_USERNAME=genix_user
DB_PASSWORD=GucluSifre123!
Generate the application key:
php artisan key:generate
Laravel generates the encryption key.
Connection test:
php artisan tinker --execute="DB::connection()->getPdo();"
🌐 5. Nginx Configuration
sudo mv ~/seyahat-listesi /var/www/seyahat-listesi
sudo chown -R www-data:www-data /var/www/seyahat-listesi
sudo chmod -R 775 /var/www/seyahat-listesi/storage /var/www/seyahat-listesi/bootstrap/cache
Create Nginx configuration file:
sudo nano /etc/nginx/sites-available/seyahat-listesi
Content:
server {
listen 80;
server_name senin_alan_adin.cloud;
root /var/www/seyahat-listesi/public;
index index.php index.html;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
gzip on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\. {
deny all;
}
}
Activate and test:
sudo ln -s /etc/nginx/sites-available/seyahat-listesi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
When you open
http://senin_alan_adin.cloudin the browser, the Laravel welcome page should appear.
🔒 6. SSL (Let's Encrypt) Setup
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d senin_alan_adin.cloud -d www.senin_alan_adin.cloud
Test automatic renewal:
sudo certbot renew --dry-run
⚡ 7. Production Optimization
Enable Laravel caching:
php artisan config:cache
php artisan route:cache
php artisan view:cache
Nginx performance settings:
client_max_body_size 20M;
keepalive_timeout 65s;
fastcgi_read_timeout 60s;
PHP-FPM settings (/etc/php/8.2/fpm/pool.d/www.conf):
pm.max_children = 30
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 1000
Restart:
sudo systemctl restart php8.2-fpm
sudo systemctl reload nginx
❓ Frequently Asked Questions (FAQ)
1. I'm getting a 502 Bad Gateway error, why?
PHP-FPM may not be working. Check out:
sudo systemctl status php8.2-fpm
2. Why shouldn't the .env file be uploaded to Git?
Because it contains API keys, passwords and confidential information.
3. What happens if my fastcgi_pass path is incorrect?
If false, Nginx cannot run PHP. Check the correct socket with ls /var/run/php/.
4. I can't write to the storage folder, why?
Fix permissions:
sudo chmod -R 775 /var/www/seyahat-listesi/storage
sudo chown -R www-data:www-data /var/www/seyahat-listesi/storage
5. Is my SSL certificate automatically renewed?
Yes, Certbot automatically renews every 90 days.
🏁 Result
You can now run Laravel 11 application securely, performantly and with SSL support on the LEMP stack on your Ubuntu server. You can try all these operations in seconds on the GenixNode platform and easily switch to the production environment. 🎯 Welcome to a modern, optimized and secure Laravel infrastructure!

