Hi,
Currently, I add a VirtualServer to Apache manually for each site I want to host.
Is there any way to add it programmatically? Means create a VirtualServer, Create a directory in /var/www/ and copy some files into it.
Is there any API to do so?
I’m running VirtualMin/Webmin but that is also a manual process. Anything to automate all this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
There isn’t any API, but it is certainly something you could script. Something like this would handle the basic use case: <br> <br><pre> <br>#!/bin/bash <br> <br>if [ ! -n “$1” ]; then <br> echo “No host set.” <br> exit <br>fi <br> <br>echo “Creating new VirtualHost /var/www/$1/” <br> <br>touch /etc/apache2/sites-available/$1 <br> <br>mkdir /var/www/$1 <br> <br>cat << EOF > /etc/apache2/sites-available/$1 <br><VirtualHost *:80> <br> ServerAdmin webmaster@localhost <br> ServerName $1 <br> <br> DocumentRoot /var/www/$1/ <br> <Directory /> <br> Options FollowSymLinks <br> AllowOverride None <br> </Directory> <br> <Directory /var/www/> <br> Options Indexes FollowSymLinks MultiViews <br> AllowOverride None <br> Order allow,deny <br> allow from all <br> </Directory> <br> <br> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <br> <Directory “/usr/lib/cgi-bin”> <br> AllowOverride None <br> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch <br> Order allow,deny <br> Allow from all <br> </Directory> <br> <br> ErrorLog ${APACHE_LOG_DIR}/error.log <br> LogLevel warn <br> CustomLog ${APACHE_LOG_DIR}/access.log combined <br></VirtualHost> <br>EOF <br> <br>a2ensite $1 <br>service apache2 reload <br></pre>
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.