The script creates the needed amount of website folders and config files for them, then it enables sites and restarts Apache. The script allows configuring several websites in Apache very fast. You must run it as root or be using sudo.
- Checks existence of root privileges and needed arguments, then the creating of sites occures.
In each iteration the script does: - Checks existence of a configuration in the directory /etc/apache2/sites-available/ (you can change this dir at the beginning of the script file) and if the current website directory is empty or not. If the directory of an iteration doesn't exist it will be created; If the directory is not empty or Apache config file exists, current website creation will be missed.
- Creates the site's direcotry using the name of the site. It the directory the script creates index.php with phpinfo() function. You can change the output for the index.php files at the beginning of the script.
- Adds relevant config into Apache.
The script creates apache configuration files like this:
<VirtualHost testsite1:80>
ServerName testsite1
DocumentRoot "/var/www/html/testsite1"
ErrorLog ${APACHE_LOG_DIR}/testsite1/error.log
CustomLog ${APACHE_LOG_DIR}/testsite1/access.log combined
<Directory "/var/www/html/testsite1">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# allow access to the directory
Require all granted
# ...other settings...
</Directory>
</VirtualHost>You can change this template in the script file as you wish.
- After generation of all configs, the script restarts Apache.
- Download the script from Github or clone it:
git clone https://github.com/igor-pgmt/siteadder.git- You can start use it from a folder but it would be useful to move it somewhere:
mv siteadder/siteadder.sh ~/myscripts/siteadder.shMake sure that You can execute the sript:
chmod +x ~/myscripts/siteadder.sh- Create an alias for the script. For example "wadd" :
echo 'alias wadd="~/myscripts/siteadder.sh"' >> ~/.bashrcOR create a symlink to your file:
sudo ln -s /home/user/myscripts/siteadder.sh /usr/bin/waddRequired arguments:
-a amount of websites to be created.
-p name prefix of websites to be created.
Not required arguments:
-d root directory for websites. By default will de used /var/www/html/
Examples:
./siteadder -a 3 -p testsite ↑This command will configure three sites:
/var/www/html/testsite1/
/var/www/html/testsite2/
/var/www/html/testsite3/
./siteadder -a 2 -p testsite -d myDir↑This command will create directory ./mydir and create two sites in current directory:
./myDir/testsite1
./myDir/testsite2