Deployment Overview of Magento on Server¶
Prerequisites and Basic Requirements¶
The deployment environment requires the following specifications to ensure compatibility and stability:
-
Operating System: Ubuntu 22.04 (Jammy Jellyfish).
-
Privileges: Root access or
sudoprivileges are required to install system packages and configure services. -
Timezone: The system timezone is configured to
UTC. -
Network: The server must have outbound internet access to download dependencies, Composer packages, and SSL certificates.
-
Ports: Ports 80 and 443 must be open for web traffic. Internal services utilize specific ports detailed in the "Available Ports" section.
FQDN of the Final Panel¶
The application is accessible via the following Fully Qualified Domain Name (FQDN) format on the hostkey.in domain:
-
Format:
magento<Server ID>.hostkey.in -
Protocol: HTTPS is enforced for all connections.
-
Example: If the Server ID is
123, the address ismagento123.hostkey.in.
File and Directory Structure¶
The application and its supporting services are organized in the following directory structure:
-
Application Root:
/var/www/magento -
Public Document Root:
/var/www/magento/pub -
Apache Configuration:
/etc/apache2/sites-available/magento<Server ID>.hostkey.in.conf -
OpenSearch Configuration:
/etc/opensearch/opensearch.yml -
Redis Configuration:
/etc/redis/redis.conf -
SSL Certificates:
/etc/letsencrypt/live/magento<Server ID>.hostkey.in/ -
Composer Global Config:
/root/.config/composer/auth.json
Application Installation Process¶
The Magento Open Source application is installed using Composer and the native setup script. The following versions are deployed:
-
PHP Version: 8.3
-
Magento Edition: Community Edition (Project Community Edition)
-
Search Engine: OpenSearch (Version 2.12.0)
-
Database: MariaDB (Version 10.6)
The installation process involves the following steps:
-
Dependency Installation: System packages including PHP 8.3 with extensions (bcmath, xml, curl, gd, intl, dom, mysql, soap, zip, mbstring), Composer, MariaDB, OpenSearch, OpenSearch-Dashboards, and Redis are installed via
apt. -
Composer Configuration: Magento access keys are configured globally for Composer to allow downloading from the Magento repository.
-
Project Creation: The Magento project is created in
/var/www/magentousing the commandcomposer create-project. -
Setup Execution: The
bin/magento setup:installcommand is executed with the following parameters:-
Base URL:
https://magento<Server ID>.hostkey.in/ -
Database Host:
localhost -
Database Name:
magento -
Search Engine:
opensearch -
Admin User:
root -
Language:
en_US -
Currency:
USD
-
-
Post-Installation:
-
Static content is deployed for both frontend and adminhtml areas.
-
Dependency injection is compiled (
setup:di:compile). -
The cron job is installed via
bin/magento cron:install. -
Two-factor authentication modules are disabled.
-
HTTPS is forced in the store configuration.
-
Access Rights and Security¶
Security measures are implemented at the system and application levels:
-
SSL/TLS: Let's Encrypt certificates are issued and managed via Certbot. Apache is configured to redirect all HTTP traffic (Port 80) to HTTPS (Port 443).
-
Firewall: The Apache configuration restricts access to the document root and enables URL rewriting.
-
User Permissions:
-
The web server user is
www-data. -
The Magento directory and all subdirectories are owned by
www-data. -
Two-factor authentication modules (
Magento_AdminAdobeImsTwoFactorAuthandMagento_TwoFactorAuth) are disabled.
-
-
Composer Security: After installation, the temporary Magento repository credentials stored in
/root/.config/composer/auth.jsonare cleared.
Databases¶
The application utilizes two primary database services:
-
MariaDB:
-
Service:
mariadb.service -
Host:
localhost -
Database Name:
magento -
User:
magento -
Storage: Local disk storage managed by the MariaDB service.
-
-
OpenSearch:
-
Service:
opensearch.service -
Host:
localhost -
Port:
9200 -
Index Prefix:
magento2 -
Timeout:
5seconds -
Configuration: Security plugins are disabled (
plugins.security.disabled: true) to allow local connection without authentication for this deployment.
-
Proxy Servers¶
Apache2 serves as the web server and reverse proxy for the application:
-
Server Software: Apache2
-
Virtual Host: Configured in
/etc/apache2/sites-available/magento<Server ID>.hostkey.in.conf. -
Document Root: Points to
/var/www/magento/pub. -
Modules: The
rewritemodule is enabled to handle Magento URL rewrites. -
SSL Termination: Apache handles SSL termination using certificates provided by Certbot.
-
Redirects: All traffic on port 80 is permanently redirected to HTTPS.
Permission Settings¶
File and directory permissions are set to ensure the web server can read and write necessary files while maintaining security:
-
Ownership: The entire
/var/www/magentodirectory tree is owned by thewww-datagroup. -
File Permissions: Files within
var,generated,vendor,pub/static,pub/media, andapp/etcare set to be writable by the group (g+w). -
Directory Permissions: Directories within the same paths are set to be writable by the group with the sticky bit (
g+ws). -
Executable: The
bin/magentoscript is set to be executable by the user (u+x).
Location of Configuration Files and Data¶
Key configuration files and data locations are as follows:
| Component | File Path | Description |
|---|---|---|
| Apache Site Config | /etc/apache2/sites-available/magento<Server ID>.hostkey.in.conf | Virtual host configuration for the application. |
| OpenSearch Config | /etc/opensearch/opensearch.yml | OpenSearch cluster and network settings. |
| Redis Config | /etc/redis/redis.conf | Redis server configuration. |
| Magento Config | /var/www/magento/app/etc/config.php | Magento application configuration (generated during install). |
| Composer Auth | /root/.config/composer/auth.json | Composer authentication (cleared after install). |
| SSL Certs | /etc/letsencrypt/live/magento<Server ID>.hostkey.in/ | Let's Encrypt certificate files. |
| Application Data | /var/www/magento | Root directory containing all application code and data. |
Available Ports for Connection¶
The following ports are utilized by the deployed services:
-
80: HTTP (Redirects to HTTPS).
-
443: HTTPS (Web application access).
-
9200: OpenSearch HTTP API (Localhost only).
-
6379: Redis (Localhost only).
-
3306: MariaDB (Localhost only).
Starting, Stopping, and Updating¶
Services are managed using systemd. The following commands are used to control the application and its dependencies:
-
Apache2:
-
Start:
systemctl start apache2 -
Stop:
systemctl stop apache2 -
Reload:
systemctl reload apache2 -
Enable:
systemctl enable apache2
-
-
MariaDB:
-
Start:
systemctl start mariadb -
Stop:
systemctl stop mariadb -
Enable:
systemctl enable mariadb
-
-
OpenSearch:
-
Start:
systemctl start opensearch -
Stop:
systemctl stop opensearch -
Enable:
systemctl enable opensearch
-
-
OpenSearch-Dashboards:
-
Start:
systemctl start opensearch-dashboards -
Stop:
systemctl stop opensearch-dashboards -
Enable:
systemctl enable opensearch-dashboards
-
-
Redis:
-
Start:
systemctl start redis -
Stop:
systemctl stop redis -
Restart:
systemctl restart redis -
Enable:
systemctl enable redis
-
To update the Magento application code or static content, the following commands are executed from the /var/www/magento directory:
-
Deploy Static Content:
php bin/magento setup:static-content:deploy -f -
Compile Dependencies:
php bin/magento setup:di:compile -
Flush Cache:
php bin/magento cache:flush -
Install Cron:
bin/magento cron:install