Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 546c49767f | |||
| a5deb07a66 | |||
| 9fd3d7142d | |||
| c185b80b4f | |||
| 9dcb385cf1 | |||
| e6b9d42097 | |||
| 0be607a1ae | |||
| f59517b318 | |||
| c8021f204d | |||
| 125e461786 | |||
| 6d154446d3 | |||
| 8684050d1d | |||
| fa910780a3 | |||
| 29d84fe54f | |||
| 2d544e1411 | |||
| 95f8846e3d | |||
| 30487a87e9 | |||
| 2d4afd080e | |||
| 35a35196e5 | |||
| 1db0abeb49 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
data/
|
||||
22
000-default.conf
Normal file
22
000-default.conf
Normal file
@@ -0,0 +1,22 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost
|
||||
|
||||
DocumentRoot /data/public
|
||||
|
||||
<Directory /data/public>
|
||||
Options FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
DirectoryIndex index.php index.html
|
||||
|
||||
# PHP-FPM handler
|
||||
<FilesMatch \.php$>
|
||||
SetHandler "proxy:unix:/run/php/php8.5-fpm.sock|fcgi://localhost/"
|
||||
</FilesMatch>
|
||||
|
||||
# Docker-friendly logging
|
||||
ErrorLog /proc/self/fd/2
|
||||
CustomLog /proc/self/fd/1 combined
|
||||
</VirtualHost>
|
||||
149
Dockerfile
149
Dockerfile
@@ -1,45 +1,120 @@
|
||||
########################################################################################################################################
|
||||
# Documentation: https://git.nickyeoman.com/4lt/phpcontainer/wiki
|
||||
########################################################################################################################################
|
||||
FROM php:8.2.9-apache
|
||||
LABEL maintainer="4 Lights Consulting <info@4lt.ca>"
|
||||
LABEL description="Production-ready PHP Apache container"
|
||||
LABEL version="1"
|
||||
LABEL org.label-schema.vcs-url="https://git.nickyeoman.com/4lt/phpcontainer"
|
||||
FROM debian:trixie-20260316
|
||||
|
||||
# Setup
|
||||
WORKDIR /website
|
||||
ENV APACHE_DOCUMENT_ROOT /website/public/
|
||||
WORKDIR /data
|
||||
|
||||
# APT
|
||||
RUN apt-get update
|
||||
# Install base packages + Apache + PHP repo
|
||||
RUN apt-get update && apt-get install -y \
|
||||
lsb-release \
|
||||
ca-certificates \
|
||||
curl \
|
||||
logrotate \
|
||||
ssl-cert \
|
||||
apache2 \
|
||||
&& echo "ServerName localhost" >> /etc/apache2/apache2.conf \
|
||||
\
|
||||
# Add Sury PHP repo
|
||||
&& curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb \
|
||||
&& dpkg -i /tmp/debsuryorg-archive-keyring.deb \
|
||||
&& echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
|
||||
\
|
||||
&& apt-get update \
|
||||
\
|
||||
# Install PHP 8.5 + extensions
|
||||
&& apt-get install -y \
|
||||
php8.5 \
|
||||
php8.5-cli \
|
||||
php8.5-fpm \
|
||||
php8.5-mysql \
|
||||
php8.5-xml \
|
||||
php8.5-mbstring \
|
||||
php8.5-curl \
|
||||
php8.5-zip \
|
||||
php8.5-redis \
|
||||
\
|
||||
# Cleanup
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
|
||||
# IMAP
|
||||
RUN apt-get install -y libc-client-dev libkrb5-dev libssl-dev;
|
||||
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl
|
||||
RUN docker-php-ext-install imap
|
||||
# Apache + PHP-FPM configuration + performance tuning
|
||||
RUN \
|
||||
# Enable modules
|
||||
a2enmod proxy_fcgi setenvif expires headers rewrite remoteip socache_shmcb ssl deflate \
|
||||
\
|
||||
# Switch to MPM event
|
||||
&& a2dismod mpm_prefork \
|
||||
&& a2enmod mpm_event \
|
||||
\
|
||||
# Enable PHP-FPM
|
||||
&& a2enconf php8.5-fpm \
|
||||
\
|
||||
# Remote IP config
|
||||
&& echo 'RemoteIPHeader X-Forwarded-For' > /etc/apache2/conf-available/remoteip.conf \
|
||||
&& echo 'RemoteIPTrustedProxy 127.0.0.1' >> /etc/apache2/conf-available/remoteip.conf \
|
||||
&& a2enconf remoteip \
|
||||
&& sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' /etc/apache2/*.conf \
|
||||
\
|
||||
# Security headers
|
||||
&& echo 'Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"' >> /etc/apache2/conf-available/security.conf \
|
||||
&& echo 'Header always set X-Content-Type-Options "nosniff"' >> /etc/apache2/conf-available/security.conf \
|
||||
&& echo 'Header always set X-Frame-Options "SAMEORIGIN"' >> /etc/apache2/conf-available/security.conf \
|
||||
\
|
||||
# Compression
|
||||
&& echo 'AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json' > /etc/apache2/conf-available/compression.conf \
|
||||
&& a2enconf compression \
|
||||
\
|
||||
# KeepAlive tuning
|
||||
&& cat <<EOF > /etc/apache2/conf-available/keepalive.conf
|
||||
KeepAlive On
|
||||
MaxKeepAliveRequests 100
|
||||
KeepAliveTimeout 2
|
||||
EOF \
|
||||
&& a2enconf keepalive \
|
||||
\
|
||||
# MPM Event tuning
|
||||
&& cat <<EOF > /etc/apache2/conf-available/mpm-event-tuning.conf
|
||||
<IfModule mpm_event_module>
|
||||
StartServers 2
|
||||
MinSpareThreads 25
|
||||
MaxSpareThreads 75
|
||||
ThreadLimit 64
|
||||
ThreadsPerChild 25
|
||||
MaxRequestWorkers 150
|
||||
MaxConnectionsPerChild 1000
|
||||
</IfModule>
|
||||
EOF \
|
||||
&& a2enconf mpm-event-tuning \
|
||||
\
|
||||
# Logrotate
|
||||
&& cat <<EOF > /etc/logrotate.d/apache2
|
||||
/var/log/apache2/*.log {
|
||||
weekly
|
||||
missingok
|
||||
rotate 4
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
create 640 root adm
|
||||
}
|
||||
EOF
|
||||
|
||||
# Symfony
|
||||
RUN apt-get install -y libicu-dev
|
||||
RUN docker-php-ext-configure intl
|
||||
RUN docker-php-ext-install intl
|
||||
# PHP-FPM tuning
|
||||
RUN sed -i 's/^pm = .*/pm = dynamic/' /etc/php/8.5/fpm/pool.d/www.conf && \
|
||||
sed -i 's/^pm.max_children = .*/pm.max_children = 20/' /etc/php/8.5/fpm/pool.d/www.conf && \
|
||||
sed -i 's/^pm.start_servers = .*/pm.start_servers = 2/' /etc/php/8.5/fpm/pool.d/www.conf && \
|
||||
sed -i 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 2/' /etc/php/8.5/fpm/pool.d/www.conf && \
|
||||
sed -i 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 5/' /etc/php/8.5/fpm/pool.d/www.conf
|
||||
|
||||
# Cleanup
|
||||
RUN rm -r /var/lib/apt/lists/*
|
||||
# PHP custom config
|
||||
RUN mkdir -p /php && echo "PHP_INI_SCAN_DIR=/php" > /etc/environment
|
||||
|
||||
# Apache settings
|
||||
|
||||
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
|
||||
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
|
||||
|
||||
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
|
||||
|
||||
RUN a2enmod expires headers rewrite socache_shmcb ssl
|
||||
|
||||
RUN docker-php-ext-install mysqli pdo pdo_mysql
|
||||
RUN docker-php-ext-install opcache
|
||||
|
||||
# Docker config
|
||||
COPY php.ini /php/php.ini
|
||||
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["apache2-foreground"]
|
||||
|
||||
# Startup
|
||||
COPY start.sh /start.sh
|
||||
RUN chmod +x /start.sh
|
||||
|
||||
CMD ["/start.sh"]
|
||||
59
README.md
59
README.md
@@ -1,16 +1,53 @@
|
||||
# 4 Lights Consulting
|
||||

|
||||
|
||||
The apache php docker container that we use for production.
|
||||
# CORXN - The Core Foundation of Novaconium
|
||||
|
||||
User Documentation: https://git.nickyeoman.com/4lt/phpcontainer/wiki
|
||||
Links: [Dockerhub](https://hub.docker.com/r/4lights/corxn), [Git Repo](https://git.4lt.ca/4lt/CORXN)
|
||||
|
||||
## Development Documentation
|
||||
CORXN (core-ex-en) is a lightweight yet powerful Docker-based environment designed as the core foundation for the [Novaconium PHP Framework](https://git.4lt.ca/4lt/novaconium).
|
||||
It provides a streamlined stack featuring Apache, the latest PHP version, Redis, and MariaDB, optimized for high performance.
|
||||
|
||||
You might have to login with your api key.
|
||||
## Features
|
||||
|
||||
- **PHP Version**: 8.5.3
|
||||
- **Apache Web Server**: Configured to run PHP applications
|
||||
- **Support for**:
|
||||
- `remoteip` (reverse proxy)
|
||||
- `redis`
|
||||
- `mariadb`
|
||||
- **Timezone**: Default set to Vancouver (`America/Vancouver`)
|
||||
|
||||
## Getting Started
|
||||
|
||||
Follow these steps to set up the PHP container on your local environment.
|
||||
|
||||
### Usage
|
||||
|
||||
#### Clone the Repository
|
||||
|
||||
```bash
|
||||
git clone https://git.4lt.ca/4lt/corxn.git
|
||||
cd corxn
|
||||
```
|
||||
sudo docker build -t phpcontainer:1 .
|
||||
sudo docker tag phpcontainer:1 4lights/phpcontainer:v1
|
||||
sudo docker tag phpcontainer:1 4lights/phpcontainer:latest
|
||||
sudo docker push 4lights/phpcontainer:v1
|
||||
sudo docker push 4lights/phpcontainer:latest
|
||||
```
|
||||
## How to update image on dockerhub
|
||||
|
||||
```bash
|
||||
sudo su
|
||||
docker buildx build --no-cache -t 4lights/corxn:8.5.3 -t 4lights/corxn:latest --load .
|
||||
docker login -u <username>
|
||||
docker push 4lights/corxn:8.5.3
|
||||
docker push 4lights/corxn:latest
|
||||
```
|
||||
# Testing
|
||||
|
||||
Here is how to text the build:
|
||||
```bash
|
||||
mkdir -p data/uploads && sudo chown -R 33:33 data/uploads && chmod 775 data/uploads
|
||||
docker compose up -d
|
||||
# Visit: http://localhost:8000/test.php
|
||||
# Test: file upload and that green checkmarks exist
|
||||
```
|
||||
|
||||
# Logs
|
||||
|
||||
```docker logs corxn```
|
||||
|
||||
BIN
_assets/corxn-logo.png
Normal file
BIN
_assets/corxn-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
39
docker-compose.yml
Normal file
39
docker-compose.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
# Sample Docker Compose
|
||||
services:
|
||||
corxn:
|
||||
image: 4lights/corxn:latest
|
||||
ports:
|
||||
- "8000:80"
|
||||
volumes:
|
||||
- ./test:/data # looks for /data/public
|
||||
- ./php.ini:/php/php.ini:ro # Optional override php.ini
|
||||
- ./data/uploads:/data/public/uploads
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- proxy
|
||||
- internal
|
||||
|
||||
redis:
|
||||
image: redis:7
|
||||
networks:
|
||||
- internal
|
||||
restart: unless-stopped
|
||||
|
||||
mariadb:
|
||||
image: mariadb:11
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=rootpassword
|
||||
- MYSQL_DATABASE=dbname
|
||||
- MYSQL_USER=user
|
||||
- MYSQL_PASSWORD=password
|
||||
volumes:
|
||||
- ./data/db:/var/lib/mysql
|
||||
networks:
|
||||
- internal
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
internal:
|
||||
driver: bridge
|
||||
5
docs/phpmyadmin.md
Normal file
5
docs/phpmyadmin.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# PHPMYADMIN
|
||||
|
||||
You may want to use PHPmyAdmin for testing.
|
||||
|
||||
Checkout [Docker Cookbooks](https://github.com/nickyeoman/docker-compose-cookbooks/blob/master/phpmyadmin/docker-compose.yml) for an example.
|
||||
53
php.ini
Normal file
53
php.ini
Normal file
@@ -0,0 +1,53 @@
|
||||
[PHP]
|
||||
; Performance
|
||||
max_execution_time = 30
|
||||
max_input_time = 60
|
||||
memory_limit = 512M
|
||||
|
||||
; Uploads
|
||||
upload_max_filesize = 100M
|
||||
post_max_size = 100M
|
||||
|
||||
; Timezone
|
||||
date.timezone = America/Vancouver
|
||||
|
||||
; Errors (production-safe)
|
||||
display_errors = Off
|
||||
display_startup_errors = Off
|
||||
log_errors = On
|
||||
error_log = /proc/self/fd/2
|
||||
|
||||
; Sessions
|
||||
session.save_path = "/var/lib/php/sessions"
|
||||
session.gc_maxlifetime = 1440
|
||||
session.cookie_lifetime = 0
|
||||
session.use_strict_mode = 1
|
||||
|
||||
; File handling
|
||||
file_uploads = On
|
||||
allow_url_fopen = On
|
||||
|
||||
; Realpath cache
|
||||
realpath_cache_size = 4096k
|
||||
realpath_cache_ttl = 120
|
||||
|
||||
; cURL
|
||||
curl.cainfo = "/etc/ssl/certs/ca-certificates.crt"
|
||||
|
||||
; Mail (optional)
|
||||
SMTP = localhost
|
||||
sendmail_path = /usr/sbin/sendmail -t -i
|
||||
|
||||
; OPcache (IMPORTANT)
|
||||
opcache.enable=1
|
||||
opcache.enable_cli=1
|
||||
opcache.memory_consumption=192
|
||||
opcache.interned_strings_buffer=16
|
||||
opcache.max_accelerated_files=20000
|
||||
opcache.validate_timestamps=0
|
||||
opcache.revalidate_freq=0
|
||||
opcache.fast_shutdown=1
|
||||
|
||||
; Redis
|
||||
session.save_handler = redis
|
||||
session.save_path = "tcp://redis:6379"
|
||||
6
start.sh
Normal file
6
start.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
service php8.5-fpm start
|
||||
|
||||
exec apachectl -D FOREGROUND
|
||||
151
test/public/test.php
Normal file
151
test/public/test.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Server Test - Debian PHP Apache</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
h2 {
|
||||
color: #0056b3;
|
||||
border-bottom: 2px solid #0056b3;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
p {
|
||||
background: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0px 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: auto;
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
th, td {
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background: #0056b3;
|
||||
color: white;
|
||||
}
|
||||
.upload-section {
|
||||
background: #e3f2fd;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.upload-section input[type="file"] {
|
||||
padding: 5px;
|
||||
}
|
||||
.upload-section input[type="submit"] {
|
||||
background: #0056b3;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.upload-section input[type="submit"]:hover {
|
||||
background: #003d80;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>PHP Container Test Script</h1>
|
||||
<p><a href="https://git.4lt.ca/4lt/CORXN">Four Lights PHP Container: CORXN</a></p>
|
||||
|
||||
|
||||
<h2>Server Information</h2>
|
||||
<table>
|
||||
<tr><th>PHP Version</th><td><?php echo phpversion(); ?></td></tr>
|
||||
<tr><th>Current Date/Time (Vancouver)</th><td><?php date_default_timezone_set('America/Vancouver'); echo date('Y-m-d H:i:s'); ?></td></tr>
|
||||
<tr><th>upload_max_filesize</th><td><?php echo ini_get('upload_max_filesize'); ?></td></tr>
|
||||
<tr><th>post_max_size</th><td><?php echo ini_get('post_max_size'); ?></td></tr>
|
||||
<tr><th>php.ini</th><td><?php echo php_ini_loaded_file(); ?></td></tr>
|
||||
</table>
|
||||
|
||||
<h2>Redis Test</h2>
|
||||
<?php
|
||||
$redis = new Redis();
|
||||
try {
|
||||
$redis->connect('redis', 6379);
|
||||
echo "<p>✅ Redis connected</p>";
|
||||
$redis->set("test_key", "There are FOUR Lights!");
|
||||
echo "<p>Redis test_key: " . $redis->get("test_key") . "</p>";
|
||||
} catch (Exception $e) {
|
||||
echo "<p>❌ Redis connection failed: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>MariaDB Test</h2>
|
||||
<?php
|
||||
$mysqli = new mysqli('mariadb', 'user', 'password', 'dbname');
|
||||
if ($mysqli->connect_error) {
|
||||
echo "<p>❌ MariaDB connection failed: " . $mysqli->connect_error . "</p>";
|
||||
} else {
|
||||
echo "<p>✅ MariaDB connected</p>";
|
||||
$result = $mysqli->query('SELECT NOW()');
|
||||
$row = $result->fetch_row();
|
||||
echo "<p>Current time in MariaDB: " . $row[0] . "</p>";
|
||||
$mysqli->close();
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>RemoteIP Test</h2>
|
||||
<p>Your IP address (from Apache's remoteip module): <?php echo $_SERVER['REMOTE_ADDR']; ?></p>
|
||||
|
||||
|
||||
|
||||
<h2>File Upload Test</h2>
|
||||
<div class="upload-section">
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="testfile">
|
||||
<input type="submit" name="upload" value="Upload">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['testfile'])) {
|
||||
if ($_FILES['testfile']['error'] === UPLOAD_ERR_OK) {
|
||||
$uploadDir = __DIR__ . '/uploads/';
|
||||
|
||||
$destination = $uploadDir . basename($_FILES['testfile']['name']);
|
||||
|
||||
if (move_uploaded_file($_FILES['testfile']['tmp_name'], $destination)) {
|
||||
echo "<p>✅ File uploaded successfully to: <strong>" . htmlspecialchars($destination) . "</strong></p>";
|
||||
echo "<p>Size: " . $_FILES['testfile']['size'] . " bytes</p>";
|
||||
} else {
|
||||
echo "<p>❌ Error moving file.</p>";
|
||||
}
|
||||
} else {
|
||||
echo "<p>❌ Error uploading file. Error Code: " . $_FILES['testfile']['error'] . "</p>";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user