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

# sudo chmod +x *.sh
# Example Usage:  ./
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

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

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

Example Hosts file:


Posts : 2305
Join date : 2010-05-09
Age : 35
Location : 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