SE181693 - Lab 5 - Part 2
SE181693 - Lab 5 - Part 2
Introduction
The Apache HTTP server is the most widely-used web server in the world. It provides
many powerful features including dynamically loadable modules, robust media support,
and extensive integration with other popular software.
In this guide, you will install an Apache web server with virtual hosts on your CentOS 7
server.
Once the packages are updated, install the Apache package: sudo
After confirming the installation, yum will install Apache and all required dependencies.
If you haven’t already done so, you can do this by enabling firewalld’s http service with
the following command:
Next, reload the firewall to put these new rules into effect: sudo
firewall-cmd –reload
Step 2 — Checking your Web Server
Apache does not automatically start on CentOS once the installation completes. You
will need to start the Apache process manually: sudo systemctl start httpd
hostname -I
When you have your server’s IP address, enter it into your browser’s address bar:
http://your_server_ip
Apache will now start automatically when the server boots again.
Step 4 — Setting Up Virtual Hosts
Create the html directory for your_domain as follows, using the -p flag to create any
necessary parent directories:
Next, assign ownership of the html directory with the $USER environmental variable:
Make sure that your web root has the default permissions set: sudo
Next, create a sample index.html page using vi or your favorite editor: sudo
vi /var/www/your_domain/html/index.html
Press i to switch to INSERT mode and add the following sample HTML to the file:
Save and close the file by pressing ESC, typing :wq, and pressing ENTER.
Next, you will tell Apache to look for virtual hosts in the sites-enabled directory.
sudo vi /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf
Save and close the file when you are done adding that line.
sudo vi /etc/httpd/sites-available/your_domain.conf
Add in the following configuration block, and change the your_domain domain to your
domain name:
Save and close the file when you are finished.
Create a symbolic link for each virtual host in the sites-enabled directory: sudo
ln -s /etc/httpd/sites-available/your_domain.conf
/etc/httpd/sitesenabled/your_domain.conf
You can list the contexts once more to see the changes:
List the contents of the /var/www/your_domain/log directory to see if Apache created the
log files: ls -lZ /var/www/your_domain/log
You’ll see that Apache was able to create the error.log and requests.log files specified in
the virtual host configuration:
Now that you have your virtual host set up and SELinux permissions updated, Apache
will now serve your domain name. You can test this by navigating to http://your_domain,
where you should see something like this:
Note :