Heman Jone
hemanjone162@gmail.com
Install Nginx, PHP, and MySQL on Ubuntu 24.04: Full LEMP Guide (29 อ่าน)
27 ก.ค. 2568 19:52
Setting up a powerful and efficient web server starts with the right stack, and the LEMP stack is one of the most widely used setups in modern web development. Comprising Linux, Nginx, MySQL, and PHP, this stack is ideal for hosting dynamic websites and PHP-based applications. In this guide, you’ll learn how to install Nginx, PHP, and MySQL on Ubuntu 24.04 step-by-step, helping you create a production-ready server environment.
For a comprehensive walkthrough, refer to the official Vultr tutorial here.
Why Choose Ubuntu 24.04 with LEMP?
Ubuntu 24.04 is the latest Long-Term Support (LTS) version and provides better security, updated packages, and longer support than previous releases. Nginx serves as a fast and lightweight web server, MySQL is a reliable relational database, and PHP processes dynamic content efficiently. Together, they form a perfect stack for everything from blogs and e-commerce sites to custom web applications.
Step 1: System Update
Before installing any packages, update the system to make sure all dependencies are current:
sudo apt update && sudo apt upgrade -y
This ensures compatibility and avoids package conflicts during the installation.
Step 2: Install Nginx
To install the Nginx web server:
sudo apt install nginx -y
After installation, start and enable Nginx to launch automatically on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Verify the installation by visiting your server’s IP address in a browser—you should see the default Nginx welcome page.
Step 3: Install MySQL
To manage your data, install MySQL:
sudo apt install mysql-server -y
After the installation, it’s recommended to secure the database:
sudo mysql_secure_installation
This step includes setting a root password, removing test databases, and disabling remote root login for added security.
Step 4: Install PHP
Next, install PHP along with the necessary extensions:
sudo apt install php-fpm php-mysql -y
The php-fpm package helps PHP integrate smoothly with Nginx using FastCGI, and php-mysql allows PHP to interact with MySQL.
You can confirm PHP installation using:
php -v
Step 5: Configure Nginx to Use PHP
Now, configure Nginx to process PHP files. Edit the default server block:
sudo nano /etc/nginx/sites-available/default
Find and modify the configuration to include the following block:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust PHP version if needed
}
Then test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 6: Test PHP Processing
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Now open http://your-server-ip/info.php in your browser. If successful, you’ll see the PHP info page, confirming everything is working.
Final Notes
You’ve now completed the essential steps to install Nginx, PHP, and MySQL on Ubuntu 24.04, forming a fully functional LEMP environment. This setup is perfect for hosting platforms like WordPress, Joomla, or any custom PHP application.
For advanced configurations, SSL setup, virtual hosts, or troubleshooting, refer to the full Vultr guide. Vultr LEMP Installation Guide
With this guide, you’re ready to build fast, scalable, and secure web applications using the latest Ubuntu platform and a trusted web stack. Whether you're a beginner or a seasoned developer, the LEMP stack on Ubuntu 24.04 provides flexibility and performance for your next web project.
Let me know if you’d like a version optimized for SEO, or tailored for Laravel, WordPress, or production server deployment.
Install Nginx, PHP, and MySQL on Ubuntu 24.04: Full LEMP Guide
Setting up a powerful and efficient web server starts with the right stack, and the LEMP stack is one of the most widely used setups in modern web development. Comprising Linux, Nginx, MySQL, and PHP, this stack is ideal for hosting dynamic websites and PHP-based applications. In this guide, you’ll learn how to install Nginx, PHP, and MySQL on Ubuntu 24.04 step-by-step, helping you create a production-ready server environment.
For a comprehensive walkthrough, refer to the official Vultr tutorial here.
Why Choose Ubuntu 24.04 with LEMP?
Ubuntu 24.04 is the latest Long-Term Support (LTS) version and provides better security, updated packages, and longer support than previous releases. Nginx serves as a fast and lightweight web server, MySQL is a reliable relational database, and PHP processes dynamic content efficiently. Together, they form a perfect stack for everything from blogs and e-commerce sites to custom web applications.
Step 1: System Update
Before installing any packages, update the system to make sure all dependencies are current:
sudo apt update && sudo apt upgrade -y
This ensures compatibility and avoids package conflicts during the installation.
Step 2: Install Nginx
To install the Nginx web server:
sudo apt install nginx -y
After installation, start and enable Nginx to launch automatically on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Verify the installation by visiting your server’s IP address in a browser—you should see the default Nginx welcome page.
Step 3: Install MySQL
To manage your data, install MySQL:
sudo apt install mysql-server -y
After the installation, it’s recommended to secure the database:
sudo mysql_secure_installation
This step includes setting a root password, removing test databases, and disabling remote root login for added security.
Step 4: Install PHP
Next, install PHP along with the necessary extensions:
sudo apt install php-fpm php-mysql -y
The php-fpm package helps PHP integrate smoothly with Nginx using FastCGI, and php-mysql allows PHP to interact with MySQL.
You can confirm PHP installation using:
php -v
Step 5: Configure Nginx to Use PHP
Now, configure Nginx to process PHP files. Edit the default server block:
sudo nano /etc/nginx/sites-available/default
Find and modify the configuration to include the following block:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust PHP version if needed
}
Then test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 6: Test PHP Processing
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Now open http://your-server-ip/info.php in your browser. If successful, you’ll see the PHP info page, confirming everything is working.
Final Notes
You’ve now completed the essential steps to install Nginx, PHP, and MySQL on Ubuntu 24.04, forming a fully functional LEMP environment. This setup is perfect for hosting platforms like WordPress, Joomla, or any custom PHP application.
For advanced configurations, SSL setup, virtual hosts, or troubleshooting, refer to the full Vultr guide. Vultr LEMP Installation Guide
With this guide, you’re ready to build fast, scalable, and secure web applications using the latest Ubuntu platform and a trusted web stack. Whether you're a beginner or a seasoned developer, the LEMP stack on Ubuntu 24.04 provides flexibility and performance for your next web project.
Let me know if you’d like a version optimized for SEO, or tailored for Laravel, WordPress, or production server deployment.
157.49.44.75
Heman Jone
ผู้เยี่ยมชม
hemanjone162@gmail.com