Búsqueda de sitios web

Comandos útiles para administrar el servidor web Apache en Linux


En este tutorial, describiremos algunos de los comandos de administración de servicios Apache (HTTPD) más utilizados que usted debe conocer como desarrollador o administrador de sistemas y debe tener estos comandos a su alcance. Mostraremos comandos tanto para Systemd como para SysVinit.

Lea también: Los 10 comandos Nginx más utilizados que todo usuario de Linux debe conocer

Asegúrese de que los siguientes comandos se deben ejecutar como usuario root o sudo y deben funcionar en cualquier distribución de Linux como CentOS, RHEL, Fedora Debian y Ubuntu.

Instalar el servidor Apache

Para instalar el servidor web Apache, utilice su administrador de paquetes de distribución predeterminado como se muestra.

sudo apt install apache2	    [On Debian/Ubuntu]
sudo yum install httpd	    [On RHEL/CentOS]
sudo dnf install httpd	    [On Fedora 22+]
sudo zypper install apache2	    [On openSUSE]

Verifique la versión de Apache

Para verificar la versión instalada de su servidor web Apache en su sistema Linux, ejecute el siguiente comando.

sudo httpd -v
OR
sudo apache2 -v
Salida de muestra
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

Si desea mostrar el número de versión de Apache y la configuración de compilación, utilice el indicador -V como se muestra.

sudo httpd -V
OR
sudo apache2 -V
Salida de muestra
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09
Server's Module Magic Number: 20120211:24
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Verifique los errores de sintaxis de configuración de Apache

Para verificar sus archivos de configuración de Apache en busca de errores de sintaxis, ejecute el siguiente comando, que verificará la validez de los archivos de configuración, antes de reiniciar el servicio.

sudo httpd -t
OR
sudo apache2ctl -t
Salida de muestra
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using linux-console.net. 
Set the 'ServerName' directive globally to suppress this message
Syntax OK

Iniciar el servicio Apache

Para iniciar el servicio Apache, ejecute el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl start httpd     [On Systemd]
sudo service httpd start 	 [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl start apache2   [On Systemd]
sudo service apache2 start     [On SysVInit]

Habilitar el servicio Apache

Mientras tanto, el comando anterior solo inicia el servicio Apache; para permitir que se inicie automáticamente en el inicio del sistema, ejecute el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl enable httpd     [On Systemd]
sudo chkconfig httpd on 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl enable apache2   [On Systemd]
sudo chkconfig apache2 on       [On SysVInit]

Reiniciar el servicio Apache

Para reiniciar Apache (detener y luego iniciar el servicio), ejecute el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl restart httpd     [On Systemd]
sudo service httpd restart 	   [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl restart apache2   [On Systemd]
sudo service apache2 restart     [On SysVInit]

Ver el estado del servicio Apache

Para verificar la información del estado del tiempo de ejecución del servicio Apache, ejecute el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl status httpd     [On Systemd]
sudo service httpd status 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl status apache2   [On Systemd]
sudo service apache2 status     [On SysVInit]

Recargar el servicio Apache

Si ha realizado algún cambio en la configuración del servidor Apache, puede indicarle al servicio que vuelva a cargar su configuración ejecutando el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl reload httpd     [On Systemd]
sudo service httpd reload 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl reload apache2   [On Systemd]
sudo service apache2 reload     [On SysVInit]

Detener el servicio Apache

Para detener el servicio Apache, utilice el siguiente comando.

------------ On CentOS/RHEL ------------ 
sudo systemctl stop httpd       [On Systemd]
sudo service httpd stop 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl stop apache2     [On Systemd]
sudo service apache2 stop     [On SysVInit]

Mostrar ayuda del comando Apache

Por último, pero no menos importante, puede obtener ayuda sobre los comandos del servicio Apache en systemd ejecutando el siguiente comando.

sudo httpd -h
OR
sudo apache2 -h		
OR
systemctl -h apache2	
Salida de muestra
Usage: httpd [-D name] [-d directory] [-f file]
             [-C "directive"] [-c "directive"]
             [-k start|restart|graceful|graceful-stop|stop]
             [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in  directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules 
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

Puedes encontrar más información sobre systemctl consultando: Cómo administrar servicios y unidades ‘Systemd’ usando ‘Systemctl’ en Linux.

Quizás también te interese leer los siguientes artículos relacionados con Apache.

  1. 5 consejos para aumentar el rendimiento de su servidor web Apache
  2. Cómo monitorear la carga del servidor web Apache y las estadísticas de la página
  3. Cómo administrar el servidor web Apache utilizando la herramienta “Apache GUI”
  4. Cómo cambiar el puerto HTTP de Apache en Linux
  5. 13 consejos de seguridad y refuerzo del servidor web Apache
  6. Proteja Apache contra ataques de fuerza bruta o DDoS utilizando los módulos Mod_Security y Mod_evasive

¡Eso es todo por ahora! En este artículo, explicamos los comandos de administración de servicios Apache/HTTPD más utilizados que usted debe conocer, incluidos iniciar, habilitar, reiniciar y detener Apache. Siempre puede comunicarse con nosotros a través del formulario de comentarios a continuación si tiene alguna pregunta o comentario.