Skip to content

Latest commit

 

History

History
278 lines (192 loc) · 6 KB

deploy.md

File metadata and controls

278 lines (192 loc) · 6 KB

Deploy in production

In this documentation, it is expected that you're at ease with managing a webserver with PHP. Nginx is used as the webserver in this documentation. Apache should work as well, but it hasn't been tested.

Warning: Bileto is not ready for the production yet. You’ll probably lose your data during an upgrade.

Check the requirements

Check Git is installed:

$ git --version
git version 2.38.1

Check PHP version (must be >= 8.1):

$ php --version
PHP 8.1.12 ...

Check your database version. If you use PostgreSQL (must be >= 11):

$ psql --version
psql (PostgreSQL) 14.3

Or if you use MariaDB (must be >= 10.4):

$ mariadb --version
mariadb 10.6.11-MariaDB

Check Composer is installed:

$ composer --version
Composer version 2.4.4 2022-10-27 14:39:29

Check the following PHP extensions are installed:

  • ctype
  • iconv
  • intl
  • pdo + pdo_pgsql or pdo_mysql (depending on which database you use)
  • sodium
  • xsl
  • zip
$ php -m
[PHP Modules]
...

Create the database

Create a dedicated user and database for Bileto.

With PostgreSQL:

# sudo -u postgres psql
postgres=# CREATE DATABASE bileto_production;
postgres=# CREATE USER bileto_user WITH ENCRYPTED PASSWORD 'secret';
postgres=# GRANT ALL PRIVILEGES ON DATABASE bileto_production TO bileto_user;

With MariaDB:

# mariadb -u root -p
MariaDB [(none)]> CREATE DATABASE bileto_production;
MariaDB [(none)]> CREATE USER 'bileto_user'@'localhost' IDENTIFIED BY 'secret';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON bileto_production.* TO 'bileto_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;

Download the code

You may want to put Bileto under a specific folder on your server, for instance:

$ cd /var/www/

Clone the code:

$ git clone https://github.com/Probesys/bileto.git

If your user doesn't have the permission to write in this folder, execute the command as root.

About file permissions

You’ll have to make sure that the system user that runs the webserver can access the files under the /var/www/bileto directory. This user is often www-data, apache or nginx. In this documentation, we’ll use www-data because it is the most generic name.

Set the owner of the files to the user that runs your webserver:

$ cd /var/www/bileto
$ sudo chown -R www-data:www-data .

From now on, you must execute the commands as the user www-data. You can either start a shell for this user (to execute as root):

# su www-data -s /bin/bash
www-data$ cd /var/www/bileto

Or prefix all the commands with sudo -u www-data. For instance:

$ sudo -u www-data php bin/console

If your current user is not in the sudoers list, you’ll need to execute the sudo commands as root.

The commands that need to be executed as www-data will be prefixed by www-data$ instead of simply $ in the rest of the documentation.

Switch to the latest version

Checkout the code to the latest version of Bileto:

www-data$ git checkout $(git describe --tags $(git rev-list --tags --max-count=1))

Go to GitHub if you want to find the full list of releases.

Configure the application

Create a .env.local file:

www-data$ cp env.sample .env.local

And edit the variables to your needs. The file is commented to help you to change it.

Restrict the permissions on this file:

www-data$ chmod 400 .env.local

Install the dependencies

Install the Composer dependencies:

www-data$ composer install --no-dev --optimize-autoloader

You don't need to install the NPM dependencies because the assets are already pre-built for production.

Setup the database

Initialize the database:

www-data$ php bin/console doctrine:migrations:migrate --no-interaction
www-data$ php bin/console db:seeds:load

Configure the webserver

Configure your webserver to serve Bileto. With Nginx:

server {
    server_name bileto.example.com;
    root /var/www/bileto/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/bileto_error.log;
    access_log /var/log/nginx/bileto_access.log;
}

Check the configuration is correct:

$ nginx -t

And reload Nginx:

$ systemctl reload nginx

Open Bileto in your web browser: it should display the login page.

Setup the Messenger worker

The Messenger worker performs asynchronous jobs. It's a sort of Cron mechanism on steroids. We'll use Systemd in this documentation, but note that the only requirement is that a command needs to run in the background.

Create the file /etc/systemd/system/bileto-worker.service:

[Unit]
Description=The Messenger worker for Bileto

[Service]
ExecStart=php /var/www/bileto/bin/console messenger:consume async scheduler_default --time-limit=3600

User=www-data
Group=www-data

Restart=always
RestartSec=30

[Install]
WantedBy=default.target

Enable and start the service:

# systemctl enable bileto-worker
# systemctl start bileto-worker

You can find the logs with:

# journalctl -f -u bileto-worker@service

Create your users

You must create your first user with the command line:

www-data$ php bin/console app:users:create [email protected] --password=secret

Important note: users created with the command line have "super-admin" permissions and can do anything in Bileto.

Then, try to login via the interface, it should work. You can start using Bileto now.