redhat:web-server-redhat:apache:apache24-on-redhat

This is an old revision of the document!


How to Install Apache on CentOS 8

Apache HTTP server is the most widely used web server in the world. It is a free, open-source, and cross-platform HTTP server, including powerful features, and can be extended by a wide variety of modules.

In this tutorial, I explain how to install and manage the Apache webserver on CentOS 8.

Apache is available in the default CentOS repositories, and the installation is pretty straight forward.

On RHEL based distributions, the Apache package and service are called httpd. To install the Apache run the following command as root or user with sudo privileges:

# yum install httpd

Once the installation is complete, enable and start the Apache service:

# systemctl enable httpd --now

To verify that the service is running, check its status:

# systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-10-12 15:54:58 UTC; 6s ago
  ...

FirewallD is the default firewall solution on Centos 8.

During the installation, Apache creates firewalld service files with predefined rules for allowing access to HTTP (80) and HTTPS (443) ports.

The following commands will permanently open the necessary ports:

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

This section explains how the Apache configuration files are structured and the best practices for managing the Apache webserver.

  • All Apache configuration files are located in the /etc/httpd directory.
  • The main Apache configuration file is /etc/httpd/conf/httpd.conf.
  • Configuration files ending with .conf located in the /etc/httpd/conf.d directory are included in main Apache configuration file.
  • Configuration files that are responsible for loading various Apache modules are located in the /etc/httpd/conf.modules.d directory.
  • Apache vhost files must end with .conf and be stored in /etc/httpd/conf.d directory. You can have as many vhosts as you need. Creating a separate configuration file (vhost) for each domain makes the server easier to maintain.
    • It is a good practice to follow a standard naming convention. For example, if the domain name is mydomain.com then the configuration file should be named mydomain.com.conf
  • Apache log files (access_log and error_log) are located in the /var/log/httpd/ directory. It is recommended to have a different access and error log files for each vhost.
  • You can set your domain document root directory to any location you want. The most common locations for webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

Im folgenden, wird der Apache Webserver erst einmal grundlegend konfiguriert. Dazu, wird die httpd.conf editiert und folgende Änderungen durchgeführt.

# vim /etc/httpd/conf/httpd.conf

# Zeile 86: setzen der Server-Admin Email Adresse
ServerAdmin root@blackgate.org

# Zeile 95: festlegen des Server-Namen
ServerName www.blackgate.org

# Zeile 151: 'none' auf 'All' wechseln
AllowOverride All

#Folgendes wird dann noch am Schluss der Konfiguration eingetragen:

ServerTokens Prod
KeepAlive On

Nun kann der Webserver auch bereits schon gestartet werden:

# systemctl start httpd 
# systemctl enable httpd

Falls nun auch Firewalld aktiv ist, müssen noch die Ports für den Webserver freigeschalten werden. Dies wird folgendermassen gemacht:

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

# firewall-cmd --reload 

Zum testen, des Apache Webservers, kann nun ganz einfach und schnell eine kleine htlm-Datei wie folgt erstellt werden:

# vim /var/www/html/index.html

<html>

    <body>
        <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
        Test Page
        </div>
    </body>
</html>

At this point, you should be able to access Apache with a web browser on port 80.


FIXME

<WRAP center box 100%>

# curl -sSL https://www.blackgate.org/deployment/base_configuration_blackGATE.sh | bash cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo
# yum -y install https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# yum update
# yum install httpd php72w-fpm php72w-cli php72w-common php72w-gd php72w-intl php72w-mbstring php72w-mysql php72w-pecl-geoip php72w-pecl-imagick php72w-process php72w-xml

# mkdir /var/lib/php/session
# chown -R apache:apache /var/lib/php

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload
# vim /etc/php-fpm.d/www.conf
# vim /etc/httpd/conf.d/php.conf
# systemctl start httpd php-fpm
# systemctl enable httpd php-fp
# vim /var/www/html/info.php

  • redhat/web-server-redhat/apache/apache24-on-redhat.1583414192.txt.gz
  • Last modified: 2020/03/05 14:16
  • by michael