Install Mautic in a Sub Folder on NGINX

Written by
on August 11, 2017

For those of you who don’t know what Mautic is, it’s a powerhouse of an application for list building, marketing automation, sales funnels… and MORE!

And the incredible part? It’s FREE to use on your own server and site — you just need to know enough about Linux administration to set it up.

You can setup Mautic at a sub domain, but I wanted to install it within a sub folder. This would mean any landing pages created were at outergain.com/landing-page vs mautic.outergain.com/landing-page.¬†However, installing in a sub folder on nginx wasn’t something many people were talking about when I first began with Mautic. So after trial and error, throwing computers out the window and destroying my office with a light saber, it began to work.

Here are the installation steps:

Opening Information:

  1. These steps assume ‘example.com’ equals your actual website.
  2. ‘Data’ is the sub folder you’re installing Mautic into — The name is completely up to you.
  3. Your nginx sites are located in /var/www/
  4. Your PHP version is 7

Also note: We use Ubuntu and/or Debian. If you’re on a different distro, you may have to adjust a few commands.

1) Create the subfolder you want to run mautic out of.

Example: http://yoursitecom/pages/

2) Get the latest Mautic files.

From a command line, navigate to your folder. Example: cd /var/www/yoursite.com/pages and get the latest files:

wget –level=0 https://www.mautic.org/download/latest

If you need an older version, type similar to:

wget –level=0 https://s3.amazonaws.com/mautic/releases/2.8.2.zip

4) Unzip the installation files.

Simply type:

unzip latest

5) Remove the zipped file.

rm latest

(add the .zip extension for a version, example: rm 2.8.2.zip)

6) Change ownership on the installation folder(s):

chown -R www-data:www-data /var/www/yoursite.com/pages

create a folder called ‘logs’ in pages/app (if it doesn’t exist). Then…

chown -R www-data:www-data /var/www/yoursite.com/pages/app/logs

Next: Server Config (based on Debian LEMP):

1) Edit php.ini file.

Add this line to the bottom of your your php.ini file:

always_populate_raw_post_data = -1

2) Install PHP packages

You may already have these items installed.

apt-get install php7-imap
apt-get install php7-intl
apt-get install php7-mcrypt

3) Enable mcrypt:

ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
php5enmod mcrypt

4) Edit your site’s server block file.

The normal path is: /etc/nginx/sites-available/yoursite.com

location /pages {
try_files $uri $uri/ /pages/?q=$uri&$args;
}

Also, adding these restrictions will help nginx work for you and secure your installation:

# Deny everything else in /app folder except Assets folder in bundles
location ~ /content/app/bundles/.*/Assets/ {
allow all;
}
location ~ /content/app/ { deny all; }# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /content/(addons|plugins)/.*/Assets/ {
allow all;
}
#location ~ /content/(addons|plugins)/ { deny all; }# Deny all php files in themes folder
location ~* /content/themes/(.*)\.php {
deny all;
}# Deny yml, twig, markdown, init file access
location ~* /content/(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
deny all;
access_log off;
log_not_found off;
}

# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc…
location ~ /content/\. {
deny all;
access_log off;
log_not_found off;
}

# Deny all grunt, composer files
location ~* /content(Gruntfile|package|composer)\.(js|json)$ {
deny all;
access_log off;
log_not_found off;
}

5) Restart nginx and php7-fpm

service nginx restart
service php7-fpm restart

6) Create mysql database for Mautic

create database yourmauticdb;
grant all on yourmauticdb.* to ‘yourmauticdbuser’ identified by ‘thepasswordyouwant’;
flush privileges;

Finally, the installation!

7) Go to http://yoursite.com/pages/installer

At this step, the installer will let you know if anything on your server isn’t ready for Mautic. This includes missing packages, outdated packages, etc. You’ll need to fix each item until you get the green Ready to Install as shown below.

8) Database information.

Next you’ll need to enter in your database information from step 6. You’re installing into a clean database, so no need to save existing tables. As long as the database info checks out, the installer will continue.

9) General Settings

The next step will prompt for general admin info such as email, name and password.

10) Email Configuration

Next up is your mail server configuration. We recommend SendGrid or SparkPost. The information below shows setting up as an SMTP server. But you can also setup with an API, which is recommended.

*You can skip this and setup the mail under the “Configuration Settings” once the installation completes.

 

11) Setup Cron

You’ll need to schedule cron jobs to keep things updated on the mautic instance.

a) from a command line type:

crontab -e

b) paste in the following lines:

*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:broadcasts:send
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:segments:update
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:campaigns:rebuild
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:campaigns:trigger
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:emails:send
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:iplookup:download
*/5 * * * * php /var/www/outergain.com/public_html/content/app/console mautic:social:monitoring

*Note: the above tells each job to run every 5 minutes. For some jobs, this is complete overkill, so schedule according to your needs. Also, you may not need all of these jobs. For example, if you haven’t setup mautic to queue mail, then you don’t need it to have email send as a cron job.

The cron layout is:

minute hour day-of-month month day-of-week command

c) Save the file and then type:

run-parts /etc/cron.daily

To check the status of your cron jobs, type this in a terminal window:

/etc/init.d/cron status

BOOYAH!

Nicely done! Now the fun begins…

Would you like to learn more?

Get free marketing tips from Outer Gain! We help people sell beyond their reach!

Written By

Kyler Boudreau

Kyler Boudreau lives with his wife and daughter on the beautiful island of Kauai. Kyler is an independent filmmaker (see theatereleven.com). His wife, Sandi Boudreau, is a Crown Diamond level distributor with Young Living.

Connect with Kyler

One thought on “Install Mautic in a Sub Folder on NGINX

  1. Hi , thank you for your guide but this is doesn’t work :(.
    setup nginx + php7-fpm
    Config (i just have for test):

    server {

    listen 80;
    server_name XX.com http://www.XX.com;

    location /XX.com {
    try_files $uri $uri/ /XX.com/?q=$uri&$args;
    }

    }

    error:
    2017/09/10 09:37:59 [error] 19418#19418: *1 openat() “/var/www/kedaranatha/data/www/XX.com/index.php/installer” failed (20: Not a directory), client: 47.155.18.15, server: XX.com, request: “GET /index.php/installer HTTP/1.1”, host: “XX.com”

    browser error:
    404 Not Found

    nginx/1.12.1

Leave a Reply

Your email address will not be published. Required fields are marked *