Apache2

This state automates installation of Apache2 and PHP7.0, creating new local VirtualHost, creating homepages for current and future users (/skel) and enabling PHP.

init.sls


# Made By Matias Richterich www.richterich.me
apache2:
 pkg.installed:
   - pkgs:
     - apache2
     - libapache2-mod-php7.0

/var/www/html/index.html:
 file.managed:
   - source: salt://apache/index.html

/etc/apache2/mods-enabled/userdir.conf:
 file.symlink:
   - target: ../mods-available/userdir.conf

/etc/apache2/mods-enabled/userdir.load:
 file.symlink:
   - target: ../mods-available/userdir.load

/etc/apache2/mods-available/php7.0.conf:
 file.managed:
   - source: salt://apache/phpconfig

/etc/apache2/sites-available/matias.example.com.conf:
 file.managed:
   - source: salt://apache/matias.example.com.conf
   - target: ../sites-available/matias.example.com.conf
   - target: ../sites-available

/etc/hosts:
 file.managed:
   - source: salt://apache/hosts

/etc/skel/public_html:
 file.recurse:
    - name: /etc/skel/public_html
    - source: salt://apache/public_html

apache2service:
 service.running:
   - name: apache2
   - watch:
     - file: /etc/apache2/mods-enabled/userdir.conf
     - file: /etc/apache2/mods-enabled/userdir.load
     - file: /etc/apache2/mods-available/php7.0.conf
     - file: /etc/apache2/sites-available/matias.example.com.conf

matias.example.com.conf


<VirtualHost *:80>
        DocumentRoot /home/xubuntu/public_html/

        <Directory /home/xubuntu/public_html/>
        Require all granted
        </Directory>
</VirtualHost>

hosts


127.0.0.1 localhost
127.0.1.1 xubuntu
127.0.0.1 matias.example.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

index.html


Hello World

phpconfig


<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>

Folder named ~/public_html

In public_html folder index.html file which contains just a “Hello world”