📜 ⬆️ ⬇️

Automating the FreeBSD8 Apache2 + Mysql5 Web Server Part 1

It so happened that I'm terribly lazy. Two years ago, when I bought myself a VDS and met FreeBSD 7.1 for the first time, I killed two weeks to configure everything I needed. Now I have 2 * Pentium III 1GHz / RAM 1GB / 2 * SCSI 17GB, it suits my tasks perfectly.

  1. Creating hosts
  2. Rotary of logs of Apache2
  3. Archive Apache2 logs and delete old logs.
  4. Creating a database and adding a new user with permissions to only one database, with the generation of a new password.


My favorite editor is vi. If someone doesn’t know how to work with him, wherever I’ve told vi to be replaced with my ee, mcedit, etc.
')
Script to create hosts.
The structure on my server is as follows, each user has a www folder in his home-directory, it looks like this.
/ home / user / www.
The script inside the www folder creates directories with the host name.

Example mk_host.sh domen.ru user
A folder domen.ru with directories will be created in the directory / home / user / www.



A host will also be created in the Apache2 directory. According to my scheme, a separate config is created for each virtual host.

We look at the script itself.

vi /root/bin/mk_host.sh
.

if [ $# -eq 2 ] ; then # , <br/>
<br/>
path = / usr / local / etc / apache2 / Includes # . <br/>
domen =$ 1 # <br/>
user =$ 2 # <br/>
pathhome = / home / $user / www # - <br/>
mkdir -p $pathhome / $ 1 / html<br/>
mkdir -p $pathhome / $ 1 / shadow<br/>
mkdir -p $pathhome / $ 1 / cgi-bin<br/>
mkdir -p $pathhome / $ 1 / logs<br/>
chown -R $user : $user $pathhome / $ 1 / # . <br/>
# <br/>
echo "<br/>
#Config for $domen <br/>
<VirtualHost *:80><br/>
DocumentRoot $pathhome / $domen /html/<br/>
ServerName $domen <br/>
ServerAlias www. $domen <br/>
ScriptAlias /cgi-bin/ $pathhome / $domen /cgi-bin/<br/>
CustomLog $pathhome / $domen /logs/web.log common<br/>
ErrorLog $pathhome / $domen /logs/error.log<br/>
</VirtualHost><br/>
#end of $domen "
>> $path / $domen .conf<br/>
else <br/>
# , . <br/>
echo "ERROR" <br/>
echo "$0 domen name_user" <br/>
exit 1 <br/>
fi

vi /root/bin/mk_host.sh
.

if [ $# -eq 2 ] ; then # , <br/>
<br/>
path = / usr / local / etc / apache2 / Includes # . <br/>
domen =$ 1 # <br/>
user =$ 2 # <br/>
pathhome = / home / $user / www # - <br/>
mkdir -p $pathhome / $ 1 / html<br/>
mkdir -p $pathhome / $ 1 / shadow<br/>
mkdir -p $pathhome / $ 1 / cgi-bin<br/>
mkdir -p $pathhome / $ 1 / logs<br/>
chown -R $user : $user $pathhome / $ 1 / # . <br/>
# <br/>
echo "<br/>
#Config for $domen <br/>
<VirtualHost *:80><br/>
DocumentRoot $pathhome / $domen /html/<br/>
ServerName $domen <br/>
ServerAlias www. $domen <br/>
ScriptAlias /cgi-bin/ $pathhome / $domen /cgi-bin/<br/>
CustomLog $pathhome / $domen /logs/web.log common<br/>
ErrorLog $pathhome / $domen /logs/error.log<br/>
</VirtualHost><br/>
#end of $domen "
>> $path / $domen .conf<br/>
else <br/>
# , . <br/>
echo "ERROR" <br/>
echo "$0 domen name_user" <br/>
exit 1 <br/>
fi

vi /root/bin/mk_host.sh
.

if [ $# -eq 2 ] ; then # , <br/>
<br/>
path = / usr / local / etc / apache2 / Includes # . <br/>
domen =$ 1 # <br/>
user =$ 2 # <br/>
pathhome = / home / $user / www # - <br/>
mkdir -p $pathhome / $ 1 / html<br/>
mkdir -p $pathhome / $ 1 / shadow<br/>
mkdir -p $pathhome / $ 1 / cgi-bin<br/>
mkdir -p $pathhome / $ 1 / logs<br/>
chown -R $user : $user $pathhome / $ 1 / # . <br/>
# <br/>
echo "<br/>
#Config for $domen <br/>
<VirtualHost *:80><br/>
DocumentRoot $pathhome / $domen /html/<br/>
ServerName $domen <br/>
ServerAlias www. $domen <br/>
ScriptAlias /cgi-bin/ $pathhome / $domen /cgi-bin/<br/>
CustomLog $pathhome / $domen /logs/web.log common<br/>
ErrorLog $pathhome / $domen /logs/error.log<br/>
</VirtualHost><br/>
#end of $domen "
>> $path / $domen .conf<br/>
else <br/>
# , . <br/>
echo "ERROR" <br/>
echo "$0 domen name_user" <br/>
exit 1 <br/>
fi


And lastly:
  1. The script must be run as root or at least you need to have access to the directory.
  2. The script is more convenient to put in your directory, for example, in my /root/bin/mk_host.sh directory and add the directory to .profile, then you will be able to run the script from anywhere without specifying a direct path to the script.
  3. The script has only checks for entering two parameters, unfortunately nothing else is checked, the script is made for yourself, in the hope that the script will be used by an experienced person.


Just in case the script is original.

And I also like when everything is in its place and laid out on the shelves, the description of the rest of the scripts will be in the next article.

Source: https://habr.com/ru/post/96933/


All Articles