5 minutes to learn CentOS 8 mounted on Apache

Apache HTTP Server is the world's most widely used Web server. It is a free, open source, cross-platform HTTP server with powerful features, and can be extended with a variety of modules.

In all available Web servers, Apache Web Server may be one of the most popular server. Developed by the Apache Foundation's Apache is very popular, it can run 70 percent of all Web servers online.

This is every system administrator should know reliable and secure Web server. Apache is part of the LAMP stack, on behalf of Linux, Apache, MariaDB and PHP, and is commonly used in many companies hosting internal and external Web sites.

5 minutes to learn CentOS 8 mounted on Apache 

Requirement

Make sure your firewall is running correctly on 8 instances CentOS. Run the command as root or a user with sudo privileges.

11月 18 00:08:11 localhost.localdomain systemd[1]: Starting firewalld - dyna...
11月 18 00:08:12 localhost.localdomain systemd[1]: Started firewalld - dynam...
Hint: Some lines were ellipsized, use -l to show in full.

How to install Apache on CentOS 8 

Apache is mounted on CentOS 8

Apache is available in the default CentOS repositories, and installation is very simple. In order to install Apache Web Server, first by running the following command to update the local package

Based on RHEL releases, Apache software packages and services are called httpd. To install Apache, run the following command:

After the update is complete, you can install the Apache.

5 minutes to learn CentOS 8 mounted on Apache

Start Apache Web server

To start your Apache Web server, run the following command

Be sure to enable your httpd service so that it starts at system startup.

5 minutes to learn CentOS 8 mounted on Apache

Finally, by running a simple command status, make sure your Apache Web server is running.

5 minutes to learn CentOS 8 mounted on Apache

You can also check the Web server version, to make sure that is properly installed.

5 minutes to learn CentOS 8 mounted on Apache

Test your Apache Web server

To test whether Apache Web server is running, you first need to find your current IP address.

To obtain your IP address, run the following command

5 minutes to learn CentOS 8 mounted on Apache

By default, Apache will run on the server on port 80.

To check whether Apache is running properly, you can run a simple curl command, you can use a Web browser to be checked.

$ curl <ip_address>:80

If you browse to the correct URL discussed earlier, this is the default page.

This is just a standard presentation pages, there are some basic instructions above. If you are unfamiliar with Web server management, you can read a paragraph provided on this page.

Configure your firewall for Apache CentOS 8

For the external host can use the Web server, you will need to open specific ports on the firewall.

By default, CentOS use firewalld, it is on the host as a firewall daemon running, and provide basic security.

In order to receive HTTP and HTTPS connections, you'll ports 80 and 443 open on the server.

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

By running the following command to ensure that the service is properly licensed

$ sudo firewall-cmd --list-all | grep services

services : cockpit dhcpv6-client http https ssh

Congratulations!

You have successfully installed the CentOS 8 Apache.

Your server is now accepting incoming HTTP requests to the Web server.

Management Apache Web server on CentOS 8

In order to manage your Apache Web server, you have several options.

In order following command to restart Apache on CentOS 8, enter

sudo systemctl restart httpd

To stop the Web server, run the following command

$ sudo systemctl stop httpd

If you want to restart, you can run

$ sudo systemctl start httpd

If you made some changes to the Apache configuration, you can reload the server, without having to completely restart the server.

If you modify a Web site, it will restart other unmodified sites, which is obviously something we want to avoid.

$ sudo systemctl reload httpd

If you want your Web server is started at boot time (if you update the server and forget to restart the Web server, we recommend that you do), you must run

$ sudo systemctl enable httpd

On the other hand, if you want to stop the Web server is started at system startup, run

$ sudo systemctl disable httpd

Create a virtual host for the Apache Web server

Creating virtual hosts on Apache is very useful.

You can use a different set of custom rules to define multiple sites, rather than on a Web server storage site. Each site can have its own set of policy rules, their own SSL keys and redirection.

It makes it easier to manage the site, and the site separated from each other.

To create a virtual host for Apache on CentOS 8, we will be "linuxmi.com" website called, for example.

Create a domain folder

By default, a file stored on the host "/ var / www / html" in.

/ var / www
├── cgi-bin
├── html

This path is also known as "DocumentRoot" (document root), which is used as the default entry point on the server site.

In order to store multiple websites, you need to create multiple folders in "/ var / www /" and modify httpd configuration file to point to these directories.

In this example, let's create the following directory structure.

[root@localhost html]# tree -Ld 2 /var/www

/ var / www
├── cgi-bin
├── html
└── linuxmi.com
    ├── html
    └── log

Create a special folder for your new site.

[root@localhost html]# mkdir -p /var/www/linuxmi.com/html

Be sure to create a file to store the site's log files.

[root@localhost html]# mkdir -p /var/www/linuxmi.com/log

5 minutes to learn CentOS 8 mounted on Apache

Create your first HTML page

Now your folder is ready, you can create to be displayed to the user on an HTML page.

Create a file called "index.html" new HTML file and paste the following into it.

$ Cd /var/www/linuxmi.com/html
$ sudo we index.html

<!doctype html>

<html lang="zh-cn">
<head>
  <meta charset="utf-8">

  <title>LinuxMi.com</title>
  <meta name="description" content="linuxmi.com Homepage">
  <meta name="author" content="devconnected">
</head>

Save the file and exit the editor.

Now your website is ready, we can publish your website by creating virtual host file.

Create a virtual host file on CentOS 8

As mentioned above, in order to publish your site, we will create a virtual host file.

Similar NGINX, we will create two directories:

  • sites-available: a complete list is available on our Web site's server. By default, these sites do not have to be enabled, which is the purpose of the second folder.
  • sites-enabled: The container contains a list of sites accessible to the user. We will create a symbolic link in this directory, in order to activate and deactivate the site as needed.

First, create two directories on the host.

$ sudo mkdir -p /etc/httpd/sites-enabled /etc/httpd/sites-available

We have now created a folder and then edit the default Apache configuration and locate the following line.

$ South you /etc/httpd/conf/httpd.conf

# Load config files in the "/etc/httpd/conf.d" directory if any
IncludeOptional conf.d/*.conf

Replace this line with the following line.

IncludeOptional sites-enabled/*.conf

Now, your Apache Web server configuration has been updated to create a virtual host file for "linuxmi.com" website.

$ South you /etc/httpd/sites-available/linuxmi.com.conf

Paste in which the following configuration.

<VirtualHost *:80>
    ServerName linuxmi.com
    ServerAlias www.linuxmi.com
    DocumentRoot /var/www/linuxmi.com/html
    ErrorLog /var/www/linuxmi.com/log/error.log
    CustomLog /var/www/linuxmi.com/log/requests.log combined
</VirtualHost>

Save the file, and make sure that is configured properly by running the following command.

$ sudo apachectl configtest
Syntax OK

Now, restart Apache Web server can not access your site directly, it must be located in sites-enabled folder.

To link it to a directory-enabled site, use this command to create a symbolic link.

$ sudo ln -s /etc/httpd/sites-available/linuxmi.com.conf /etc/httpd/sites-enabled/linuxmi.com.conf

Update your firewall rules SELinux

By default, SELinux is configured for use with the default Apache configuration folder.

When you create a custom item, you need to enable them in SELinux.

To start the Apache Web server correctly, you need to modify the policy to include Apache custom log directory.

To enable custom directory, run the following command

$ Sudo setsebool httpd_unified -P 1

Restart your Apache server

Now, everything is set up correctly, it is time to restart the server to see changed.

$ sudo systemctl restart httpd

Go to your specified file in the virtual host URL, you should see your website is running. (See top screenshot article)

to sum up

In this tutorial, you learned how to install Apache on CentOS 8.

You also learned how to set up virtual hosts to store many different sites on a single Apache Web server.

Guess you like

Origin www.linuxidc.com/Linux/2019-11/161439.htm