Zack McCauley - WardsParadox

Hi, I’m a macadmin for a school district in Montana. Never stop learning.

Setting up MunkiReport-PHP on Ubuntu 16 with Nginx

2018-02-14

This post is still really rough, but should be fully functional.

Follow this guide to get PHP running: Install PHP 7.1 with Nginx on Ubuntu 16.04 Follow this guide to get MySQL running: How To Install MySQL on Ubuntu 16.04

For MRPHP to run, you will need to install the following:

apt-get install php7.1-common php7.1-opcache php7.1-json php7.1-mcrypt php7.1-zip php7.1-xml php7.1-soap php7.1-readline php7.1-cli php7.1-fpm php7.1-mbstring php7.1-mysql php7.1-cgi

Make sure git is also installed.

Create a new group that you can add www-data to, as well as your service accounts.

cd /media/
git clone https://github.com/munkireport/munkireport-php munkireport
cd ./munkireport
# Install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Run composer tools
php composer.phar install --no-dev --no-suggest --optimize-autoloader
chown -R $USER:groupthatcontainsuserandwww-data ../munkireport
chmod -R 755 ../munkireport

Modify your Nginx config for the server

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /var/www/html;

  # Add index.php to the list if you are using PHP
  index index.php index.html index.htm index.nginx-debian.html;

  server_name fqdn.ofyourserver.com;

  location /munkireport {
    try_files $uri $uri/ =404;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    include snippets/fastcgi-php.conf;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

  location ~ /\.ht {
    deny all;
  }
}

Create a symlink from /media/munkireport/public to /var/www/html/munkireport

ln -s /media/munkireport/public /var/www/html/munkireport

Modify your munkireport config.php

$conf['connection'] = [
 'driver'    => 'mysql',
 'host'      => '127.0.0.1',
 'port'      => 3306,
 'database'  => 'dbname',
 'username'  => 'username',
 'password'  => 'password',
 'options'   => [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']
];
$conf['subdirectory'] = substr(
            $_SERVER['PHP_SELF'],
            0,
            strpos($_SERVER['PHP_SELF'], basename(FC))
          );

Restart your server or your services.