Table of Contents

Installing RADIUSdesk on Ubuntu 16.04 using Nginx

Background


What do we require

Requirement Comment
Interpret PHP Scripts We would like the web server to call the PHP interpreter when a page ending with .php is requested.
Be able to have access to the MySQL functions of PHP Since we set up a LEMP server, we need to have a MySQL server installed and accessible from PHP.
Modify the expiry date of http headers to encourage caching We want files that does not change (e.g. css or images) to be cached on the client's side to make the client's experience more pleasant
Compress text before they are served to the client We can compress the text that flows between the client and the server and in this way reduce the over the line bytes which in turn should also give the client a more pleasant experience
Enable rewrite rules in CakePHP for pretty URL's CakePHP makes use of the .htaccess files in Apache to enable pretty URLs. Since Nginx does not support .htaccess files, we need to change Nginx to behave in the same way.

HOWTO

Install Nginx

  • To remove Apache
   sudo systemctl start apache2.service
   sudo apt-get remove apache2
 
sudo apt-get install language-pack-en-base
sudo apt-get install nginx
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
 sudo vi /etc/nginx/sites-enabled/default
 
#root /var/www/html;
root /usr/share/nginx/html;

Configure Nginx to interpret .php files

php-fpm

sudo apt-get install php-fpm

Modify Nginx

    sudo vi /etc/nginx/sites-enabled/default
    #add index.php
    index index.php index.html index.htm;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
sudo systemctl reload nginx.service
sudo vi /usr/share/nginx/html/test.php
    <?php
        phpinfo();
    ?>

Install MySQL

sudo apt-get install mysql-server php-mysql

Disable strict mode

sudo vi /etc/mysql/conf.d/disable_strict_mode.cnf
[mysqld]
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sudo systemctl restart mysql.service

Performance tune Nginx

Modify expiry date for certain files

sudo vi /etc/nginx/sites-available/default
location ~ ^/cake2/.+\.(jpg|jpeg|gif|png|ico|js|css)$ {
    rewrite ^/cake2/rd_cake/webroot/(.*)$ /cake2/rd_cake/webroot/$1 break;
    rewrite ^/cake2/rd_cake/(.*)$ /cake2/rd_cake/webroot/$1 break;
    access_log off;
    expires max;
    add_header Cache-Control public;
}
sudo systemctl reload nginx.service

Compress the text before sending it to client

sudo vi /etc/nginx/nginx.conf
gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
sudo systemctl restart nginx.service

Install RADIUSdesk

Install CakePHP

  • As from December 2016 we started a migration process of migrating from CakePHP v2 to CakePHP v3.
  • The ORM component of CakePHP v3 is completely new and different which makes the migration fairly involved.
  • Since the architecture of RADIUSdesk is following modern design principles it allows us to run both CakePHP v2 and CakePHP v3 simultaneously.
  • We can then do the migration gradually over time.
Required packages
sudo apt-get install php-cli php-gd php-curl php-xml php-mbstring php-intl
Install CakePHP v2
sudo cp 2.9.7.tar.gz /usr/share/nginx/html
cd /usr/share/nginx/html
sudo tar -xzvf 2.9.7.tar.gz 
sudo ln -s ./cakephp-2.9.7 ./cake2
sudo systemctl reload php7.0-fpm.service
Install the RADIUSdesk CakePHP v2 Application
sudo apt-get install subversion
cd /usr/share/nginx/html/cake2
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/rd_cake ./rd_cake
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/tmp
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/Locale
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/img/flags
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/img/nas
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/img/realms
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/img/dynamic_details
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/img/dynamic_photos
sudo chown -R www-data. /usr/share/nginx/html/cake2/rd_cake/webroot/files/imagecache
Install the RADIUSdesk CakePHP v3 Application
cd /usr/share/nginx/html/
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/cake3 ./cake3
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/tmp
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/logs
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/webroot/img/realms
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/webroot/img/dynamic_details
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/webroot/img/dynamic_photos
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/webroot/img/access_providers
sudo chown -R www-data. /usr/share/nginx/html/cake3/rd_cake/webroot/files/imagecache

The Database

sudo su
mysql -u root
create database rd;
GRANT ALL PRIVILEGES ON rd.* to 'rd'@'127.0.0.1' IDENTIFIED BY 'rd';
GRANT ALL PRIVILEGES ON rd.* to 'rd'@'localhost' IDENTIFIED BY 'rd';
exit;
    sudo mysql -u root rd < /usr/share/nginx/html/cake3/rd_cake/setup/db/rd.sql
  • If you have a small server like a Raspberry Pi you, run the following SQL for better performance.
USE rd;
DELETE FROM phrase_values WHERE language_id=16 OR language_id=15 OR language_id=13 OR language_id=5 OR language_id=14;

Configure Nginx

    sudo vi /etc/nginx/sites-enabled/default
location /cake2/rd_cake {
     rewrite ^/cake2/rd_cake/(.*)$ /cake2/rd_cake/webroot/$1 break;
     try_files $uri $uri/ /cake2/rd_cake/webroot/index.php?q=$uri&$args;
}
 
location /cake3/rd_cake {
   rewrite ^/cake3/rd_cake(.+)$ /cake3/rd_cake/webroot$1 break;
   try_files $uri $uri/ /cake3/rd_cake/index.php$is_args$args;
}
   sudo systemctl reload nginx.service

Viewer component

cd /usr/share/nginx/html/
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/rd ./rd
cd /usr/share/nginx/html/
sudo svn checkout svn://svn.code.sf.net/p/radiusdesk/code/extjs ./
sudo mv  ext-6-2-sencha_cmd.tar.gz ./rd
cd /usr/share/nginx/html/rd
sudo tar -xzvf ext-6-2-sencha_cmd.tar.gz

Cron Scripts

sudo cp /usr/share/nginx/html/cake2/rd_cake/Setup/Cron/rd /etc/cron.d/

Next steps