Apache HTTP Server is the most used web server in the world. Apache offers many powerful features including dynamically downloadable modules, robust media support, and comprehensive integration with other popular software.
Before starting this guide, you must have a regular, non-root user with sudo privileges configured on your server.
We recommend that you test every tutorial or guide found on the internet on a virtual machine (vmware or virtualbox) before deploying to a production server, so you don’t mess up the OS when something goes wrong.
First Step – Install Apache
Apache is available in the default CentOS repository, which makes it possible to install it using traditional package management tools.
In CentOS and RHEL the package is called Apache and the service httpd. To install the package, run the following command:
sudo yum install httpd
After the installation is complete, activate and start the Apache service:
sudo systemctl enable httpd sudo systemctl start httpd
Set up a firewall on CentOS 7
If your server is protected by a firewall, you will need to open the port
HTTP And the
80 And the
443. Use the following command to open the required ports:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
Check that Apache is installed
Now that Apache is installed and running on our CentOS 7 server, we can check the status and version of the Apache service, using the command:
sudo 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 Thu 2018-04-26 07:13:07 UTC; 11s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 3049 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─3049 /usr/sbin/httpd -DFOREGROUND ├─3050 /usr/sbin/httpd -DFOREGROUND ├─3051 /usr/sbin/httpd -DFOREGROUND ├─3052 /usr/sbin/httpd -DFOREGROUND ├─3053 /usr/sbin/httpd -DFOREGROUND └─3054 /usr/sbin/httpd -DFOREGROUND
Then also look at the version installed with the command:
sudo httpd -v
Server version: Apache/2.4.6 (CentOS) Server built: Oct 19 2017 20:39:16
Finally, to check if everything is working properly, open your domain or server IP address in a browser of your choice, and you will see the default Apache CentOS 7 welcome page as shown below:
Manage the Apache process
Now that your web server is up and running, let’s cover some basic management commands.
To stop the web server, type
To start the web server when it stops, type:
To stop and then restart the service, type:
If you only make configuration changes, Apache can reload the application without disconnecting. To do this, use the command:
By default, Apache is configured to start automatically on server boot. If this isn’t what you want, disable this behavior by typing:
To re-enable the service to start on boot, type:
Apache will now start automatically when the server is restarted.
Basic Apache setup on CentOS
Here is the basic Apache setup on CentOS, if you run into problems, or want to change the configuration, this is where to look:
- All Apache configuration files are in the directory
- The main configuration file in Apache is
- The configuration files responsible for loading the various Apache modules are located in the directory
- For better maintenance, it is recommended to create a separate configuration file (vhost) for each domain.
- The Apache virtual host must end with the extension
.confIt is located in the directory
- It is highly recommended that you follow standard naming conventions, for example if the domain name for this site is
beritabebas.com, Then the domain configuration file is named
/etc/httpd/conf.d/beritabebas.com.confTo facilitate site management.
- Apache log files (
error.log) In the manual
/var/log/httpd. Recommended for use
errorDifferent records for each virtual host.
- You can set your domain document root directory to anywhere you want. The most popular sites for webroots include:
You have successfully installed Apache on your CentOS 7 server. You are now ready to start publishing your application and using Apache as your web or proxy server.