Creating a salt state which enables Apaches users’ homepages. At first, installing everything manually on master: sudo salt ‘*’ pkg.install apache2
After that, enabling the userdir module: sudo a2enmod userdir
Then I created a directory named public_html, changed permissions (chmod 777 public_html) and created a file index.html. Then I could access the site via webrowser.
Let’s try to automate enabling user homepages on slaves by creating a state. I used
http://terokarvinen.com/2018/apache-user-homepages-automatically-salt-package-file-service-example as an example.
First error occured when I tried applying the state.
After fixing the error above, I applied the state again and this time it seemed to work.
After creating “default-index.html” file under the /srv/salt/apache/ directory, and applying the state again, apaches homepage was replaced by file I had just created.
Next step was to enable php to function on users’ home directories as well. I installed php and made some modifications on apaches conf files. I did this manually on salt master, to make sure everything works before making a state. First I had to install php: sudo apt install php libapache2-mod-php after that, I made slight modifications to php7.2.conf file. I found a tutorial on ubuntus site how to enable php on user dir which helped me to get this working: https://wiki.ubuntu.com/UserDirectoryPHP
And after restarting apache daemon, php worked on my home directory.
Then I wanted to make above steps to happen automatically. So I made a state.
Problems I encountered was few syntax errors when writing the state and wrong file name in source file. After fixing those errors, I created info.php file on slaves to test if it was working.
In this task, I created a state that would set up name-based virtual host on apache. I haven’t done virtual hosts on apache before, so I configured that manually first. I found a handy tutorial for doing that:
So basically what I did was create directories for both of virtualhosts, make configuration files for them and tell apache to use them.
I couldn’t get example homepages work for new users. I was able to make a state which would create a index.html file for new users, but it didn’t work as I wanted.