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_rewriteenabled - PHP Version: Configured via the
ondrej/phpPPA (version defined byphp_versionvariable) - 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 bymagento_dir) - Public Document Root:
/var/www/magento/pub - Apache Configuration:
/etc/apache2/sites-available/(configured with a dynamic name based onprefix,server_id, andzone) - 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.
- 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.
- Project Creation: The Magento project is created using the
composer create-projectcommand targetingmagento/project-community-edition. - Magento Installation: The
bin/magento setup:installcommand 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
- 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 port9200.
Databases¶
The deployment utilizes MariaDB for data storage and OpenSearch for search functionality.
- MariaDB:
- Installed via the Ubuntu repository.
- Service
mariadb.serviceis 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
.debpackages downloaded from the official artifacts repository. - Configuration file
/etc/opensearch/opensearch.ymlis modified to:- Set
cluster.nametoopensearch. - Set
node.nametonode-1. - Bind
network.hostto127.0.0.1. - Set
http.portto9200. - Disable security plugins.
- Set
- Services
opensearchandopensearch-dashboardsare started and enabled.
- Installed via
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
pubdirectory of the Magento installation. - Rewrite Rules: The
mod_rewritemodule 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-datagroup. - File Permissions:
- Files in
var,generated,vendor,pub/static,pub/media, andapp/etcare 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).
- Files in
- Executable Permissions: The
bin/magentoscript 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):