L
L
lfoma2015-08-22 00:01:48
Apache HTTP Server
lfoma, 2015-08-22 00:01:48

Automating installation of virtual hosts?

Good evening! For local development, I use xampp.
And not that I would be very tired of manually installing new sites, but I would like to find an automation script that could install the site:

  • Site directory
  • Register it in httpd-vhosts.conf
  • Register it in hosts

All this with or without settings + the ability to delete.
Of course, prescribing all this is not long and not difficult, but, you see, if this can be automated, then why not? Maybe there is another approach that I'm not aware of?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Chvalov, 2015-08-22
@Chvalov

I didn’t use xampp, I always install apach, php, mysql, phpmyadmin separately. Then I create the test.com/public_html/ folder
in /var/www/ and put my *.php scripts. Next, I create the sudo nano file /etc/apache2/sites-available /test.com.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName test.com
    ServerAlias www.test.com
    DocumentRoot /var/www/test.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then
sudo a2ensite test.com.conf
and restart apache sudo service apache2 restart
I think it's quite simple

V
Valery Ryaboshapko, 2015-08-22
@valerium

Have you tried writing a script? After all, since you use XAMPP for development, you know how to code :-) You can roll it both in PHP and (IMHO, more beautiful) in bash.
In the simplest case, it will look something like this. Runs with one parameter (domain name), implies that /etc/apache2/skeleton already contains the virtual host config skeleton.

#!/bin/bash

# создаём папку под данные
mkdir -p /var/www/$1
# копируем скелет конфига
cp /etc/apache2/sites-available/skeleton /etc/apache2/sites-available/$1
# заменяем в конфиге доменное имя
sed -i "s/test.com/$1/g" /etc/apache2/sites-available/$1
# включаем конфиг
a2ensite test.com
# прописываем домен в hosts
echo "\n127.0.0.1\t$1\n" >> /etc/hosts
# перезапускаем Apache
service apache2 restart

And, by the way, I will support my colleague Chvalov . If you use Linux, why do you need XMPP? In most modern distributions, LAMP can be installed in one command in 15 minutes, and even automatically updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question