Skip to content

Deployment Overview of Magento on Server

Prerequisites and Basic Requirements

The deployment process requires a server running Ubuntu 22.04 (jammy). The system must have root privileges to install packages, configure services, and manage file permissions. The following components are installed and configured as part of the deployment:

  • Operating System: Ubuntu 22.04 (jammy)
  • Web Server: Apache2 with mod_rewrite enabled
  • PHP Version: Configured via the ondrej/php PPA (version defined by php_version variable)
  • Database: MariaDB Server
  • Search Engine: OpenSearch and OpenSearch-Dashboards
  • Message Queue: RabbitMQ (optional, based on configuration)
  • Cache: Redis Server
  • Package Manager: Composer (installed from Ubuntu repository)
  • SSL Management: Certbot with Apache plugin

The server must have network access to download dependencies from Ubuntu repositories, the ondrej/php PPA, OpenSearch artifacts, and the RabbitMQ repositories.

File and Directory Structure

The application and its components are installed in the following locations:

  • Magento Application Root: /var/www/magento (defined by magento_dir)
  • Public Document Root: /var/www/magento/pub
  • Apache Configuration: /etc/apache2/sites-available/ (configured with a dynamic name based on prefix, server_id, and zone)
  • OpenSearch Configuration: /etc/opensearch/opensearch.yml
  • Redis Configuration: /etc/redis/redis.conf
  • Composer Global Configuration: /root/.config/composer/auth.json
  • SSL Certificates: /etc/letsencrypt/live/ (managed by Certbot)

Application Installation Process

The Magento Open Source project is installed using Composer. The process involves setting up the environment, installing dependencies, and running the Magento installation wizard via command line.

  1. Composer Setup: Composer is installed from the Ubuntu repository. Magento access keys are configured globally in the Composer configuration file to allow access to the Magento repository.
  2. Project Creation: The Magento project is created using the composer create-project command targeting magento/project-community-edition.
  3. Magento Installation: The bin/magento setup:install command is executed with the following parameters:
    • Base URL and Secure Base URL
    • Database host, name, user, and password
    • Admin user credentials (firstname, lastname, email, username, password)
    • Language, currency, and timezone settings
    • Search engine configuration pointing to OpenSearch
  4. Post-Installation Steps:
    • Static content is deployed for both frontend and adminhtml areas.
    • Dependency injection is compiled using setup:di:compile.
    • The Magento cron job is installed.
    • Two-factor authentication modules are disabled.
    • Cache is flushed to ensure configuration changes take effect.

Access Rights and Security

Security configurations are applied to the web server, database, and application files.

  • Apache Virtual Host: The Apache configuration enforces HTTPS redirection. Any HTTP request to the server is permanently redirected to HTTPS.
  • SSL Certificates: Let's Encrypt certificates are issued and managed via Certbot. The certificate is automatically renewed if it does not already exist.
  • Database Access: A dedicated database user is created with full privileges (*.*:ALL) for the Magento database.
  • OpenSearch Security: The OpenSearch security plugin is disabled (plugins.security.disabled: true) to allow local connections without authentication for this deployment.
  • Network Binding: OpenSearch is configured to listen only on 127.0.0.1 (localhost) on port 9200.

Databases

The deployment utilizes MariaDB for data storage and OpenSearch for search functionality.

  • MariaDB:
    • Installed via the Ubuntu repository.
    • Service mariadb.service is started and enabled.
    • A database named {{ db_name }} is created.
    • A user {{ db_user }} is created with the specified password and granted all privileges on the database.
  • OpenSearch:
    • Installed via .deb packages downloaded from the official artifacts repository.
    • Configuration file /etc/opensearch/opensearch.yml is modified to:
      • Set cluster.name to opensearch.
      • Set node.name to node-1.
      • Bind network.host to 127.0.0.1.
      • Set http.port to 9200.
      • Disable security plugins.
    • Services opensearch and opensearch-dashboards are started and enabled.

Proxy Servers

Apache2 acts as the web server and reverse proxy for the Magento application.

  • Configuration: A custom VirtualHost configuration is created in /etc/apache2/sites-available/.
  • Document Root: Points to the pub directory of the Magento installation.
  • Rewrite Rules: The mod_rewrite module is enabled to handle URL rewriting required by Magento.
  • SSL Redirection: The configuration includes a rule to redirect all HTTP traffic to HTTPS.
  • Certbot Integration: Certbot is installed with the Apache plugin to automatically obtain and install SSL certificates for the domain.

Permission Settings

File and directory permissions are set to ensure the web server user (www-data) can read and write necessary files.

  • Group Ownership: The entire Magento directory and its subdirectories are assigned to the www-data group.
  • File Permissions:
    • Files in var, generated, vendor, pub/static, pub/media, and app/etc are set to be writable by the group (g+w).
    • Directories in the same paths are set to be writable by the group with the sticky bit (g+ws).
  • Executable Permissions: The bin/magento script is set to be executable by the owner (u+x).

Starting, Stopping, and Updating

The following services are managed via systemd and are configured to start automatically on boot:

  • Apache2: apache2.service
  • MariaDB: mariadb.service
  • OpenSearch: opensearch
  • OpenSearch-Dashboards: opensearch-dashboards
  • Redis: redis.service
  • RabbitMQ: rabbitmq-server (if enabled)

To manage these services, use the following commands:

# Start a service
sudo systemctl start <service_name>

# Stop a service
sudo systemctl stop <service_name>

# Restart a service
sudo systemctl restart <service_name>

# Check service status
sudo systemctl status <service_name>

# Enable service on boot
sudo systemctl enable <service_name>

For Magento-specific operations, the following commands are used from the application directory (/var/www/magento):

# Deploy static content
sudo -u www-data php bin/magento setup:static-content:deploy -f

# Compile dependency injection
sudo -u www-data php bin/magento setup:di:compile

# Flush cache
sudo -u www-data php bin/magento cache:flush

# Install cron jobs
sudo -u www-data php bin/magento cron:install
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×