GNU/Linux >> Tutoriales Linux >  >> Cent OS

Instale y configure Drupal 8 con Nginx y Lets Encrypt en CentOS 8

Drupal es un sistema de administración de contenido gratuito, de código abierto y escalable que las personas pueden utilizar para crear y administrar cualquier tipo de sitio web. Está escrito en PHP y usa MySQL/MariaDB para almacenar sus datos. Drupal proporciona un amplio conjunto de funciones que se pueden ampliar con miles de complementos. Drupal admite una gran cantidad de servidores web, incluidos Apache, Nginx, IIS, Lighttpd y bases de datos MySQL, MariaDB, MongoDB, SQLite, PostgreSQL y el servidor MS SQL. Drupal viene con una interfaz de usuario web simple y fácil de usar que le permite crear sitios web sin ningún conocimiento de codificación.

En este tutorial, le mostraremos cómo instalar Drupal 8 en el servidor CentOS 8 y protegerlo con SSL gratuito de Let's Encrypt.

Requisitos

  • Un servidor que ejecuta CentOS 8.
  • Un nombre de dominio válido apuntado con la IP de su servidor
  • Se configura una contraseña raíz en el servidor.

Instalar Nginx, MariaDB y PHP

Antes de comenzar, deberá instalar el servidor LEMP en su servidor. Puede instalarlo ejecutando el siguiente comando:

dnf install nginx mariadb-server php php-fpm php-cli php-mbstring php-gd php-xml php-curl php-mysqlnd php-pdo php-json php-opcache -y

Una vez instalado, inicie el servicio Nginx, MariaDB y php-fpm y habilítelos para que se inicien después de reiniciar el sistema con el siguiente comando:

systemctl start nginx
systemctl start php-fpm
systemctl start mariadb
systemctl enable nginx
systemctl enable php-fpm
systemctl enable mariadb

Configurar base de datos

De forma predeterminada, MariaDB no está protegida, por lo que deberá protegerla. Puede asegurarlo ejecutando el siguiente comando:

mysql_secure_installation

Responda todas las preguntas como se muestra a continuación:

Enter current password for root (enter for none):
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Una vez que haya terminado, inicie sesión en el shell de MariaDB con el siguiente comando:

mysql -u root -p

Proporcione su contraseña raíz cuando se le solicite y luego cree una base de datos y un usuario para Drupal con el siguiente comando:

MariaDB [(none)]> CREATE DATABASE drupaldb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
MariaDB [(none)]> CREATE USER [email protected] IDENTIFIED BY "password";

Luego, otorgue todos los privilegios a drupaldb con el siguiente comando:

MariaDB [(none)]> GRANT ALL ON drupaldb.* TO [email protected] IDENTIFIED BY "password";

A continuación, elimine los privilegios y salga del shell de MariaDB con el siguiente comando:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Descargar Drupal

Primero, deberá descargar la última versión de Drupal desde su sitio web oficial. Puedes descargarlo con el siguiente comando:

wget https://ftp.drupal.org/files/projects/drupal-8.7.10.tar.gz

Una vez descargado, extraiga el archivo descargado con el siguiente comando:

tar -xvzf drupal-8.7.10.tar.gz

A continuación, mueva el directorio extraído al directorio raíz web de Nginx con el siguiente comando:

mv drupal-8.7.10 /var/www/html/drupal

A continuación, cree un directorio para almacenar archivos del sitio web y cambie el nombre del archivo default.settings.php como se muestra a continuación:

mkdir /var/www/html/drupal/sites/default/files
cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php

A continuación, cambie la propiedad del directorio de Drupal a nginx como se muestra a continuación:

chown -R nginx:nginx /var/www/html/drupal/

Configurar Nginx para Drupal

Primero, cree un archivo de configuración php-fpm para Drupal con el siguiente comando:

nano /etc/php-fpm.d/drupal.conf

Agregue las siguientes líneas:

[drupal]
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen = /run/php-fpm/drupal.sock
pm = ondemand
pm.max_children =  50
pm.process_idle_timeout = 10s
pm.max_requests = 500
chdir = /

Guarde y cierre el archivo cuando haya terminado. Luego, cree un archivo de configuración de host virtual Nginx para Drupal:

nano /etc/nginx/conf.d/drupal.conf

Agregue las siguientes líneas:

server {
    listen 80;
    server_name example.com;

    root /var/www/html/drupal;

    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }


    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        include fastcgi_params;
       	# Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/run/php-fpm/drupal.sock;
    }
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }
}

Guarde y cierre el archivo. Luego, reinicie el servicio php-fpm y Nginx para aplicar los cambios:

systemctl restart php-fpm
systemctl restart nginx

Configurar SELinux y Firewall

De manera predeterminada, SELinux está habilitado en CentOS 8. Por lo tanto, deberá configurar SELinux para que Drupal funcione correctamente.

Primero, permite que Drupal escriba en los directorios de archivos públicos y privados con el siguiente comando:

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/drupal(/.*)?"
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/settings.php'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/files'
restorecon -Rv /var/www/html/drupal
restorecon -v /var/www/html/drupal/sites/default/settings.php
restorecon -Rv /var/www/html/drupal/sites/default/files

A continuación, permite que Drupal envíe correos electrónicos salientes con el siguiente comando:

setsebool -P httpd_can_sendmail on

A continuación, deberá crear una regla de firewall para permitir el servicio HTTP y HTTPS desde redes externas. Puedes permitirlo con el siguiente comando:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Asegure Drupal con Let's Encrypt SSL

Drupal ahora está instalado y configurado. Es hora de protegerlo con SSL gratuito de Let's Encrypt.

Para hacerlo, deberá descargar el cliente certbot en su servidor. Puede descargar y establecer el permiso correcto ejecutando el siguiente comando:

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

Ahora, ejecute el siguiente comando para obtener e instalar un certificado SSL para su sitio web de Drupal.

certbot-auto --nginx -d example.com

El comando anterior instalará primero todas las dependencias requeridas en su servidor. Una vez instalado, se le pedirá que proporcione una dirección de correo electrónico y acepte el término del servicio como se muestra a continuación:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y 


Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/drupal.conf

A continuación, deberá elegir si desea redirigir o no el tráfico HTTP a HTTPS, como se muestra a continuación:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Escriba 2 y presione Entrar para continuar. Una vez finalizada la instalación, debería ver el siguiente resultado:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/drupal.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-03-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Acceder al sitio web de Drupal

Ahora, abra su navegador web y escriba la URL https://example.com . Será redirigido a la siguiente página:

Seleccione el idioma deseado y haga clic en Guardar y continuar botón. Debería ver la siguiente página:

Elija su perfil de instalación y haga clic en Guardar y continuar botón. Debería ver la siguiente página:

Proporcione los detalles de su base de datos y haga clic en Guardar y continuar botón. Debería ver la siguiente página:

Proporcione el nombre de su sitio, el nombre de usuario del administrador, la contraseña y haga clic en Guardar y continuar botón. Deberías ver tu tablero de Drupal en la siguiente página:

¡Felicidades! Ha instalado y asegurado con éxito Drupal en el servidor CentOS 8.


Cent OS
  1. Cómo instalar y configurar Nginx en CentOS 7

  2. Asegure Nginx con Lets Encrypt en CentOS 7

  3. Asegure Apache con Lets Encrypt en CentOS 7

  4. Cómo instalar y configurar Askbot con Nginx en CentOS 7

  5. Cómo instalar OwnCloud 8 con Nginx y MariaDB en CentOS 7

Cómo instalar Askbot con Nginx y Secure con Lets Encrypt en CentOS 8

Cómo instalar Drupal con Nginx y Lets Encrypt SSL en Ubuntu 20.04 LTS

Cómo instalar Drupal 9 con Nginx y Lets Encrypt SSL en Debian 10

Cómo instalar Shopware 6 con NGINX y Lets Encrypt en CentOS 8

Cómo Instalar PrestaShop con Apache y Lets Encrypt SSL en CentOS 8

Instalación y configuración de PhpMyAdmin con Nginx en CentOS 7