This comprehensive tutorial will guide you through the process of setting up a LEMP (Linux, NGINX, MariaDB, PHP) stack on a Debian VPS. A LEMP stack (Linux, NGINX, MariaDB, PHP) is a popular web server configuration known for its performance, scalability, and security. It is commonly used to host websites and web applications. By following this detailed guide, you can establish a robust and reliable foundation for hosting your website or web application on your Debian VPS.
Prerequisites
Before embarking on this tutorial, ensure you have the following prerequisites in place:
-
A Debian VPS with SSH Access: You will need a Debian VPS with SSH access to perform the installation and configuration steps.
-
Root or Sudo User Account: You will need to have a root user account or a sudo user account with administrative privileges to execute the necessary commands.
-
Basic Linux Knowledge: Familiarity with basic Linux commands and file system navigation will be beneficial.
Steps
Step 1: Install the Software
- Update the package manager cache:
sudo apt update
- Install the LEMP stack software:
sudo apt install nginx python3-certbot-nginx php-fpm php-mysql zip unzip pwgen
- Install MariaDB:
sudo apt install mariadb-server
Step 2: Configure the Software
- Secure the MariaDB installation:
sudo mysql_secure_installation && sudo mysql_upgrade
- Configure Certbot to obtain SSL certificates:
sudo certbot --nginx -d $(hostname) -d vmXXXX.contaboserver.net
- PHP configuration:
sudo grep "listen =" /etc/php/7.3/fpm/pool.d/www.conf
- NGINX configuration:
sudo open /etc/nginx/sites-enabled/default
- Restart NGINX:
sudo systemctl restart nginx
Step 3: Install and Configure phpMyAdmin
- Download phpMyAdmin:
sudo mkdir /var/www/phpmyadmin
sudo cd /var/www/phpmyadmin/
sudo wget [https://files.phpmyadmin.net/phpMyAdmin/5.0.0-alpha1/phpMyAdmin-5.0.0-alpha1-all-languages.zip](https://files.phpmyadmin.net/phpMyAdmin/5.0.0-alpha1/phpMyAdmin-5.0.0-alpha1-all-languages.zip)
sudo unzip phpMyAdmin-5.0.0-alpha1-all-languages.zip
sudo mv phpMyAdmin-5.0.0-alpha1-all-languages/* .
- Create a database user and import the database:
sudo mysql < sql/create_tables.sql
sudo mysql
CREATE USER 'phpmyadminuser'@'localhost' IDENTIFIED BY 'USE ONLY SECURE PASSWORDS !!';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'phpmyadminuser'@'localhost'
IDENTIFIED BY 'USE ONLY SECURE PASSWORDS !!';
FLUSH PRIVILEGES;
- Configure phpMyAdmin:
sudo cp -p config.sample.inc.php config.inc.php
sudo chown www-data: /var/www/phpmyadmin -R
- Configure NGINX for phpMyAdmin:
sudo open /etc/nginx/sites-enabled/domain_name
Additional Tips and Considerations
- Regularly update your software: To ensure your system remains secure and up-to-date, regularly update your software packages using the following command:
sudo apt update && sudo apt upgrade
-
Monitor system performance: Keep an eye on your system’s performance metrics, such as CPU usage, memory consumption, and disk I/O, to identify potential bottlenecks or resource constraints.
-
Implement security measures: Take additional security measures to protect your server by enabling firewall rules, implementing intrusion detection systems, and regularly scanning for vulnerabilities.
-
Consider using a control panel: Consider installing a web-based control panel like cPanel or Plesk to manage multiple websites or require a more user-friendly interface.
Conclusion
LEMP is a powerful and versatile web server stack that can support a wide range of web applications. By carefully following the guidelines and delving into the advanced topics presented in this comprehensive tutorial, you can effectively configure, optimize, and manage your LEMP stack. This will lay the foundation for a reliable, scalable, and high-performance web infrastructure that supports your online presence and empowers your web applications to thrive.