PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Create A Subdomain Linux Apache2 Web Server Script

Go down

Create A Subdomain Linux Apache2 Web Server Script Empty Create A Subdomain Linux Apache2 Web Server Script

Post by jamied_uk 29th May 2017, 19:44





Code:
#!/bin/bash
#
# sudo chmod +x *.sh
#
# Example Usage:  ./New.sh
#
# jnet.forumotion.com/t1509-create-a-subdomain-linux-apache2-web-server-script#2235
#
#
echo "Enter New Virtual Host Name"
read name1
# Creating New Hosts
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/$name1.conf
sudo mkdir /var/www/$name1/
# Adding Example Index page.
sudo echo "<center>Virtual Host test Page " > /var/www/$name1/index.php
# now set permissions for this file
sudo chown -R $USER:www-data /var/www/$name1/
sudo chmod -R 755 /var/www/$name1
sudo chown -R $USER:www-data /var/www/$name1/index.php
sudo chmod -R 755 /var/www/$name1/index.php
# Or Use nano if doing it remotely!
sudo gedit /etc/apache2/sites-available/$name1.conf
sudo a2ensite $name1.conf
sudo service apache2 restart
echo "Now add entry to hosts file..."
sudo gedit /etc/hosts
echo "All Done Now Test New Site With browser"
firefox $name1

Example test.conf file


Code:
<VirtualHost *:80>
    ServerAdmin root@localhost
    ServerName test.com
    ServerAlias www.test.com
    DocumentRoot /var/www/VirtualHost1/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Example Hosts file:

Code:
192.168.0.4     test.com
jamied_uk
jamied_uk
Admin

Posts : 2965
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum