What is the best and fastest way to replicate apache virtual hosts to a new server?
When I need to change server I recreate all domains one by one with a procedure similar to this one:
sudo mkdir -p /var/www/html/sito.com
sudo chown -R $USER:$USER /var/www/html/sito.com
sudo chmod -R 755 /var/www/html/sito.com
sudo nano /etc/apache2/sites-available/sito.com.conf
------
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName sito.com
ServerAlias www.sito.com
DocumentRoot /var/www/html/sito.com
<Directory /var/www/html/sito.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# New directive needed in Apache 2.4.3:
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
-------
sudo a2ensite sito.com.conf
sudo systemctl reload apache2
and with 50, 100 domains this procedure is slow and tedious ...
Is there a fast and secure way to replicate the virtual hosts of the old server to a new server? Can there be problems with permissions and file owners?
I have ssh access and server root, ubuntu 20.04 server, apache, php8.1