Comandos úteis para gerenciar o servidor da Web Apache no Linux
Neste tutorial, descreveremos alguns dos comandos de gerenciamento de serviços mais usadosdo Apache (HTTPD) que você deve conhecer como desenvolvedor ou administrador do sistema e deve manter esses comandos ao alcance dos seus dedos. Mostraremos comandos para Systemd e SysVinit .
Certifique-se de que os comandos a seguir devem ser executados como um usuário root ou sudo e devem funcionar em qualquer distribuição Linux, como CentOS , RHEL , Fedora Debian e Ubuntu .
Instalar o Apache Server
Para instalar o servidor da web Apache, use o gerenciador de pacotes de distribuição padrão, conforme mostrado.
$ 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 a versão do Apache
Para verificar a versão instalada do seu servidor da web Apache em seu sistema Linux, execute o seguinte comando.
$ sudo httpd -v OR $ sudo apache2 -v
Server version: Apache/2.4.6 (CentOS) Server built: Nov 5 2018 01:47:09
Se você deseja exibir o número da versão do Apache e as configurações de compilação, use o sinalizador -V
conforme mostrado.
$ sudo httpd -V OR $ sudo apache2 -V
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"
Verificar erros de sintaxe de configuração do Apache
Para verificar os arquivos de configuração do Apache em busca de erros de sintaxe, execute o seguinte comando, que verificará a validade dos arquivos de configuração antes de reiniciar o serviço.
$ sudo httpd -t OR $ sudo apache2ctl -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using tecmint.com. Set the 'ServerName' directive globally to suppress this message Syntax OK
Iniciar o serviço Apache
Para iniciar o serviço Apache , execute o seguinte 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]
Ativar o serviço Apache
O comando anterior apenas inicia o serviço Apache, entretanto, para permitir que ele inicie automaticamente na inicialização do sistema, execute o seguinte 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]
Reinicie o serviço Apache
Para reiniciar o Apache ( pare e, em seguida, inicie o serviço), execute o seguinte 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]
Visualizar o status do serviço Apache
Para verificar as informações de status do tempo de execução do serviço Apache, execute o seguinte 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]
Recarregue o serviço Apache
Se você tiver feito alterações na configuração do servidor Apache, poderá instruir o serviço a recarregar sua configuração executando o seguinte 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]
Pare o serviço Apache
Para parar o serviço Apache , use o seguinte 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 a Ajuda do Comando do Apache
Por último, mas não menos importante, você pode obter ajuda sobre os comandos de serviço Apache em systemd executando o seguinte comando.
$ sudo httpd -h OR $ sudo apache2 -h OR $ systemctl -h apache2
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)
Você pode encontrar mais informações sobre o systemctl consultando: Como gerenciar serviços e unidades do "Systemd" usando o "Systemctl" no Linux.
Você também pode gostar de ler estes artigos relacionados ao Apache.
- 5 Tips to Boost the Performance of Your Apache Web Server
- How to Monitor Apache Web Server Load and Page Statistics
- How to Administrate the Apache Web Server Using “Apache GUI” Tool
- How to Change Apache HTTP Port in Linux
- 13 Apache Web Server Security and Hardening Tips
- Protect Apache Against Brute Force or DDoS Attacks Using Mod_Security and Mod_evasive Modules
É tudo por agora! Neste artigo, explicamos os comandos de gerenciamento de serviços Apache/HTTPD mais usadosque você deve saber, incluindo inicialização, ativação, reinício e interrupção do Apache. Você sempre pode entrar em contato através do formulário de comentários abaixo para quaisquer perguntas ou comentários.