Synology

This page contains some lessons learned when configuring my Synology NAS

The Synology name is trademark of Synology, Inc., registered in the Republic of China (Taiwan) and other regions

Handle Url by Script

modified 21-July-2018 23:37:57

This article is about DSM 6.1.6

To handle a url of the webserver by a PHP dispatcher script you will have to add configurations to the web server. On Synology you are not allows to modify system configuration files, so we have to create a new configuration for each web site.

Identify Guid of each website

First identify the guid of the website(s) you want the script to be active. In a terminal session to the server enter:

vi /etc/nginx/app.d/server.webstation-vhost.conf

In the file you will find an include of site-specific configuration files for each website url, for instance:

server {
    listen      80;
    listen      [::]:80;
    listen      443 ssl;
    listen      [::]:443 ssl;
    server_name www.homecraft.nl;

    include /usr/local/etc/nginx/conf.d/c26ab877-1e0e-4232-94f6-0cf9edd41e6e/user.conf*;

Note that www.homecraft.nl and homecraft.nl will be defined as a separate website, with a different guid.

Configure script

For each website add user configuration by opening the text editor:

sudo vi /etc/nginx/conf.d/c26fbf77-1e0e-4232-94f6-0cf9edd41e6e/user.conf

For instance, we specify a script blog.php that is in the subdirectory blog of website www.homecraft.nl, that is stored at /var/services/web/homecraft.nl

location ~ ^/blog/content/.*$ {
     deny all;
     return 404;
}
location ~ ^/blog/.*$ {
        root /var/services/web/homecraft.nl;
        try_files $uri /blog/blog.php$is_args$args;
}
location ~ ^/$ {
        root /var/services/web/homecraft.nl;
        try_files $uri /blog/blog.php;
}

The first section with the 'deny all' and status 404 is to disable direct access to the system files in the /blog/content directory that should only be viewed by the dispatcher script.

To reload the configuration restart the webserver:

sudo synoservicecfg --restart nginx

Enable mail from PHP

modified 15-July-2018 16:32:22

To enable mail in PHP there are two alternatives

  • Enable Synology notifications to enable smtp
  • Install Mail Server

Enable synology notifications to enable smtp

Go to Configuration / Notifications and enable email notifications and specify the smtp server etc.

Then you can send emails from PHP:

$msg = "<style>* {font-family: \"Verdana\"; font-size:11px;}</style>".
            "<h1>Test email</h1><p>Test email</p>";
$headers = "From: somebody@xs4all.nl\r\n" .
        "Reply-To: somebody@xs4all.nl\r\n" .
        "MIME-Version: 1.0\r\n".
        "Content-Type: text/html; charset=ISO-8859-1\r\n".
        "X-Mailer: PHP/" . phpversion();
mail("somebody@xs4all.nl", "Test email", $msg, $headers);

Install Mail Server

Note: I did not manage to get it to work yet

Install MailServer

Configure SMTP and SMTP relay

Log in the the Synology server with terminal

You can send a test email using:

echo "Subject: sendmail test" | sendmail -v somebody@xs4all.nl

Next create the following files

/etc/php/conf.d/custom.ini
/usr/local/etc/php56/conf.d/custom.ini
/usr/local/etc/php70/conf.d/custom.ini
/etc.defaults/php/conf.d/custom.ini

all with contents:

[mail function]
sendmail_from = fsomebody@xs4all.nl
sendmail_path = /var/packages/MailServer/target/sbin/sendmail -t

Next restart webserver: sudo synoservicecfg --restart nginx

Note: I did not manage to get it to work yet