miércoles, 15 de octubre de 2025

Instalación de Apache2 en Ubuntu 20

  Instalar servidor apache

$ sudo apt install apache2

Administrar el servicio apache2

En esta parte aprenderemos cómo iniciar, detener o reiniciar el servicio apache2, usando el comando systemctl, systemctl forma parte de la suite systemd (systemd es un reemplazo para el sistema de inicialización SysV y también un conjunto de configuración y gestión de servicios para el sistema operativo GNU/Linux)


Comprobar estado

Con el siguiente comando comprobamos si el servidor web se está ejecutando exitosamente, note la linea Active: active (running)


$ sudo systemctl status apache2

● apache2.service - The Apache HTTP Server

     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)

     Active: active (running) since Sat 2020-10-31 15:02:47 UTC; 1h 25min ago

       Docs: https://httpd.apache.org/docs/2.4/

    Process: 620 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)

    Process: 1611 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)

   Main PID: 666 (apache2)

      Tasks: 55 (limit: 1075)

     Memory: 9.7M

     CGroup: /system.slice/apache2.service

             ├─ 666 /usr/sbin/apache2 -k start

             ├─1615 /usr/sbin/apache2 -k start

             └─1643 /usr/sbin/apache2 -k start

...

Iniciar el servicio

En caso de que el servicio esté detenido: Active: inactive puede iniciarlo ejecutando el siguiente comando:


$ sudo systemctl start apache2

Reiniciar el servicio

Para aplicar cualquier modificación realizada al fichero de configuración debe reiniciar el servidor con el siguiente comando:


$ sudo systemctl restart apache2

Refrescar configuraciones

Es preferible usar el siguiente comando para refrescar las configuraciónes ya que el servicio recargará las configuraciones sin perder las conexiones.


$ sudo systemctl reload apache2

Detener el servidor

Si desea detener el servicio ejecute el siguiente comando:


$ sudo systemctl stop apache2

Iniciar con el sistema operativo

Puede asegurarse de que el servicio apache2 se iniciará automáticamente después de un reinicio del sistema operativo ejecutando el siguiente comando:


$ sudo systemctl is-enabled apache2

enabled

El resultado del comando anterior es enabled o disabled, en caso de de que sea disable ejecute:


$ sudo systemctl enable apache2

Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable apache2

Si desea que no se inicie con el sistema operativo ejecute:


$ sudo systemctl disable apache2

Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install disable apache2

Removed /etc/systemd/system/multi-user.target.wants/apache2.service.

Verificar modulos cargados

Apache presenta una arquitectura modular la cual permite extender las funcionalidades básicas mediante la selección de un conjunto de módulos: los módulos son compilados como Dynamic Shared Objects (DSO) y prodrán activarse y desactivarse a través de la directiva LoadModule.


Con el siguiente comando verificamos cuales son los módulos activos.


$  apachectl -M

Loaded Modules:

 core_module (static)

 so_module (static)

 watchdog_module (static)

 http_module (static)

 log_config_module (static)

 logio_module (static)

 version_module (static)

 unixd_module (static)

 access_compat_module (shared)

 alias_module (shared)

 auth_basic_module (shared)

 authn_core_module (shared)

 authn_file_module (shared)

 authz_core_module (shared)

 authz_host_module (shared)

 authz_user_module (shared)

 autoindex_module (shared)

 deflate_module (shared)

 dir_module (shared)

 env_module (shared)

 filter_module (shared)

 mime_module (shared)

 mpm_event_module (shared)

 negotiation_module (shared)

 reqtimeout_module (shared)

 setenvif_module (shared)

 status_module (shared)

Habilitar mod_rewrite

mod_rewrite es un podoreso y sofisticado módulo del servidor web Apache que permite la rescritura de urls haciendo uso de expresiones regulares (PCRE).


$ sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

$ sudo systemctl restart apache2


Importante correr estos comandos 

   a2enmod rewrite

   systemctl restart apache2

   apt install libapache2-mod-php