Procedure:
- First you need to install httpd using yum
# yum -y install httpd
- After installation you need to start and enable service
# systemctl enable httpd.service
# systemctl start httpd.service
- Configure firewall to allow httpd traffic using below command
# firewall-cmd –zone=public –permanent –add-service=http
# firewall-cmd –zone=public –permanent –add-service=https
# firewall-cmd –reload
- Test your installation by browse default page in browser
http://SERVER_DOMAIN_NAME_OR_IP
Configure Name Based Virtual Host:
- If you have more than one domain need to host on same server then you need to configure Name based virtual host.
Procedure:
- First create vhost.conf file under /etc/httpd/conf.d/ to store multiple vhost configuration
# vi /etc/httpd/conf.d/vhost.conf
Add the following example virtual host directive template for website testdomain.com, make sure to change the necessary values for your own domain
NameVirtualHost *:80
ServerAdmin master@testdomain.com
ServerName testdomain.com
ServerAlias http://www.testdomain.com
DocumentRoot /var/www/html/testdomain.com/
ErrorLog /var/log/httpd/testdomain.com/error.log
CustomLog /var/log/httpd/testdomain.com/access.log
######## Additional Domain ################
ServerAdmin master@testdomain2.com
ServerName testdomain2.com
ServerAlias http://www.testdomain2.com
DocumentRoot /var/www/html/testdomain2.com/
ErrorLog /var/log/httpd/testdomain2.com/error.log
CustomLog /var/log/httpd/testdomain2.com/access.log
- Save file after make changes
- You can add more virtual host as you require.
- Make sure to create error log and custom log folder as defined in virtual host file.
- Restart httpd service after chagnes
# systemctl restart httpd.service
- Now you can visit to testdomain.com
Setup Apache Password Protected Directory with htpasswd
- By default Apache does not allow the use of .htaccess files in CentOS 7. You will need to set up Apache to allow .htaccess based authentication. You can do this by editing the Apache config file
# vi /etc/httpd/conf/httpd.conf
- Create a password file with htpasswd
# htpasswd -c /etc/httpd/.htpasswd user1
- Now, you need to allow the apache user to read the .htpasswd file.
- Save file and restart service.
- Test it by browse URL in browser. You will prompt for username and password













