Apache Virtual Hosts on CentOS Rumi, August 24, 2019 Step One— Create a New Directory The first step in creating a virtual host is to a create a directory where we will keep the new website’s information. This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory. sudo mkdir -p /var/www/example.com/public_html You will need to designate an actual DNS approved domain, or an IP address, to test that a virtual host is working. In this tutorial we will use example.com as a placeholder for a correct domain name. However, should you want to use an unapproved domain name to test the process you will find information on how to make it work on your local computer in Step Six. Step Two—Grant Permissions We need to grant ownership of the directory to the user, instead of just keeping it on the root system. sudo chown -R apache:apache /var/www/example.com/public_html Additionally, it is important to make sure that everyone will be able to read our new files. sudo chmod 755 /var/www Now you are all done with permissions. Step Three— Create the Page We need to create a new file called index.html within our configurations directory. sudo vi /var/www/example.com/public_html/index.html We can add some text to the file so we will have something to look at when the IP redirects to the virtual host <html> <head> <title>www.example.com</title> </head> <body> <h1>Success: You Have Set Up a Virtual Host</h1> </body> </html> Save and Exit Step Four—Turn on Virtual Hosts The next step is to enter into the apache configuration file itself. sudo vi /etc/httpd/conf/httpd.conf There are a few lines to look for. Make sure that your text matches what you see below. #Listen 12.34.56.78:80 Listen 80 Scroll down to the very bottom of the document to the section called Virtual Hosts. NameVirtualHost *:80 # # NOTE: NameVirtualHost cannot be used without a port specifier # (e.g. :80) if mod_ssl is being used, due to the nature of the # SSL protocol. # # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot /var/www/example.com/public_html ServerName www.example.com ServerAlias example.com ErrorLog /var/www/example.com/error.log CustomLog /var/www/example.com/requests.log </VirtualHost> The most important lines to focus on are the lines that say NameVirtualHost, Virtual Host, Document Root, and Server Name. Let’s take these one at a time. ServerAlias is a new line in the config file that is not there by default. Adding it will allow you to list a few variants of the domain name, for example without the www in the front. The rest of the lines in this section are not required to set up a virtual host. However, it is still helpful to know what they do. Step Five—Restart Apache We’ve made a lot of the changes to the configuration. However, they will not take effect until Apache is restarted. First stop all apache processes: sudo apachectl -k stop Then start up apache once again. sudo /etc/init.d/httpd start You may see the following error: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName The message is just a warning, and you will be able to access your virtual host without any further issues. Related Administrations Configurations (Linux) ApacheApache2CentOS
Enable IPTables on Rocky Linux 8 September 2, 2023 Disabling firewalld You can’t really run the old iptables utilities alongside firewalld. They’re just not compatible. The best way to get around this is to disable firewalld entirely (no need to uninstall it unless you want to) , and reinstall the iptables utilities. Disabling firewalld can be done using these… Read More
Windows 7 theme for Ubuntu 9.10 March 29, 2010 An interesting article, as it looks it transforms the entire OS theme into Windows 7 like…. 🙂 http://ubuntu.sun.ac.za/index.php?title=W7_Theme Related Read More
Install Apache2, PHP 7.2 and MariaDB 10.5 on Debian 11 February 18, 2023 First, update all the packages of the system by below-mentioned command: sudo apt update After updating packages, now install the dependencies required by the below-mentioned command: sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https Enable SURY Repository The following step is to integrate the SURY repository into our system. SURY is… Read More