Create A Subdomain Linux Apache2 Web Server Script

View previous topic View next topic Go down

Create A Subdomain Linux Apache2 Web Server Script

Post by jamied_uk on 29th May 2017, 19:44





Code:
#!/bin/bash
#
# sudo chmod +x *.sh
#
# Example Usage:  ./New.sh
#
# jnet.forumn.biz/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
avatar
jamied_uk
Admin

Posts : 2151
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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