Answer the question
In order to leave comments, you need to log in
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:
Answer the question
In order to leave comments, you need to log in
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>
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question