Instalar Apache - Servidores Virtuales Privados

Inicio » Servidores Virtuales Privados


Esta guía explica cómo instalar, habilitar y verificar el funcionamiento del servidor web Apache en Ubuntu 22.04 y AlmaLinux 8, utilizando los comandos más recientes y confiables.


1. Instalación en Ubuntu 22.04

Paso 1: Actualizar el sistema

sudo apt update
sudo apt upgrade -y

Paso 2: Instalar Apache

sudo apt install apache2 -y

Paso 3: Habilitar y arrancar el servicio

sudo systemctl enable apache2
sudo systemctl start apache2

Paso 4: Verificar el estado

sudo systemctl status apache2

Paso 5: Permitir tráfico en el firewall (UFW)

sudo ufw allow 'Apache Full'
sudo ufw reload

Accede desde tu navegador a http://tu-ip para confirmar que Apache está en funcionamiento. Deberías ver la página de bienvenida de Apache.


2. Instalación en AlmaLinux 8

Paso 1: Actualizar los paquetes del sistema

sudo dnf update -y

Paso 2: Instalar Apache (httpd)

sudo dnf install httpd -y

Paso 3: Habilitar y arrancar el servicio

sudo systemctl enable httpd
sudo systemctl start httpd

Paso 4: Verificar el estado del servicio

sudo systemctl status httpd

Paso 5: Configurar el firewall (firewalld)

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

Una vez habilitado, abre tu navegador y accede a http://tu-ip para comprobar que Apache está funcionando correctamente.


3. Comandos útiles

  • Reiniciar Apache: sudo systemctl restart apache2 (Ubuntu) / sudo systemctl restart httpd (AlmaLinux)
  • Detener Apache: sudo systemctl stop apache2 / sudo systemctl stop httpd
  • Verificar configuración: sudo apache2ctl configtest / sudo httpd -t
  • Ver logs de acceso: /var/log/apache2/access.log / /var/log/httpd/access_log
  • Ver logs de error: /var/log/apache2/error.log / /var/log/httpd/error_log

4. Desinstalar Apache (opcional)

En Ubuntu:

sudo apt remove apache2 -y
sudo apt autoremove -y

En AlmaLinux:

sudo dnf remove httpd -y
BOT