Friday, October 18, 2019

Installing MAILJET to Ubuntu 18.04 using POSTFIX (to send email using smtp mail relay)

MailJet is a Third Party email sending (SMTP mail relay).  Mailjet allow you to send up to 200 emails per day for Free (no strings attached!).

Go to mailjet to sign-up here:   https://www.mailjet.com

This guide will quickly show you all the commands to integrate MailJet to your Ubuntu 18.04 Server using POSTFIX.


INSTALLING POSTFIX MODULES AND SASL PASSWORD

sudo apt install postfix libsasl2-modules


SETUP POSTFIX's MAIN.CF CONFIGURATION FILE

sudo nano /etc/postfix/main.cf


# outbound relay configurationsrelayhost = in-v3.mailjet.com:587smtp_sasl_auth_enable = yessmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options = noanonymoussmtp_tls_security_level = mayheader_size_limit = 4096000

NOTE: your relayhost value may be different, please double check with your MailJet account.


SETUP POSTFIX's SASL_PASSWD FILE 
(get your api-key and secret-key from your MailJet account)

sudo nano /etc/postfix/sasl_passwd

in-v3.mailjet.com:587  api-key:secret-key

sudo postmap /etc/postfix/sasl_passwd
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo systemctl restart postfix


CONFIGURE YOUR SENDER ADDRESS -or- DOMAIN AUTHENTICATION
(this is VERY IMPORTANT for your email deliverability)

Go to your MailJet account and find Sender Email Address
Go to your MailJet account and find Domain Authentication


TEST SENDING EMAIL AND CHECK YOUR SCORE!

sudo apt install bsd-mailx


echo "this is a test email." | mailx -r from-address -s "Hello sending from MailJet" to-address


Installing Akaunting (open source accounting / invoicing software) on Ubuntu 18.04 LEMP

Welcome to my quick guide how to install self-hosted Akaunting web application. Akaunting is a very good open source accounting software. It is 100% free to use and customize because it is open source. It is built solidly using PHP and Laravel and stores data using MySQL server.

Here is the link to Akaunting project official website:

https://www.akaunting.com

Before you get started you may want to install LEMP (linux nginx mysql and PHP) first.
I have a quick 10 minute guide here:

https://ubuntu-server-how-to-tips-tricks.blogspot.com/2019/10/installing-lemp-linux-nginx-mysql-php.html

in this example I am going to store my akaunting software in /data_local/app/www/akaunting
yours may be different such as /var/www/akaunting


After you have LEMP installed you can start installing Akaunting:


DOWNLOAD AND COPY AKAUNTING ZIP FILE FROM THIS URL

https://akaunting.com/thank-you


PREPARE THE DESTINATION DIRECTORY

mkdir -p /data_local/app/www/akaunting


UNZIP THE AKAUNTING ZIP FILE  (adjust filename as necessary for different version)

unzip Akaunting_1.3.17-Stable.zip


SET CORRECT PERMISSION ON DESTINATION DIRECTORY

chmod -R 775 /data_local/app/www/akaunting
chown -R www-data:www-data /data_local/app/www/akaunting


SETUP MYSQL DATABASE, USER AND PERMISSIONS

sudo mysql
create database akaunting;
create user accountant@localhost identified by '<your_password_here>';
grant all privileges on akaunting.* to accountant@localhost;
flush privileges;
exit;


INSTALL ADDITIONAL PHP MODULES AS REQUIRED BY AKAUNTING

sudo apt install php-imagick php7.2-gd php7.2-curl php7.2-zip php7.2-xml php7.2-mbstring php7.2-bz2 php7.2-intl


SETUP NGINX CONFIGURATION FILE USING THE FOLLOWING TEXT

nano /etc/nginx/sites-enabled/default


server {

    listen 80 default_server;

    # listen 443 ssl http2;



    # ssl_certificate /ssl/crt/file.crt;

    # ssl_certificate_key /ssl/key/file.key;



    server_name _;



    root /data_local/app/www/akaunting/;



    add_header X-Frame-Options "SAMEORIGIN";

    add_header X-XSS-Protection "1; mode=block";

    add_header X-Content-Type-Options "nosniff";



    index index.html index.htm index.php;



    charset utf-8;



    location / {

        try_files $uri $uri/ /index.php?$query_string;

    }



    # Prevent Direct Access To Protected Files

    location ~ \.(env|log) {

        deny all;

    }



    # Prevent Direct Access To Protected Folders

    location ~ ^/(^app$|bootstrap|config|database|resources|routes|storage|tests|artisan) {

        deny all;

    }



    # Prevent Direct Access To modules/vendor Folders Except Assets

    location ~ ^/(modules|vendor)\/(.*)\.((?!ico|gif|jpg|jpeg|png|js|css|less|sass|font|woff|woff2|eot|ttf|svg).)*$ {

        deny all;

    }



    error_page 404 /index.php;



    # Pass PHP Scripts To FastCGI Server

    location ~ \.php$ {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # Depends On The PHP Version

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

    }



    location ~ /\.(?!well-known).* {

        deny all;

    }

}


sudo systemctl nginx reload


GO TO BROWSER AND FINISH CONFIGURATION



Just follow the rest of the guide / wizard from the Akaunting.

Congratulations! You have just installed a free and powerful accounting software for your business!


REVERSE PROXY SETTING

If you are using Akaunting behind reverse proxy, make sure you add this setting:

fastcgi_param HTTPS 1;

This setting saved my day!


Installing LEMP (linux nginx mysql php) on Ubuntu 18.04 LTS and PHP 7.2+

Here is a quick guide how to install LEMP (linux + nginx + mysql/mariadb + PHP 7.2) on Ubuntu Server 18.04 LTS.

If this is a brand new server, you may want to do the Initial Commands I do for every new Ubuntu server first. It will only take about 3 min and you can find those initial commands here:

https://ubuntu-server-how-to-tips-tricks.blogspot.com/2019/10/initial-setup-commands-for-every-new.html

PREPARE APT

sudo apt update


INSTALL NGINX (web server)

sudo apt install nginx
sudo systemctl enable nginx


INSTALL MYSQL SERVER (or MARIADB)

sudo apt install mariadb-server mariadb-client
sudo systemctl enable mariadb
sudo mysql_secure_installation


INSTALL PHP 7.2+

sudo apt install php7.2 php7.2-fpm php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline


That's it, if all goes well you can do all of the above in less than 10 min!

Congratulations! you now have a fully functional LEMP server!






Initial setup commands for every new ubuntu server I setup

Each time I setup a new Ubuntu Server, I always do the same initial commands.  These commands will set the locale, date & time and base softwares.

SETTING LOCALE

sudo dpkg-reconfigure locales


SETTING TIMEZONE

timedatectl
timedatectl list-timezones
timedatectl set-timezone Region/Location


UPDATING APT

sudo apt update


UPGRADING OPERATING SYSTEM

sudo apt upgrade


INSTALLING BUILD ESSENTIAL

sudo apt install build-essential
sudo apt install software-properties-common