Install and Configure Apache Server
A. Install and Verify Apache Server
- Install the Web Serverpackage group:
- Edit the /etc/hosts file and the ip address and fully qualified domain name of the server:
- Optionally, Set the ServerName directive in /etc/httpd/conf/httpd.conf file. Activate at boot time and start the service:
- Add the HTTP service to the firewall configuration and reload it:
If you plan to use the HTTPS protocol, the command should be # firewall-cmd –permanent –add-service=https
- Check which ports this deamon is listening on:
Here it shows that our web server daemon is listening on port 80 and 443. A further check you can do is this:
# fuser -v -n tcp 80 # fuser -v -n tcp 443- Confirm that our client can connect to these ports:
- Test the Welcome Page. Open the browser and visit http://server.example.com. You will get the welcome page, even if you create an html page in /var/www/html. This is due to IncludeOptional conf.d/*.confstatement at the end of the /etc/httpd/conf/httpd.conf file that instructs Apache to load the files finishing by *.conf located in the /etc/httpd/conf.d To display the content of the /var/www/html directory, you need to go to the /etc/httpd/conf.d directory and check the welcome.conf file.
- Create /etc/httpd/conf.d/mywebserver.conf file:
- Install the httpd-manual package.
B. Configure a Virtual Host.
Let’s assume your website is called vhost1.example.com.
- Create /var/www/html/vhost1.example.com directory:
- Create an index.html file and assign the correct SELinux context:
- Create the /etc/httpd/conf.d/vhosts.conf file and paste the following lines:
- Optionaly, rename the /etc/httpd/conf.d/ssl.conf file, otherwise you get an additional non-working https virtual host displayed in the configuration.
- Check the validity of the configuration:
You can also type: # httpd -t
- Restart the httpd service:
You can also use # systemctl restart httpd. For minor configuration changes, it is also possible to restart the Apache daemon without losing the current connections: # apachectl graceful
- Check the virtual host(s) configuration:
- Check the configuration:
C. Configure Apache access restrictions on directories.
- Create a private directory, private, in /var/www/html
- Host-based private directories: To only allow the test.example.com host (add the name/IP address in the /etc/hosts file if necessary) to access a specific directory (here private), edit the /etc/httpd/conf/httpd.conf file and paste the following lines at the end:
- Check the configuration file:
- User-based private directories: To only allow me to access a specific directory (here private), edit the /etc/httpd/conf/httpd.conffile and paste the following lines at the end:
- Check the configuration file:
- Create the passwd file and store me‘s password:
The .htpasswd file can be used locally instead of the httpd.conf file.
- Whatever the option chosen, restart the httpd service:
- Check the httpd service:
or
# yum install -y elinks # elinks http://localhost/private