Install and configure Apache under Linux

lab environment:

  • Linux 5.19.13-arch1-1
  • konsole 22.08.2
  • apache 2.4.54-2

I. Overview

Apache HTTP Server (Apache for short) is an open source Web server of the Apache Software Foundation and the world's number one Web server software. It can run on almost all widely used computer platforms and is one of the most popular Web server-side software due to its cross-platform and security being widely used. It is fast, reliable and extensible with a simple API to compile interpreters like Perl/Python into the server.

Apache HTTP server is a modular server, common modules can be viewed Introduction to apache Common Modules - Lone Sword - Blog Park

LAMP refers to a combination of software used on many web servers: Linux, Apache, MySQL/MariaDB and PHP. This article describes how to install and configure the Apache web server.

2. Installation and environment configuration

1. Installation

Regarding version selection: The time is now 2022, and Apache mainstream Stable Release s are 1.3, 2.0, 2.2, and 2.4. The latest Stable Release is now 2.4.54. The latest stable version is recommended, but 2.2 can be used as appropriate

Install using package manager Apache
# If you can use the package manager, don't install it manually. Using the package manager can automatically handle dependencies, and you don't need to handle it yourself.
# If you really want to install manually, check out the link below
# Use the package manager to query if apache exists in aur
yay -q apache      # Arch
yum search apache  # CentOS
apt search apache  # Debian / Ubuntu
# If it exists, install it, otherwise go to the official website to download the package and install it manually
yay -S apache      # Arch
yum install apache # CentOS
apt install apache # Debian / Ubuntu

2. Basic environment configuration

1. Confirm that the software is installed correctly
[guyan@DrangonBoat conf]$ httpd -v
Server version: Apache/2.4.54 (Unix)
Server built:   Sep 25 2022 19:50:57

2. service start/stop/reboot
# apache has been renamed to httpd since version 2 and above
# init was replaced by systemd, all service control commands changed from service to systemctl
systemctl start/stop/restart httpd

3. service on/Off Auto-start
systemctl enable/disable httpd

4. View running status
systemctl status httpd

5. Verify use
- Open the browser and enter the URL localhost:80
- If the page can be opened normally, it means apache can be used normally

centos7 systemctl replaces service and chkconfig to achieve system management, all the control commands written in some tutorials use service instead of systemctl, but it is recommended to learn to use systemctl

Introduction to common configuration files for Apache services:

file name effect
/etc/httpd service catalog
/etc/httpd/conf configuration file
/etc/httpd/conf/httpd.conf main configuration file
/etc/httpd/modules Stores module files (binary files), which are automatically loaded when the service starts
/var/www/html Website page data directory
/var/log/httpd log file directory


# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:> for detailed information.
# In particular, see 
# <URL:>
# for a discussion of each configuration directive.

# Where to save server configuration, error, and log files
# Please do not add slashes at the end of the path
ServerRoot "/etc/httpd"

# The port on which the Apache server listens, you can bind Apache to a specific IP address or port
# Listen
Listen 80

# To repeat, Apache is a modular server and can load modules on demand
# There are many similar statements in the configuration file, indicating loaded modules
LoadModule auth_basic_module modules/

<IfModule dir_module>
    DirectoryIndex index.html

# The following are the default user names and user groups of Apache
# If you want to switch the running identity, you need to initially run as ROOT
User http
Group http

# Error documentation, or some generated pages will be emailed

# Web page five evils and requests will be stored here
# However, in actual use, a new directory is generally created to store web page files, and the pointing location here will also change.
DocumentRoot "/srv/http"

# Error message storage location
ErrorLog "/var/log/httpd/error_log"

3. Use


refer to:

Tags: server

Posted by X74SY on Fri, 04 Nov 2022 02:52:58 +0300