Installation on Linode

Version Date Notes By
0.1 2021-07-13 Initial release acl

Notes

As example we are using sgi.wemake.pt and sgi-back.wemake.pt as the domains. This should be changed to the real subdomains.

Backend

  1. Clone the core project using: git clone <https-link> <backend-folder>

  2. Go to the backend folder and create the .env file using: cp .env.example .env

    Check how many licenses the client has. Also check or ask for the client number in order to update the root and wemake users' passwords

  3. Set random app key on .env file (just so a package from composer can be installed, you cannot use yet the php artisan key:generate command). You can use this app_key for now: base64:rmoQ7TT61ll/UvSARXWOmPPniautyOaiypjoKoMfmEI=

  4. Install composer packages using: composer install --no-dev

  5. Install the modules needed using: composer require <modules>

  6. Set the proper permissions using: sudo chown -R www-data storage/ bootstrap/cache/ and sudo chmod -R 775 storage/ bootstrap/cache/

  7. Generate an application key using: php artisan key:generate

  8. Generate the JWT secret php artisan jwt:secret

  9. Create the database, database user and assign proper privileges.

    DO NOT FORGET to write down the user, database name and password

    sudo mysql
    CREATE DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    CREATE USER '<user>'@'localhost' IDENTIFIED BY '<password>'; (you can use bitwarden or the following command to generate a password: `openssl rand -base64 32`)
    GRANT ALL PRIVILEGES ON <database_name>.* TO '<user>'@'localhost';

View this document to check which REDIS_DB_NUM and REDIS_DB_CACHE to use, as well as the echo server port and add those in https://docs.google.com/spreadsheets/d/1NL24JtrzUMBAhj2nftBQGdZmb8kQO5nc0_henXVuZK4/edit?usp=sharing

  1. Update the .env file (no need to say this though)

  2. Run migrations and seed translations using: php artisan migrate && php artisan reseed

  3. Update root and wemake users' passwords using: php artisan tinker and on tinker run User::whereKey([1, 2])->update(['password' => Hash::make(<password>)])

  4. Test apache configuration, will throw errors if there's something wrong, using: sudo apachectl configtest

  5. Go to /etc/apache2/sites-available/ and create a new apache configuration file with the following name sgi-back.wemake.pt.conf

HTTP

<Directory /var/www/html/sgi-back.wemake.pt/public>
        AllowOverride All
        Require all granted
</Directory>
<VirtualHost sgi-back.wemake.pt:80>
        ServerName sgi-back.wemake.pt
        DocumentRoot /var/www/html/sgi-back.wemake.pt/public

        ErrorLog /var/log/apache2/sgi-back.wemake.pt.error.log
        CustomLog /var/log/apache2/sgi-back.wemake.pt.access.log combined
</VirtualHost>

HTTPS

<Directory /var/www/html/sgi-back.wemake.pt/public>
        AllowOverride All
        Require all granted
</Directory>
<VirtualHost sgi-back.wemake.pt:443>
        ServerName sgi-back.wemake.pt
        DocumentRoot /var/www/html/sgi-back.wemake.pt/public

        SSLEngine on
        SSLCertificateFile <path_to_cert_file>
        SSLCertificateKeyFile <path_to_key_file>

        ErrorLog /var/log/apache2/sgi-back.wemake.pt.error.log
        CustomLog /var/log/apache2/sgi-back.wemake.pt.access.log combined
</VirtualHost>
  1. Enable the new configuration using: sudo a2ensite sgi-back.wemake.pt.conf

  2. Reload apache using: sudo systemctl reload apache2

  3. Test that the backend is online: http://sgi-back.wemake.pt/ you should get a 404 page error, which is normal because there's no route for root

  4. Create the laravel echo server config file using: cp laravel-echo-server.example.json laravel-echo-server.json

  5. Update the laravel echo server config file

HTTP

{
    "appKey": "47r1i66li4cn9anb4pocpb9h6eb5fc7d35f5lhs363gho1kmqcqf2tred6p2",
    "authHost": "https://sgi-back.wemake.pt",
    "authEndpoint": "/broadcasting/auth",
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "127.0.0.1",
            "options": {
                "db": <REDIS_DB_NUM>
            }
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": false,
    "host": "sgi-back.wemake.pt",
    "port": <laravel-echo-server-port>,
    "referrers": [
        {
            "host": "*",
            "apiKey": "nrhmk8ic64lgnqbs6t794gpj6per33ho5q34j2mrgia61j8hf238rf0c014b"
        }
    ],
    "socketio": {
        "wsEngine": "uws"
    },
    "protocol": "http",
    "sslCertPath": "",
    "sslKeyPath": "",
    "verifyAuthPath": true,
    "verifyAuthServer": false
}

HTTPS

{
    "appKey": "47r1i66li4cn9anb4pocpb9h6eb5fc7d35f5lhs363gho1kmqcqf2tred6p2",
    "authHost": "https://sgi-back.wemake.pt",
    "authEndpoint": "/broadcasting/auth",
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "127.0.0.1",
            "options": {
                "db": <REDIS_DB_NUM>
            }
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": false,
    "host": "sgi-back.wemake.pt",
    "port": <laravel-echo-server-port>,
    "referrers": [
        {
            "host": "*",
            "apiKey": "nrhmk8ic64lgnqbs6t794gpj6per33ho5q34j2mrgia61j8hf238rf0c014b"
        }
    ],
    "socketio": {
        "wsEngine": "uws"
    },
    "protocol": "https",
    "sslCertPath": "<path_to_cert_file>",
    "sslKeyPath": "<path_to_key_file>",
    "verifyAuthPath": true,
    "verifyAuthServer": false
}
  1. Run laravel-echo-server start on the backend folder and check if it works. If it is working, stop it by doing CTRL+C

  2. Use supervidord to configure the service, create a new file /etc/supervisor/conf.d/sgi.wemake.pt.conf and use the following configuration (change as needed)

    [program:<client name>-laravel-echo-server]
    directory=/var/www/html/sgi-back.wemake.pt
    command=/usr/bin/laravel-echo-server start
    autostart=true
    autorestart=true
    user=root
    redirect_stderr=true
    stdout_logfile=/var/www/html/sgi-back.wemake.pt/storage/logs/laravel-echo-server.log
  3. Use sudo supervisorctl reread && sudo supervisorctl update in order for the new configuration to be available

  4. sudo supervisorctl start <client name>-laravel-echo-server

  5. Edit the same file (/etc/supervisor/conf.d/sgi.wemake.pt.conf) and add this for the laravel-queue-work

    [program:<client name>-laravel-queue-work]
    process_name=%(program_name)s_%(process_num)02d
    command=php /var/www/html/sgi-back.wemake.pt/artisan queue:work --sleep=3
    autostart=true
    autorestart=true
    user=www-data
    numprocs=2
    redirect_stderr=true
    stdout_logfile=/var/www/html/sgi-back.wemake.pt/storage/logs/laravel-queue-listen.log
  6. Use sudo supervisorctl reread && sudo supervisorctl update in order for the new configuration to be available (same as in step 21)

  7. sudo supervisorctl start <client name>-laravel-queue-work:

Frontend

  1. Use gulp export on your local machine

  2. Copy the zipped 'export' folder CONTENTS (zip all the files within export folder, not the folder itself) via ssh and put it on the home directory (/home/devel)

  3. Go to /var/www/html and create the frontend folder using: mkdir sgi.wemake.pt

  4. Go to the frontend folder using cd sgi.wemake.pt and then unzip the frontend there using unzip ~/frontend.zip -d .

  5. Update env.js (you can take a look at another frontend folder env.js in case you're not sure about some settings)

  6. Go to /etc/apache2/sites-available/ and create a new apache configuration file with the following name sgi.wemake.pt.conf

HTTP

<Directory /var/www/html/sgi.wemake.pt>
        AllowOverride All
        Require all granted
</Directory>
<VirtualHost sgi.wemake.pt:80>
        ServerName sgi.wemake.pt
        DocumentRoot /var/www/html/sgi.wemake.pt

        ErrorLog /var/log/apache2/sgi.wemake.pt.error.log
        CustomLog /var/log/apache2/sgi.wemake.pt.access.log combined
</VirtualHost>

HTTPS

<Directory /var/www/html/sgi.wemake.pt>
        AllowOverride All
        Require all granted
</Directory>
<VirtualHost sgi.wemake.pt:443>
        ServerName sgi.wemake.pt
        DocumentRoot /var/www/html/sgi.wemake.pt

        SSLEngine on
        SSLCertificateFile <path_to_cert_file>
        SSLCertificateKeyFile <path_to_key_file>

        ErrorLog /var/log/apache2/sgi.wemake.pt.error.log
        CustomLog /var/log/apache2/sgi.wemake.pt.access.log combined
</VirtualHost>
  1. Enable the new configuration using sudo a2ensite sgi.wemake.pt.conf

  2. Run sudo systemctl reload apache2

  3. Test it on sgi.wemake.pt

DO NOT FORGET to disable module dependencies

Try to export a PDF and Excel to check if all permissions are ok

DO NOT FORGET to register the installation on https://docs.google.com/spreadsheets/d/1BqVOwCL8RSKFSLd4W3EJRQOiSbKoXo8mph6qs3rWsmE/edit?usp=sharing