Requirements:
- Download Docker from Docker Desktop.
1. Modify config.php
Code: Select all
$dbServer = 'localhost';
$dbUsername = 'root';
$dbPassword = 'root';
$dbDatabase = 'mydatabase';
Code: Select all
version: '3.8'
services:
app:
build: .
ports:
- "81:80"
volumes:
- .:/var/www/html
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=mydatabase
Code: Select all
FROM php:7.4-apache
# Install system dependencies
RUN apt-get update && apt-get install -y default-mysql-server
# Install PHP extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql
# Set the default MySQL socket for PHP
RUN echo "mysqli.default_socket=/var/run/mysqld/mysqld.sock" > /usr/local/etc/php/conf.d/mysql_socket.ini
# Copy your PHP application to the container
COPY . /var/www/html/
RUN chown -R www-data:www-data /var/www/html && \
find /var/www/html/ -type d -exec chmod 755 {} \; && \
find /var/www/html/ -type f -exec chmod 644 {} \;
# Copy the SQL dump file to the container
COPY mydatabase.sql /mydatabase.sql
# Copy custom MySQL configuration file
COPY my_custom.cnf /etc/mysql/conf.d/my_custom.cnf
# Copy the entrypoint script to the container
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Expose port 80 to the outside world
EXPOSE 80
# Set the working directory to the root of apache
WORKDIR /var/www/html
# Start Apache and MySQL services
ENTRYPOINT ["/entrypoint.sh"]
Code: Select all
[mysqld]
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
datadir=/var/lib/mysql
# Custom settings to allow larger row sizes
innodb_strict_mode = 0
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix = 1
Code: Select all
#!/bin/bash
set -e
# Fix ownership and permissions of the MySQL data directory
chown -R mysql:mysql /var/lib/mysql
chmod 755 /var/lib/mysql
# Start MySQL in the background
mysqld_safe --skip-networking &
# Wait for MySQL to start
while ! mysqladmin ping --silent; do
sleep 1
done
# Create the database and import the SQL dump
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS mydatabase;"
mysql -uroot -proot mydatabase < /mydatabase.sql
# Update root user with new password and grant privileges
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;"
# Start Apache in the foreground
apache2-foreground
To start each container cd to your app directory then run:
Code: Select all
docker-compose up -d --build
Code: Select all
docker-compose down
docker system prune -a --volumes --force
Code: Select all
http://localhost:81/index.php
http://localhost:82/index.php
http://localhost:83/index.php
By following this tutorial, you can host multiple AppGini apps with different PHP versions on the same machine. Each app will run in its own Docker container, accessible on a unique port. Enjoy your versatile hosting environment!
--
. Dockerfile for Other PHP Versions
Duplicate the Dockerfile and other files and replace the base image with the desired PHP version. Additionally, adjust the ports in docker-compose.yml accordingly, for example:
Code: Select all
FROM php:7.4-apache
Code: Select all
ports:
- "82:80" # Set this to 82 on your next version on another php version, 83, 84.... you get the idea