I wrote a little thing
Long story short, I've started making small useful things... Let's go on
So, I decided it would be a good idea to write a small bash script that would save me a lot of time. It was then that I thought about setting up VirtualHosts on a linux server.
I have a procedure I go through every time I do it. I set up the .conf file, I then enable the site, restart apache, set up the root dir. Automation to some degree was the idea
The idea I came up with was to create a bash script that I can run on the command line on my server to do this for me. This is how vhost_bash came to be.
You can check it out on Github.
I'll outline the README.md here and go through how to use it.
vhost_bash
The vhost.sh file is a script that will, given the correct arguments, create Vhost conf files and then enable these or delete and disable the site.
Note this is currently only works on Linux servers using Apache, Virtual Hosts and sites-enabled.
Installation
Download the script file. Place the file on your server.
Optional - Mod the email variable in the vhost file to an email that you deem fit.
Make the file executable
$ chmod +x /path/to/vhost.sh
You can then run the script from the where you place it.
Optional - Making the file globally accessible.
$ sudo cp /path/to/vhost.sh /usr/local/bin/vhost
If you go through with this step, you will be able to use the script globally
Usage
Running the script from where it lives
$ ./vhost.sh create|delete|help domain_name web_path
Running this script globally.
$ vhost create|delete|help domain_name web_path
Examples
These examples will assume global setup
Create
$ sudo vhost create testwebsite.com testwebsitepath
This will create a VirtualHost file in sites-available
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/testwebsitepath/public_html
ServerName testwebsite.com
ServerAlias www.testwebsite.com
LogLevel error
ErrorLog ${APACHE_LOG_DIR}/testwebsite.com-error.log
CustomLog ${APACHE_LOG_DIR}/testwebsite.com-access.log combined
</VirtualHost>
and then enable it.
If the site already exists, then it will return a message to say this is the case and you won't get a duplicate.
Delete
$ sudo vhost delete testwebsite.com
This will disable the current vhost file in sites available, restart apache and then remove the conf file.
If it doesn't find a site, then it will return a nice message to say it has not found anything.
Help
$ vhost help
This will explain the actions that you can use.
Contribution
If you want to contribute, then feel free to. I'm not sure how much else is needed, but feel free.