Pila LEMP significa pila Linux, Nginx, MariaDB y PHP y se usa ampliamente para alojar sitios web/blogs.
Aquí, veremos cómo instalar LEMP Stack en Ubuntu 18.04 con soporte PHP (a través de PHP-FPM) y soporte de base de datos (MariaDB).
Instalar la pila LEMP
Instalar Linux
Aquí está el tutorial sobre la instalación paso a paso de Ubuntu 18.04 y la actualización de Ubuntu 16.04 y Ubuntu 17.10 a Ubuntu 18.04.
Continúe con la instalación de EMP (Nginx versión 1.17.2, PHP versión 7.2, MariaDB versión 10.1.40) en Ubuntu 18.04.
Instalar Nginx
Nginx es un servidor web HTTP gratuito, de código abierto y de alto rendimiento y es conocido por su estabilidad, configuración simple y bajo consumo de recursos.
Actualizar el índice del repositorio.
sudo apt update
Instale los siguientes paquetes.
sudo apt install -y wget gnupg2 ca-certificates
Descargue la clave de firma del repositorio de Nginx del sitio web oficial.
wget http://nginx.org/keys/nginx_signing.key
Agregue la clave pública de Nginx al sistema.
sudo apt-key add nginx_signing.key
Agregue el repositorio Nginx a su sistema.
echo "deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu bionic nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Instale el paquete Nginx usando el siguiente comando.
sudo apt update sudo apt install -y nginx
Inicie el servicio Nginx después de la instalación.
sudo systemctl start nginx
Abra un navegador web y visite la siguiente URL.
http://tu-dirección-ipDebería ver la página predeterminada de Nginx, y esto le confirma que Nginx se instaló correctamente en el servidor.
La raíz de documentos predeterminada de Nginx en Ubuntu 18.04 es /usr/share/nginx/html/ y los archivos de configuración se encuentran en el directorio /etc/nginx/.
Inicio automático de Nginx al iniciar el sistema.
sudo systemctl enable nginx
Instalar servidor MariaDB
Instale el servidor MariaDB emitiendo el siguiente comando.
De forma predeterminada, Ubuntu 18.04 incluye MariaDB v10.1, que es un poco más antigua que la versión disponible en el repositorio oficial de MariaDB (v10.4). Puede instalar MariaDB v10.4 siguiendo los pasos en la siguiente URL.Cómo instalar MariaDB en Ubuntu 18.04
sudo apt install -y mariadb-server mariadb-client
A continuación, haga que el servidor MariaDB sea seguro mediante el comando mysql_secure_installation.
mysql_secure_installation
Salida:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): << No root password. Just press Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y << Set MariaDB root password New password: << Enter root password Re-enter new password: << Re-enter root password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y << Remove anonymous users ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y << Disallow root login remotely ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y << Remove test database - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y << Reload privilege ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Instalar PHP-FPM
Instale PHP a través de PHP-FPM (PHP-FastCGI Process Manager), una implementación alternativa de PHP FastCGI. Proporciona funciones adicionales útiles para sitios de mayor tamaño.
De forma predeterminada, Ubuntu 18.04 incluye PHP-FPM v7.2. También puede instalar PHP-FPM v7.3 siguiendo los pasos en la siguiente URL.Cómo instalar PHP 7.3 en Ubuntu 18.04
Instale php-fpm usando el siguiente comando.
sudo apt install -y php-fpm php-mysql php-cli
PHP-FPM escucha en el socket /run/php/php7.2-fpm.sock por defecto.
Para hacer que PHP-FPM use la conexión TCP, edite el siguiente archivo.
sudo nano /etc/php/7.2/fpm/pool.d/www.conf
Luego, cambie el parámetro de escucha.
listen = /run/php/php7.2-fpm.sock
PARA:
listen = 127.0.0.1:9000
Reinicie el proceso PHP-FPM y permita que se inicie automáticamente al iniciar el sistema.
sudo systemctl restart php7.2-fpm sudo systemctl enable php7.2-fpm
Pila LEMP de prueba
Vamos a crear un host virtual basado en nombres en el servidor Nginx para obtener los siguientes detalles.
Nombre de dominio: web.itzgeek.local
Raíz del documento: /usr/share/nginx/html/web.itzgeek.local
Primero, cree un archivo de configuración de host virtual para nuestro dominio en el directorio /etc/nginx/conf.d/.
sudo nano /etc/nginx/conf.d/web.itzgeek.local.conf
Agrega el siguiente contenido.
server { server_name web.itzgeek.local; root /usr/share/nginx/html/web.itzgeek.local; location / { index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Cree el directorio raíz para nuestro host virtual.
sudo mkdir -p /usr/share/nginx/html/web.itzgeek.local
Para probar la compatibilidad con PHP-FPM, coloque un archivo PHP en la raíz del documento del host virtual creado.
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/web.itzgeek.local/index.php
Actualice el permiso del archivo.
sudo chown -R www-data:www-data /usr/share/nginx/html/web.itzgeek.local/
Reinicie los servicios.
sudo systemctl restart nginx sudo systemctl restart php7.2-fpm
Cree una entrada de host para su dominio (web.itzgeek.local) en el archivo /etc/hosts en caso de que su entorno no tenga un servidor DNS para la resolución de nombres.
nano /etc/hosts
Agregue una entrada de host similar a la siguiente.
192.168.1.10 web.itzgeek.local web
Abra su navegador web y escriba su nombre de dominio en la dirección web.
http://web.itzgeek.localLa página se verá como a continuación:
De la captura de pantalla anterior, PHP está funcionando a través de FPM/FastCGI , como se muestra en la línea de la API del servidor.
Si se desplaza hacia abajo en la página, verá el soporte de MariaDB.
Conclusión
Eso es todo. Espero que haya aprendido a instalar la pila LEMP en Ubuntu 18.04. Considere instalar el certificado Let's Encrypt SSL para su sitio para mejorar la seguridad. Comparta sus comentarios en la sección de comentarios.