Deployment Overview of LAMP on Server¶
Prerequisites and Basic Requirements¶
To ensure a successful deployment, the following requirements must be met:
-
Operating System: Ubuntu or Debian.
-
Privileges: Root or sudo access is required for package installation and service configuration.
-
Ports:
-
443/tcp: External HTTPS traffic (handled by the Nginx proxy). -
8080/tcp: Internal Apache traffic (redirected from port 80 to avoid conflicts with Certbot).
FQDN of the final panel on the hostkey.in domain¶
The application is accessible via a specific subdomain template based on the server ID.
| Parameter | Value |
|---|---|
| Prefix | lamp |
| Domain | hostkey.in |
| Full template | lamp{Server_ID_from_Invapi}.hostkey.in |
File and Directory Structure¶
The deployment utilizes the following directory structure for configuration and data management:
-
/etc/apache2/: Apache web server configuration files. -
/data/nginx/user_conf.d/: Nginx proxy configuration files (includes SSL headers). -
/root/nginx/: Contains the Docker Compose file for the Nginx-Certbot container. -
/var/www/html/: Default web root directory whereinfo.phpis created for testing.
Application installation process¶
The installation follows a multi-step process involving package management and container orchestration:
-
System Preparation: The system updates the package cache and removes any conflicting legacy Docker repository files to prevent dependency errors.
-
Web Server Installation: Apache2 is installed via the
aptpackage manager. -
Database Installation: MariaDB server and client are installed from the official MariaDB repositories.
-
PHP Installation:
-
On Ubuntu: PHP version
8.3is installed using theppa:ondrej/phprepository, including modules for MySQL, Curl, and CGI. -
On Debian: Standard PHP packages are installed via the default repositories.
-
Apache Reconfiguration: Apache is configured to listen on internal port
8080instead of the standard port 80 to allow the Docker container to handle SSL termination on port 443. -
Proxy Configuration: A reverse proxy configuration is generated for Nginx to forward traffic to Apache, ensuring proper
HostandX-Forwarded-Protoheaders are passed.
Access Rights and Security¶
-
Firewall: The system is configured to allow HTTPS traffic on port 443 via the Nginx container.
-
User Permissions: Configuration files in
/data/nginx/user_conf.d/are managed with specific permissions to ensure secure proxying. -
Service Isolation: Apache is bound to
127.0.0.1:8080, preventing direct external access and forcing all traffic through the SSL-enabled Nginx proxy.
Databases¶
The application uses MariaDB as its database engine.
-
Connection Method: Localhost connection via socket or TCP/IP.
-
Storage Location: Managed by the system's default MariaDB data directory (typically
/var/lib/mysql). -
Version: 10.11.x.
Docker Containers and Their Deployment¶
The deployment utilizes a single container to manage SSL certificates and reverse proxying:
Nginx-Certbot Container
-
Image:
jonasal/nginx-certbot:latest -
Ports: Uses
hostnetwork mode (binds directly to host ports). -
Volumes:
-
nginx_secrets:/etc/letsencrypt: Shared volume for SSL certificates. -
/data/nginx/user_conf.d:/etc/nginx/user_conf.d: Maps custom proxy configurations into the container. -
Environment Variables:
-
CERTBOT_EMAIL: Configured via an external environment file (/data/nginx/nginx-certbot.env). -
Restart Policy:
unless-stopped
Custom Scripts and Additional Setup¶
The deployment performs several automated configuration steps:
-
Apache Internal Binding: A script modifies
/etc/apache2/ports.confand the default VirtualHost to listen on port8080. -
Header Injection: The installation automatically injects
proxy_set_header Host $host;andproxy_set_header X-Forwarded-Proto $scheme;into the Nginx configuration files to ensure PHP applications correctly detect HTTPS. -
Test File Creation: An
info.phpfile is created in/var/www/html/to verify that the PHP engine is functioning correctly after installation.
Application Update Instructions¶
To update the main application components:
-
Nginx Proxy (Docker): Navigate to
/root/nginxand execute: -
System Packages: To update Apache, MariaDB, or PHP, use the standard package manager:
Location of configuration files and data¶
| Component | Path |
|---|---|
| Nginx Compose File | /root/nginx/compose.yml |
| Nginx Proxy Configs | /data/nginx/user_conf.d/ |
| Apache Configuration | /etc/apache2/ |
| MariaDB Data | /var/lib/mysql |
Available ports for connection¶
-
HTTPS (External):
443 -
HTTP (Internal/Apache):
8080
Starting and Stopping the application¶
The application consists of system services and a Docker container.
Managing Apache & MariaDB:
-
Start Apache:
systemctl start apache2 -
Stop Apache:
systemctl stop apache2 -
Start MariaDB:
systemctl start mariadb -
Stop MariaDB:
systemctl stop mariadb
Managing the Nginx Proxy (Docker):
-
Navigate to
/root/nginx. -
Start:
docker compose up -d -
Stop:
docker compose down