I want to share a small experience that simplifies the administration of a web sever running a debian-like operating system. Immediately make a reservation, I'm not a guru in this area, just at some point I needed to raise vsftpd, nginx, PHP-FPM and PostgreSQL. It's no secret that when adding virtual hosts, setting up PHP-FPM pools and creating databases, you have to perform the same actions. Deleting virtual hosts with everything connected with them, as well as creating backup copies, is also very monotonous. Therefore, it would be nice to get scripts that automate all these things.
To be honest, at the time of writing the scripts, I was not bothering to search for existing solutions, it was just interesting for me to do everything myself. And, although
the Bitbucket repository came along with the first version of the scripts, thoughts of their possible usefulness for someone else came to mind a little later.
And yet, for a start, it is worth considering the existing solutions. One of them is described in the
article . It provides an example script for FreeBSD that creates a virtual host. Another solution is provided in the
article , and a similar script is considered there, but for Debian.
After reading the materials of the articles, we can conclude that none of them presented the complete solution of the problem. It also grieves the lack of a flexible system of parameters, that is, you cannot influence the behavior of scripts without changing their code. And, in the meantime, we may need to create a virtual host without PHP support or, for example, not to create a database. In addition, all configs are located right inside the scripts, which is also not very good.
')
To business
So, there are several scripts:
- siteadd.sh - to create a virtual host;
- passwd.sh - to change the password;
- backup.sh - to create a backup;
- sitedel.sh - to remove a virtual host.
How to work with them is described on the
wiki , but the general idea is that, for example, when
creating a virtual host test.ru, the script asks which password to assign to the user test.ru, creates this user in the system, then creates the / var / www folder /data/test.ru/public_html with the stub file index.html and gives all the necessary rights to the user test.ru.
Next, the script creates a nginx configuration file with a template with the necessary parameters and similarly configures the PHP-FPM pool. In PostgreSQL, it creates a test_ru database and a test_ru user, which it assigns as its owner.
If the
--no-php parameter is specified when invoking the script, the PHP-FPM pool is not configured, and the template without PHP support is used when creating the nginx configuration file. With the
--no-pgsql option, PostgreSQL does not create a database and user.
When
changing the password for the virtual host test.ru, the script asks for a new password and assigns it both to the test.ru user in the system and to the test_ru user in PostgreSQL.
When
creating a backup for the virtual host test.ru, the script creates:
- archive files /var/www/backup/test.ru/YY-mm-dd_HH:ii:ss.tar.gz;
- base dump /var/www/backup/test.ru/YY-mm-dd_HH:ii:ss.sql.
When you
delete the virtual host test.ru, the script deletes the database and the user test_ru from PostgreSQL, deletes the folder /var/www/data/test.ru and the user test.ru from the system. Backups are not deleted.
It should be noted that there are two versions of scripts:
- the normal version, which lies in the default branch;
- version with support for the transfer of parameters in JSON format, which lies in the json branch.
The regular version does not require any special tools. A JSON-enabled version requires a JSON processor in the system called jq, which is available through standard Debian repositories. And although someone will not like this condition, this version is now more flexible, but not for long.
What's next?
From time to time I return to my server to play. As a result, scripts are being developed, and this is what I would like to modify first:
- increase the number of parameters of the regular version, which will make it more flexible, including adding a parameter for deploying a backup;
- add configuration templates, because there are some settings missing;
- write a script for cleaning outdated backups;
- provide support for apache and mysql.
That's all for now. I remind you that the scripts can be downloaded
here . I will be glad comments and suggestions. Thanks for attention!