How to install LEMP stack (Linux + Nginx + MySQL + PHP)
To run modern websites and applications, the LEMP stack is often used: Linux, Nginx, MySQL/MariaDB and PHP. This combination combines stability and high performance, allowing you to quickly process requests and work with dynamic content.
LEMP is suitable for web services of any scale: personal blog, corporate websites, online stores and applications of any complexity. Flexible configuration and low resource consumption make it a popular solution among developers and system administrators.
In this article we will look at how to install a LEMP stack step by step.
Step 1: Prepare the server
- Connect to the server via SSH
- Create a new user (so as not to work as root):
adduser userName - Give him administrator rights:
usermod -aG sudo userName - Switch to new user:
su - userName - Update the system:
sudo apt-get update && sudo apt-get upgrade -y
Step 2. Install and configure Nginx
- Install the web server:
sudo apt-get install nginx - Open ports in the firewall:For HTTP (80):
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPTsudo iptables-save
For HTTPS (443):sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPTsudo iptables-save - Go to the server IP address — the standard Nginx page should open.
Step 3: Install and Configure MySQL
- Install the DBMS. In our case it will be MySQL:
sudo apt-get install mysql-server - Connect to MySQL as root:
mysql -u root -p - Create a user:
CREATE USER 'user-name'@'localhost' IDENTIFIED BY 'password';GRANT ALL PRIVILEGES ON *.* TO 'user-name'@'localhost';FLUSH PRIVILEGES; - Create a database:
CREATE DATABASE BaseName;
Step 4: Install and Configure PHP
- Install PHP and modules:
sudo apt-get install php-fpm php-mysql - Determine PHP Version
php -v - Open the php.ini settings file:
sudo nano /etc/php/X.X/fpm/php.ini(instead of X.X, substitute your version, for example 7.4). - Find the line
;cgi.fix_pathinfo=1 - Remove ; and replace with:
cgi.fix_pathinfo=0 - Restart PHP:
sudo systemctl restart phpX.X-fpm
Step 5. Configure Nginx to work with PHP
- Open the configuration:
sudo nano /etc/nginx/sites-available/default - Make changes:
add to the index lineindex.php;
in server_name specify the domain or IP;
uncomment the blocklocation ~ .php$and configurefastcgi_pass unix:/run/php/phpX.X-fpm.sock;
uncomment the blocklocation ~ /.ht. - Check the file for errors:
sudo nginx -t - Restart Nginx:
sudo systemctl reload nginx
Step 6. Check the server operation
- Create a test file:
sudo bash -c 'echo "<?php phpinfo(); ?>" > /var/www/html/info.php - Go to your browser to:
http://IP_server/info.php - Make sure the PHP options page opens.
- Remove the test file:
sudo rm /var/www/html/info.php
Everything is ready: the LEMP stack is now installed and configured on the server. You can host websites and connect databases.
CONTENT:
Similar
Похожее
Все новости
Adaxa Suite: подробный обзор ERP-системы корпоративного класса
Adaxa Suite — комплексная ERP-платформа для компаний, которым уже тесно в рамках простых учётных систем, но которые при этом не готовы идти в сторону дорогих корпоративных решений уровня SAP или Oracle. Изначально продукт создавался для среднего бизнеса, которому нужна большой набор функций, сквозная автоматизация процессов и надёжная архитектура без чрезмерной стоимости владения. Архитектура и техническая […]
Как заказать дополнительные IP-адреса на UFO.Hosting: пошаговая инструкция
По мере роста проекта одного IP-адреса может стать недостаточно. Это типичная ситуация для компаний, которые масштабируют инфраструктуру, запускают новые сервисы или разделяют внутренние процессы. В UFO.Hosting подключение дополнительных IP-адресов выполняется через биллинговую панель и занимает всего несколько минут. Важно: возможность для заказа дополнительных IP-адресов доступна для тарифов VPS начиная с Haedus. Зачем нужны дополнительные IP-адреса […]