Skip to content

Instantly share code, notes, and snippets.

@jainxy

jainxy/apache-1.txt

Created May 6, 2020
Embed
What would you like to do?
Web Hosting related gists
$ sudo mkdir -p /var/www/test.com/public_html
$ sudo mkdir -p /var/www/example.com/public_html
$ sudo chown -R $USER:$USER /var/www/example.com/public_html
$ sudo chown -R $USER:$USER /var/www/test.com/public_html
$ sudo chmod -R 755 /var/www
Create the virtual hosts configuration files for our two sites
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.com.conf
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
open the first virtual hosts file on a nano editor to edit its content using the command below:
<VirtualHost *:80>
ServerAdmin admin@test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the two virtual hosts
$ sudo a2ensite test.com.conf
$ sudo a2ensite example.com.conf
Restart Apache for the changes to take effect
$ sudo service apache2 restart
Edit the local hosts file on your computer
$ sudo nano /etc/hosts
111.111.111.111 example.com
111.111.111.111 test.com
=====================
EDIT /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin hello@chandank.com
DocumentRoot /opt/htdocs/bestflare
ServerName bestflare.com
ErrorLog logs/bestflare.com-error_log
CustomLog logs/bestflare.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin hello@chandank.com
DocumentRoot /opt/htdocs/usefulread
ServerName usefulread.com
ErrorLog logs/usefulread.com-error_log
CustomLog logs/usefulread.com-access_log common
</VirtualHost>
Change the value for ServerAdmin, DocumentRoot, ServerName, ErrorLog, CustomLog based on your requirement.
Restart Apache HTTP and test both urls.
======================
add the following stanza to the bottom of its /etc/httpd/conf/httpd.conf configuration file
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/html
ServerName www.site1.org
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/html2
ServerName www.site2.org
</VirtualHost>
https://httpd.apache.org/docs/2.4/vhosts/
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 www.site1.org www.site2.org
systemctl restart httpd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment