Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
9fd3d7142d | |||
c185b80b4f | |||
9dcb385cf1 | |||
e6b9d42097 | |||
0be607a1ae | |||
f59517b318 | |||
c8021f204d | |||
125e461786 | |||
6d154446d3 | |||
8684050d1d | |||
fa910780a3 | |||
29d84fe54f | |||
2d544e1411 | |||
95f8846e3d |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
data/
|
16
000-default.conf
Normal file
16
000-default.conf
Normal file
@ -0,0 +1,16 @@
|
||||
# Global log redirection to stdout and stderr
|
||||
ErrorLog "|/usr/bin/tee -a /var/log/apache2/error.log"
|
||||
CustomLog "|/usr/bin/tee -a /var/log/apache2/access.log" combined
|
||||
|
||||
<VirtualHost *:80>
|
||||
DocumentRoot /data/public
|
||||
<Directory /data/public>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
# Remote IP configuration
|
||||
RemoteIPHeader X-Forwarded-For
|
||||
RemoteIPTrustedProxy 127.0.0.1
|
||||
</VirtualHost>
|
183
Dockerfile
183
Dockerfile
@ -1,148 +1,53 @@
|
||||
########################################################################################################################################
|
||||
# Documentation: https://git.nickyeoman.com/4lt/phpcontainer/wiki
|
||||
# v2.0
|
||||
#################################################################################################################################
|
||||
FROM debian:bookworm-20250224
|
||||
|
||||
# Use the PHP base image
|
||||
FROM php:8.2.9-apache
|
||||
WORKDIR /data
|
||||
|
||||
# Set maintainer information
|
||||
LABEL version="2"
|
||||
LABEL maintainer="4 Lights Consulting <info@4lt.ca>"
|
||||
LABEL description="Production-ready PHP Apache container"
|
||||
LABEL org.label-schema.vcs-url="https://git.nickyeoman.com/4lt/phpcontainer"
|
||||
# Install necessary packages and configure PHP repository
|
||||
RUN apt-get update && apt-get install -y \
|
||||
lsb-release ca-certificates curl apt-transport-https logrotate ssl-cert apache2 && \
|
||||
echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
|
||||
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb && \
|
||||
dpkg -i /tmp/debsuryorg-archive-keyring.deb && \
|
||||
sh -c '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 && \
|
||||
apt-get install -y \
|
||||
php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-xml php8.4-mbstring php8.4-curl php8.4-zip php8.4-redis libapache2-mod-php8.4 && \
|
||||
apt-get autoremove -y && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
|
||||
# Set working directory and Apache document root
|
||||
WORKDIR /website
|
||||
ENV APACHE_DOCUMENT_ROOT /website/public/
|
||||
# log management
|
||||
RUN cat <<EOF > /etc/logrotate.d/apache2
|
||||
/var/log/apache2/*.log {
|
||||
weekly
|
||||
missingok
|
||||
rotate 4
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
create 640 root adm
|
||||
}
|
||||
EOF
|
||||
|
||||
# Install required packages
|
||||
RUN set -eux; \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends ghostscript;
|
||||
RUN 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
|
||||
|
||||
# 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
|
||||
RUN mkdir -p /php && echo "PHP_INI_SCAN_DIR=/php" > /etc/environment
|
||||
COPY php.ini /php/php.ini
|
||||
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
|
||||
# Install PHP extensions
|
||||
RUN set -ex; \
|
||||
\
|
||||
savedAptMark="$(apt-mark showmanual)"; \
|
||||
\
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libbz2-dev \
|
||||
libgmp-dev \
|
||||
libicu-dev \
|
||||
libfreetype6-dev \
|
||||
libjpeg-dev \
|
||||
libldap2-dev \
|
||||
libmemcached-dev \
|
||||
libmagickwand-dev \
|
||||
libpq-dev \
|
||||
libpng-dev \
|
||||
libwebp-dev \
|
||||
libzip-dev \
|
||||
; \
|
||||
\
|
||||
docker-php-ext-configure gd \
|
||||
--with-freetype \
|
||||
--with-jpeg \
|
||||
--with-webp \
|
||||
; \
|
||||
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
|
||||
docker-php-ext-configure ldap --with-libdir="lib/$debMultiarch"; \
|
||||
docker-php-ext-configure intl; \
|
||||
docker-php-ext-install -j "$(nproc)" \
|
||||
bz2 \
|
||||
bcmath \
|
||||
exif \
|
||||
gd \
|
||||
gmp \
|
||||
intl \
|
||||
ldap \
|
||||
mysqli \
|
||||
pdo_mysql \
|
||||
pdo_pgsql \
|
||||
pgsql \
|
||||
zip \
|
||||
; \
|
||||
pecl install imagick-3.6.0 && \
|
||||
docker-php-ext-enable imagick && \
|
||||
rm -r /tmp/pear; \
|
||||
\
|
||||
out="$(php -r 'exit(0);')"; \
|
||||
[ -z "$out" ]; \
|
||||
err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
|
||||
[ -z "$err" ]; \
|
||||
\
|
||||
extDir="$(php -r 'echo ini_get("extension_dir");')"; \
|
||||
[ -d "$extDir" ]; \
|
||||
\
|
||||
pecl install APCu-5.1.21 && \
|
||||
pecl install memcached-3.2.0 && \
|
||||
pecl install redis-5.3.7 && \
|
||||
\
|
||||
docker-php-ext-enable \
|
||||
apcu \
|
||||
memcached \
|
||||
redis && \
|
||||
rm -r /tmp/pear; \
|
||||
\
|
||||
apt-mark auto '.*' > /dev/null && \
|
||||
apt-mark manual $savedAptMark && \
|
||||
ldd "$extDir"/*.so | awk '/=>/ { print $3 }' | sort -u | xargs -r dpkg-query -S | cut -d: -f1 | sort -u | xargs -rt apt-mark manual; \
|
||||
\
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
! { ldd "$extDir"/*.so | grep 'not found'; } && \
|
||||
err="$(php --version 3>&1 1>&2 2>&3)"; \
|
||||
[ -z "$err" ]
|
||||
# Security headers for Apache
|
||||
RUN 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-XSS-Protection "1; mode=block"' >> /etc/apache2/conf-available/security.conf && \
|
||||
echo 'Header always set X-Frame-Options "SAMEORIGIN"' >> /etc/apache2/conf-available/security.conf
|
||||
|
||||
# Set recommended PHP.ini settings
|
||||
RUN set -eux; \
|
||||
docker-php-ext-enable opcache; \
|
||||
{ \
|
||||
echo 'opcache.memory_consumption=128'; \
|
||||
echo 'opcache.interned_strings_buffer=8'; \
|
||||
echo 'opcache.max_accelerated_files=4000'; \
|
||||
echo 'opcache.revalidate_freq=2'; \
|
||||
echo 'opcache.fast_shutdown=1'; \
|
||||
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
|
||||
|
||||
# Set recommended error logging
|
||||
RUN { \
|
||||
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
|
||||
echo 'display_errors = Off'; \
|
||||
echo 'display_startup_errors = Off'; \
|
||||
echo 'log_errors = On'; \
|
||||
echo 'error_log = /dev/stderr'; \
|
||||
echo 'log_errors_max_len = 1024'; \
|
||||
echo 'ignore_repeated_errors = On'; \
|
||||
echo 'ignore_repeated_source = Off'; \
|
||||
echo 'html_errors = Off'; \
|
||||
} > /usr/local/etc/php/conf.d/error-logging.ini
|
||||
|
||||
# Enable Apache modules and configure RemoteIP
|
||||
RUN set -eux; \
|
||||
a2enmod expires headers rewrite remoteip socache_shmcb ssl && \
|
||||
{ \
|
||||
echo 'RemoteIPHeader X-Forwarded-For'; \
|
||||
echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \
|
||||
echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \
|
||||
echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \
|
||||
echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \
|
||||
echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \
|
||||
} > /etc/apache2/conf-available/remoteip.conf; \
|
||||
a2enconf remoteip; \
|
||||
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
|
||||
|
||||
# More 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 remoteip socache_shmcb ssl
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["apache2-foreground"]
|
||||
CMD ["apachectl", "-D", "FOREGROUND"]
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
|
||||
CMD curl --silent --fail localhost:80 || exit 1
|
||||
|
44
README.md
44
README.md
@ -1,8 +1,44 @@
|
||||
# 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)
|
||||
|
||||
Dockerhub: https://hub.docker.com/r/4lights/phpcontainer
|
||||
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.
|
||||
|
||||
## Features
|
||||
|
||||
- **PHP Version**: 8.4.5
|
||||
- **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
|
||||
```
|
||||
## How to update image on dockerhub
|
||||
|
||||
```bash
|
||||
sudo su
|
||||
docker buildx build --no-cache -t 4lights/corxn:6.0.0 -t 4lights/corxn:latest --load .
|
||||
docker login
|
||||
docker push 4lights/corxn:6.0.0
|
||||
docker push 4lights/corxn:latest
|
||||
```
|
||||
|
||||
# References And Notes
|
||||
|
||||
Test using test.php
|
||||
|
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:6.0.0
|
||||
ports:
|
||||
- "8000:80"
|
||||
volumes:
|
||||
- ./:/data # looks for /data/public
|
||||
- ./php.ini:/php/php.ini # Optional override php.ini
|
||||
- ./data/logs:/var/log/apache2 # Optional Logs
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- proxy
|
||||
- internal
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
networks:
|
||||
- internal
|
||||
restart: unless-stopped
|
||||
|
||||
mariadb:
|
||||
image: mariadb:latest
|
||||
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
|
55
php.ini
Normal file
55
php.ini
Normal file
@ -0,0 +1,55 @@
|
||||
[PHP]
|
||||
; Basic PHP settings
|
||||
max_execution_time = 30
|
||||
memory_limit = 500M
|
||||
upload_max_filesize = 100M
|
||||
post_max_size = 100M
|
||||
max_input_time = 60
|
||||
date.timezone = America/Vancouver
|
||||
|
||||
; Error handling
|
||||
display_errors = On
|
||||
display_startup_errors = On
|
||||
log_errors = On
|
||||
error_log = /var/log/php_errors.log
|
||||
|
||||
; Session settings
|
||||
session.save_path = "/var/lib/php/sessions"
|
||||
session.gc_maxlifetime = 1440
|
||||
session.cookie_lifetime = 0
|
||||
session.use_strict_mode = 1
|
||||
|
||||
; Realpath cache
|
||||
realpath_cache_size = 4096k
|
||||
realpath_cache_ttl = 120
|
||||
|
||||
; File upload settings
|
||||
file_uploads = On
|
||||
allow_url_fopen = On
|
||||
|
||||
; Redis settings (ensure Redis extension is loaded)
|
||||
extension=redis.so
|
||||
|
||||
; mbstring settings (useful for multi-byte encoding handling)
|
||||
mbstring.language = Japanese
|
||||
mbstring.internal_encoding = UTF-8
|
||||
mbstring.http_input = auto
|
||||
mbstring.http_output = UTF-8
|
||||
mbstring.detect_order = auto
|
||||
mbstring.substitute_character = none
|
||||
|
||||
; cURL settings
|
||||
curl.cainfo = "/etc/ssl/certs/ca-certificates.crt"
|
||||
|
||||
; SMTP settings (for sending mail, if needed)
|
||||
SMTP = localhost
|
||||
sendmail_path = /usr/sbin/sendmail -t -i
|
||||
|
||||
; Extension loading
|
||||
extension=curl
|
||||
extension=mbstring
|
||||
extension=redis
|
||||
extension=xml
|
||||
extension=mysqli
|
||||
extension=pdo_mysql
|
||||
extension=zip
|
155
public/test.php
Normal file
155
public/test.php
Normal file
@ -0,0 +1,155 @@
|
||||
<!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/phpcontainer">Four Lights PHP Container</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 = '/data/public/uploads/';
|
||||
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
|
||||
$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>
|
Loading…
x
Reference in New Issue
Block a user