Skip to content

Prepare RdCore on Ubuntu 20.04

Dirk van der Walt edited this page Sep 1, 2022 · 2 revisions

Install Nginx

  • We assume you have a clean install of Ubuntu 20.04 WITHOUT Apache installed.
  • If you have not yet added a sudo user add one now.
# Add the system user
sudo adduser system
# Update the system to the latest
usermod -aG sudo system
  • Make sure it is up to date.
# Get the latest package lists
sudo apt-get update
# Update the system to the latest
sudo apt-get upgrade
  • Ensure the English language pack is installed
sudo apt-get -y install language-pack-en-base
  • Install Nginx
sudo apt-get -y install nginx
  • Ensure the web server starts up and is running
sudo systemctl enable nginx
sudo systemctl start nginx
  • Navigate to the IP Address of the server where you installed Nginx using a browser to ensure Nginx serves content e.g. http://127.0.0.1

Install and Configure PHP-FPM to allow Nginx interpret .php files

  • The default install of Nginx does not support the serving of .php files. We will install PHP-FPM to listen for PHP requests.

  • Install the php-fpm package:

sudo apt-get -y install php-fpm
sudo systemctl enable php7.4-fpm
sudo systemctl start php7.4-fpm

Modify Nginx to use PHP-FPM

  • Edit the default server file:
sudo vi /etc/nginx/sites-enabled/default
  • Add index.php to this line:
#add index.php
index index.php index.html index.htm;
  • Activate PHP processing by uncommenting the section below. (Note that we use the UNIX socket for better performance)
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
}
  • Deny access to .htaccess files
 # deny access to .htaccess files, if Apache's document root
 # concurs with nginx's one
 #
 location ~ /\.ht {
     deny all;
 }
  • Reload the Nginx web server's configuration
sudo systemctl reload nginx
  • Create an info.php file and confirm that it interprets PHP properly
sudo vi /usr/share/nginx/html/info.php
  • Contents:
 <?php phpinfo(); ?>

Install MariaDB

Why MariaDB?

  • We discovered that the version of MySQL that comes bundled by default with Ubuntu 20.04 are breaking things on RdCore.
  • For this reason we install MariaDB as an alternative.
  • MariaDB is an open-source relational database management system, commonly used as an alternative for MySQL as the database portion of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack
  • It is intended to be a drop-in replacement for MySQL.
  • Be sure to supply a root password for the MariaDB database when asked for it if you are security conscious else simply hit the ESC key.
sudo apt-get -y install mariadb-server php-mysql
sudo systemctl enable mariadb
sudo systemctl restart mariadb
sudo systemctl status mariadb

Disable strict mode

  • With Ubuntu 20.04, the bundled release of MariaDB is at version 10.3 which introduced a few Strict modes which have some problems with RdCore database implementation
  • We will disable Strict SQL Mode in MariaDB by creating a new file /etc/mysql/conf.d/disable_strict_mode.cnf
sudo vi /etc/mysql/conf.d/disable_strict_mode.cnf
  • Enter these two lines:
[mysqld]
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  • Save the file and restart the MariaDB Server
sudo systemctl restart mariadb

Nginx Performance Tuning - Modify expiry date for certain files

  • Edit the /etc/nginx/sites-available/default file:
sudo vi /etc/nginx/sites-available/default
  • Add the following inside the server section:
location ~ ^/cake4/.+\.(jpg|jpeg|gif|png|ico|js|css)$ {
    rewrite ^/cake4/rd_cake/webroot/(.*)$ /cake4/rd_cake/webroot/$1 break;
    rewrite ^/cake4/rd_cake/(.*)$ /cake4/rd_cake/webroot/$1 break;
    access_log off;
    expires max;
    add_header Cache-Control public;
}
  • Reload Nginx:
sudo systemctl reload nginx.service

Next Steps