Magento (AlmaLinux 8)

Magento (AlmaLinux 8)

  • OS: almalinux 8

Description

Magento is an open-source e-commerce platform that allows businesses to create and manage online stores. It offers a wide range of features and customization options, making it a popular choice for both small and large businesses.

Software included

Package Version
Magento latest
Docker 3.20.10
Docker compose 2.12.2
containerd.io 1.6.10

Initial start of the service

This application uses Docker to provide faster startup of the adjacent software (Magento) and direct use of it. This eliminates the need to familiarize yourself with its specifics in terms of configuration and installation. To start working directly with the application, all you need to do is visit the IP address assigned to your virtual machine in your browser to view your new Magento installation.

Note: By default, Magento can be accessed directly by IP address. To start using Magento with your real domain, you first need to point the domain in question to your IP address and change the settings for where Magento opens from through its admin panel.

Quick settings and frequently asked questions

  • Logging into the cloud service is done using an SSH key or password that you have specified.
  • Docker is installed as recommended by the official docker documentation.
  • The standard docker and docker compose commands are now available in this application.
  • When the virtual machine is first started, it takes a few minutes before a Docker container containing Magento is started.
  • Magento's data is set to be persistent and is located in /opt/magento/data/. MariaDB is also persistent and stores its databases in /opt/mariadb/data/.
  • The user to access the Magento admin panel is admin and the password is P@ssw0rd!.

Note: By default, MAGENTO_HOST is set to be the first address of the virtual machine. The goal of this is to have access immediately after starting the machine. To start using Magento with your real domain, you first need to point the domain in question to your IP address and change the settings for where Magento opens from through its admin panel.

Additional Docker settings

Additional Magento settings that you can change and that are controlled directly by Docker are set as variable values in the configuration file /opt/docker-magento/docker-compose.yml:

Note: After changing any of the values, you must recreate the Docker container on which the application is running. For more information, please read the Recreating Docker containers section.

Magento configuration options

General options

  • APACHE_HTTP_PORT_NUMBER: Port used by Apache for HTTP. Default: 8080
  • APACHE_HTTPS_PORT_NUMBER: Port used by Apache for HTTPS. Default: 8443
  • MAGENTO_EXTERNAL_HTTP_PORT_NUMBER: Port to access Magento from outside of the container using HTTP. Used to configure Magento's internal routes. Default: 80
  • MAGENTO_EXTERNAL_HTTPS_PORT_NUMBER: Port to access Magento from outside of the container using HTTPS. Used to configure Magento's internal routes. Default: 443
  • MAGENTO_USERNAME: Magento application username. Default: admin
  • MAGENTO_PASSWORD: Magento application password. Default: P@ssw0rd!
  • MAGENTO_EMAIL: Magento application email. Default: admin@example.com
  • MAGENTO_FIRST_NAME: Magento application first name. Default: FirstName
  • MAGENTO_LAST_NAME: Magento application last name. Default: LastName
  • MAGENTO_HOST: Magento host domain or IP address. Default: Current IP address, taken dynamically
  • MAGENTO_MODE: Magento mode. Valid values: default, production, developer. Default: default
  • MAGENTO_EXTRA_INSTALL_ARGS: Extra flags to append to the Magento 'setup:install' command call. No defaults
  • MAGENTO_ADMIN_URL_PREFIX: URL prefix to access the Magento Admin. Default: admin
  • MAGENTO_ENABLE_HTTPS: Whether to use SSL to access the Magento Store. Valid values: yes, no. Default: no
  • MAGENTO_ENABLE_ADMIN_HTTPS: Whether to use SSL to access the Magento Admin. Valid values: yes, no. Default: no
  • MAGENTO_DEPLOY_STATIC_CONTENT: Whether to deploy Magento static content during the initialization, to optimize initial page load time. Default: no
  • MAGENTO_KEEP_STATIC: Whether to keep the content of 'pub/static' folder during the initialization. Default: no
  • MAGENTO_SKIP_REINDEX: Whether to skip Magento re-index during the initialization. Default: no
  • MAGENTO_SKIP_BOOTSTRAP: Whether to skip performing the initial bootstrapping for the application. Default: no

HTTP cache server

  • MAGENTO_ENABLE_HTTP_CACHE: Whether to enable a HTTP cache server for Magento (i.e. Varnish). Default: no
  • MAGENTO_HTTP_CACHE_BACKEND_HOST: HTTP cache backend hostname. No defaults
  • MAGENTO_HTTP_CACHE_BACKEND_PORT_NUMBER: HTTP cache backend port. No defaults
  • MAGENTO_HTTP_CACHE_SERVER_HOST: HTTP cache server hostname. No defaults
  • MAGENTO_HTTP_CACHE_SERVER_PORT_NUMBER: HTTP cache server hostname. No defaults

Search engines

  • MAGENTO_SEARCH_ENGINE: Magento search engine. Default: elasticsearch7
  • MAGENTO_ELASTICSEARCH_HOST: Elasticsearch server host, if using Elasticsearch as a search engine. Default: elasticsearch
  • MAGENTO_ELASTICSEARCH_PORT_NUMBER: Elasticsearch server port number, if using Elasticsearch as a search engine. Default: 9200
  • MAGENTO_ELASTICSEARCH_USE_HTTPS: Whether to request Elasticsearch server with 'https://' prefix. Default: no
  • MAGENTO_ELASTICSEARCH_ENABLE_AUTH: Whether to enable authentication for connections to the Elasticsearch server. Default: no
  • MAGENTO_ELASTICSEARCH_USER: Elasticsearch server user login, if using Elasticsearch as a search engine and authentication is enabled. No defaults
  • MAGENTO_ELASTICSEARCH_PASSWORD: Elasticsearch server user password, if using Elasticsearch as a search engine and authentication is enabled. No defaults

Database configuration

  • MAGENTO_DATABASE_HOST: Hostname for MariaDB server. Default: mariadb
  • MAGENTO_DATABASE_PORT_NUMBER: Port used by MariaDB server. Default: 3306
  • MAGENTO_DATABASE_NAME: Database name that Magento will use to connect with the database. Default: magento
  • MAGENTO_DATABASE_USER: Database user that Magento will use to connect with the database. Default: magento
  • MAGENTO_DATABASE_PASSWORD: Database password that Magento will use to connect with the database. No defaults.
  • MAGENTO_ENABLE_DATABASE_SSL: Whether to enable SSL for database connections. Default: no
  • MAGENTO_VERIFY_DATABASE_SSL: Whether to verify the database SSL certificate when SSL is enabled for database connections. Default: yes
  • MAGENTO_DATABASE_SSL_CERT_FILE: Path to the database client certificate file. No defaults
  • MAGENTO_DATABASE_SSL_KEY_FILE: Path to the database client certificate key file. No defaults
  • MAGENTO_DATABASE_SSL_CA_FILE: Path to the database server CA bundle file. No defaults
  • ALLOW_EMPTY_PASSWORD: It can be used to allow blank passwords. Default: no

PHP configuration

  • PHP_ENABLE_OPCACHE: Enable OPcache for PHP scripts. Default: yes
  • PHP_EXPOSE_PHP: Enables HTTP header with PHP version. No default.
  • PHP_MAX_EXECUTION_TIME: Maximum execution time for PHP scripts. Без default.
  • PHP_MAX_INPUT_TIME: Maximum input time for PHP scripts. No default.
  • PHP_MAX_INPUT_VARS: Maximum amount of input variables for PHP scripts. No default.
  • PHP_MEMORY_LIMIT: Memory limit for PHP scripts. Default: 512M
  • PHP_POST_MAX_SIZE: Maximum size for PHP POST requests. No default.
  • PHP_UPLOAD_MAX_FILESIZE: Maximum file size for PHP uploads. No default.

SSL certificates

Use of own (paid) SSL certificates

If you already have ready-made, valid certificates, you need to make a few configuration modifications before you can use them. To achieve this, please follow these steps:

Step 1 - placing the certificates

Create a directory where the certificates will be stored:

mkdir /opt/certs/

Copy the certificates into the directory you just created and modify their permissions:

chown 1001:1001 /opt/certs/ -R

Step 2 - modify the Docker configuration

Open the docker configuration file /opt/docker-magento/docker-compose.yml with a text editor and find the following snippet:

  magento:
    image: docker.io/bitnami/magento:2
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mariadb
      - MAGENTO_DATABASE_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=magento
      - MAGENTO_DATABASE_NAME=magento
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
      - ALLOW_EMPTY_PASSWORD=yes
      - MAGENTO_USERNAME=admin
      - MAGENTO_PASSWORD=P@ssw0rd!
      - MAGENTO_EMAIL=admin@example.com
      - MAGENTO_ADMIN_URL_PREFIX=admin
    volumes:
      - '/opt/magento/data/:/bitnami/magento'

Edit it so it looks like this:

  magento:
    image: docker.io/bitnami/magento:2
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mariadb
      - MAGENTO_DATABASE_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=magento
      - MAGENTO_DATABASE_NAME=magento
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
      - ALLOW_EMPTY_PASSWORD=yes
      - MAGENTO_USERNAME=admin
      - MAGENTO_PASSWORD=P@ssw0rd!
      - MAGENTO_EMAIL=admin@example.com
      - MAGENTO_ADMIN_URL_PREFIX=admin
    volumes:
      - '/opt/magento/data/:/bitnami/magento'
      - '/opt/certs/cert.pem:/opt/bitnami/apache/conf/bitnami/certs/server.crt'
      - '/opt/certs/privkey.pem:/opt/bitnami/apache/conf/bitnami/certs/server.key'

Note that /opt/certs/cert.pem is the path to the certificate and /opt/certs/privkey.pem is the path to the private key. You can name the files and directories as you wish, but they must be specified correctly in the configuration

Step 3 - restart the Docker containers

cd /opt/docker-magento/
docker compose up -d

Issuing certificates with Letsencrypt

If you wish, you can always issue free certificates from Letsencrypt as well. To do this, please follow the steps below:

Step 1 - install the necessary packages

Login to your server as root and run the following commands:

dnf install -y epel-release
dnf install -y certbot

Step 2 - issuance of the certificate

Please note that in order for a free certificate to be issued, you must be able to verify your domain ownership in some way. Letsencrypt provides several options for verifying your domains, in this example we will use verification by running a temporary web server.

To do this, temporarily stop the container with the docker stop docker-magento-magento-1 command. Important: Performing this step will temporarily stop your site from working. Make sure you perform this action at a time when it will least affect your users.

Issue the certificate with the command certbot certonly --standalone --preferred-challenges http -d example.com, replacing "example.com" with the domain you pointed to your Cloud server IP address.

Step 3 - put the new certificates in the configuration

Open the docker configuration file /opt/docker-magento/docker-compose.yml with a text editor and find the following snippet:

  magento:
    image: docker.io/bitnami/magento:2
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mariadb
      - MAGENTO_DATABASE_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=magento
      - MAGENTO_DATABASE_NAME=magento
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
      - ALLOW_EMPTY_PASSWORD=yes
      - MAGENTO_USERNAME=admin
      - MAGENTO_PASSWORD=P@ssw0rd!
      - MAGENTO_EMAIL=admin@example.com
      - MAGENTO_ADMIN_URL_PREFIX=admin
    volumes:
      - '/opt/magento/data/:/bitnami/magento'

Edit it so it looks like this:

  magento:
    image: docker.io/bitnami/magento:2
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mariadb
      - MAGENTO_DATABASE_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=magento
      - MAGENTO_DATABASE_NAME=magento
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
      - ALLOW_EMPTY_PASSWORD=yes
      - MAGENTO_USERNAME=admin
      - MAGENTO_PASSWORD=P@ssw0rd!
      - MAGENTO_EMAIL=admin@example.com
      - MAGENTO_ADMIN_URL_PREFIX=admin
    volumes:
      - '/opt/magento/data/:/bitnami/magento'
      - '/etc/letsencrypt/live/example.com/cert.pem:/opt/bitnami/apache/conf/bitnami/certs/server.crt'
      - '/etc/letsencrypt/live/example.com/privkey.pem:/opt/bitnami/apache/conf/bitnami/certs/server.key'

With this modification, you end up "binding" the external certificates issued by Letsencrypt to the configuration that resides inside the docker container. Replace "example.com" with your domain name. After you change the configuration, you need to fix the certificate permissions with the command chown 1001:1001 /etc/letsencrypt/archive/example.com/ -R, again replacing "example.com" with your domain name.

Step 4 - start the services

Since the docker container is temporarily stopped, it needs to apply the new configuration and start it. Please run the following commands:

cd /opt/docker-magento/
docker compose up -d

Step 5 (optional) - automatic certificate renewal

Automatic renewal can be arranged via cron. You can set the following cron configuration to make auto-renewal happen:

# Automated Letsencrypt renewal
0 0 * * * /usr/bin/certbot renew --pre-hook 'docker stop docker-magento-magento-1' --post-hook 'chown 1001:1001 /etc/letsencrypt/archive/example.com/ -R; docker start docker-magento-magento-1'

Of course, you can change the runtime whenever you want. In the above example, this task will run every day at 00:00.

Working with Docker

The organization of this application is entirely done using Docker. In this way, we can provide you with ready-made applications faster. In addition, their configuration is more flexible and quite controllable. To be able to control this application, however, you need to know some basic Docker functionalities and features.

Restarting all services

Restarting the database and the Docker container that contains Magento itself, along with the rest of the software, can be done in two ways:

  1. By restarting the entire virtual machine
  2. Restarting the Docker containers, which is the faster option. To do this, access your machine via SSH, and run the following commands:
sudo su -
cd /opt/docker-magento
docker compose restart

Recreating Docker containers

Recreation of a docker container may be necessary if you've changed the configuration inside the docker-compose.yml file. If there are changes, please follow these steps:

cd /opt/docker-elasticsearch/
docker compose stop
docker compose up -d

Checking the status of the Docker application

To check, you need to run the following commands:

sudo su -
docker ps -a

Please pay attention to the STATUS column. It should show how long the service has been running, for example Up X minutes. If the status is Restarting then you need to check what is wrong with the application. In such a case, you can check by following the application logs as follows:

  1. Get the application name that you can see in the NAMES column from the output of the docker ps -a command. View the logs with the docker logs <NAME> command, where is the name of the container.

Changing settings

The settings in section Additional Docker settings can be set in the docker-compose.yml file. The path to it is described again in this section. To change a setting, open the configuration file and note the environment section under magento. Each configuration option must be described on a new line with a dash in front, as in the following example:

    environment:
      - АPACHE_HTTP_PORT_NUMBER=8080
      - APACHE_HTTPS_PORT_NUMBER=8443

Please note that the correct indentation (number of spaces) must also be observed, as this is important for yaml configuration files.