
The LEMP stack combines Linux, Nginx, MySQL, and PHP to serve dynamic websites and applications. It provides a powerful foundation for hosting PHP-based applications with Nginx's high-performance web server, MySQL's robust database management, and PHP's server-side scripting capabilities. The Vultr Marketplace provides a pre-configured LEMP instance, enabling quick deployment and setup on a Vultr server.
This guide explains deploying and using Vultr's LEMP Marketplace Application. You will deploy an instance, verify the installation, configure DNS and SSL, set up a virtual host, secure MySQL, and implement best practices for production deployments.
Log in to your Vultr Console and click the Deploy Server button.
Select your preferred server type.
Choose a server location.
Select a server plan with at least 1GB RAM and 1 CPU core for basic workloads, or 2GB RAM and 2 CPU cores for production applications.
Click the Configure button to proceed.
Under Marketplace Apps, search for LEMP and select it as the Marketplace Application.
Select the Limited Login option from the Additional Features section to create a limited user with sudo access.
Review your configurations and click the Deploy Now button to start deployment.
It may take up to 10 minutes for your server to finish installing the LEMP stack.
After the instance shows the status of Running, navigate to the Server Overview page and copy the SSH connection details.
After deployment, verify the installation, configure DNS, and secure your LEMP stack before hosting applications.
Create a DNS A record pointing to your server's IP address, such as lemp.example.com.
Connect to your Vultr server instance over SSH using the connection details from the Server Overview page.
Check the Nginx service status.
The service should show as active (running).
Verify the PHP installation.
Output:
Check the MySQL service status.
The service should show as active (running).
Verify Nginx is serving the default page by visiting http://SERVER_IP in a web browser.
Secure your server by configuring the firewall to allow only necessary traffic before enabling SSL.
Allow SSH connections.
Allow HTTP and HTTPS traffic for Nginx and Certbot.
Enable the firewall.
Verify firewall status.
Protect your web server with HTTPS using Let's Encrypt certificates via Certbot.
Install Certbot and the Nginx plugin.
Request an SSL certificate for your domain.
Follow the prompts and select the option to redirect HTTP traffic to HTTPS when asked.
Verify SSL certificate auto-renewal.
Access your site securely at https://lemp.example.com.
Set up a virtual host to serve your website with proper configurations for PHP applications.
Create a directory for your website.
Set proper ownership.
Set safe directory permissions.
Create a test index file.
Save and close the file.
Create an Nginx virtual host configuration.
Replace lemp.example.com with your domain name and adjust the PHP-FPM socket path if needed.
Save and close the file.
Enable the virtual host.
Disable the default Nginx site.
Test the Nginx configuration.
Output:
Reload Nginx to apply changes.
Run Certbot again to configure SSL for the new virtual host.
Access your site at https://lemp.example.com to verify the test page loads with SSL.
Set up MySQL with secure authentication and create a database for your application.
Run the MySQL secure installation script.
Follow the prompts:
Log in to MySQL as root.
Enter the root password when prompted.
Create a database for your application.
Create a dedicated database user.
Replace secure_password_here with a strong password.
Grant privileges to the user.
Flush privileges and exit.
Test the new user connection.
Enter the password when prompted. If you can access the database, the setup is correct.
Optimize PHP settings for production use and security.
Edit the PHP-FPM configuration file.
Update the following settings for production use.
Adjust values based on your application requirements.
Save and close the file.
Create the PHP log directory.
Restart PHP-FPM to apply changes.
Install frequently used PHP extensions.
Restart PHP-FPM after installing extensions.
Verify installed extensions.
Implement these recommendations to ensure your LEMP stack runs securely and efficiently.
Configure Nginx security headers in your virtual host.
Add the following inside the server block:
Save, close, and reload Nginx.
Disable PHP version exposure.
Set:
Restart PHP-FPM: sudo systemctl restart php8.3-fpm
Keep the system and packages updated.
Enable PHP OPcache for better performance.
Restart PHP-FPM.
Configure Nginx client body size for uploads.
Add inside the http block:
Reload Nginx.
Create regular backups of important directories.
Back up MySQL databases.
This section covers common issues and diagnostic commands to help resolve problems with your LEMP stack.
Verify all services are running.
View service logs.
Check PHP-FPM status and restart if needed.
Verify the PHP-FPM socket path matches the Nginx configuration.
Verify PHP-FPM is running.
Check that the Nginx virtual host includes the PHP location block.
Restart both services.
Set proper ownership for web directories.
Check Nginx and PHP-FPM are running as the same user.
Verify MySQL is running and accessible.
Check user privileges.
The LEMP stack provides a flexible environment suitable for various PHP-based web workloads:
In this guide, you deployed Vultr's LEMP Marketplace Application and configured it for production use. You secured the server with firewall rules and SSL/TLS certificates, set up Nginx virtual hosts with proper permissions, configured MySQL with secure authentication and dedicated database users, and optimized PHP settings for performance and security. With this production-ready LEMP stack, you can host PHP applications, manage databases, and serve dynamic content efficiently.
0 Comments
Be the first to comment and share your perspective with the community.