Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a33843

Browse files
Merge pull request #19 from thecodeholic/docker
Docker Integration
2 parents abd6d22 + 7a1b8fd commit 1a33843

File tree

9 files changed

+129
-3
lines changed

9 files changed

+129
-3
lines changed

‎.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
runtime

‎.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DB_DSN = mysql:host=localhost;port=3306;dbname=mvc_framework
2-
DB_USER = root
3-
DB_PASSWORD =
1+
DB_DSN = mysql:host=db;port=3306;dbname=php_mvc
2+
DB_USER = php_mvc
3+
DB_PASSWORD =php_mvc

‎README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ Minimalistic custom framework created for educational purposes.
1818
7. Start php server by running command `php -S 127.0.0.1:8080`
1919
8. Open in browser http://127.0.0.1:8080
2020

21+
------
22+
## Installation using docker
23+
Make sure you have docker installed. To see how you can install docker on Windows [click here](https://youtu.be/2ezNqqaSjq8). <br>
24+
Make sure `docker` and `docker-compose` commands are available in command line.
25+
26+
1. Clone the project using git
27+
1. Copy `.env.example` into `.env` (Don't need to change anything for local development)
28+
1. Navigate to the project root directory and run `docker-compose up -d`
29+
1. Install dependencies - `docker-compose exec app composer install`
30+
1. Run migrations - `docker-compose exec app php migrations.php`
31+
8. Open in browser http://127.0.0.1:8080
2132

2233
> The project was created along with Youtube Video Series "[Build PHP MVC Framework](https://www.youtube.com/playlist?list=PLLQuc_7jk__Uk_QnJMPndbdKECcTEwTA1)".
2334
> I appreaciate if you share it.

‎docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.7"
2+
3+
services:
4+
app:
5+
build: ./docker
6+
image: thecodeholic/php_mvc
7+
ports:
8+
- "8080:80"
9+
volumes:
10+
# Mount source-code for development
11+
- ./:/var/www
12+
db:
13+
image: mysql:8
14+
ports:
15+
- "3307:3306"
16+
volumes:
17+
- mysql-data:/var/lib/mysql
18+
- ./docker/mysql-config.cnf:/etc/mysql/conf.d/config.cnf
19+
environment:
20+
MYSQL_ROOT_PASSWORD: root
21+
MYSQL_DATABASE: php_mvc
22+
MYSQL_USER: php_mvc
23+
MYSQL_PASSWORD: php_mvc
24+
25+
volumes:
26+
mysql-data:

‎docker/000-default.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<VirtualHost *:80>
2+
ServerAdmin webmaster@localhost
3+
DocumentRoot /var/www/public
4+
5+
<Directory /var/www>
6+
Options Indexes FollowSymLinks
7+
AllowOverride All
8+
Require all granted
9+
</Directory>
10+
</VirtualHost>

‎docker/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM php:8.1-apache
2+
3+
# Copy virtual host into container
4+
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
5+
6+
# Enable rewrite mode
7+
RUN a2enmod rewrite
8+
9+
# Install necessary packages
10+
RUN apt-get update && \
11+
apt-get install \
12+
libzip-dev \
13+
wget \
14+
git \
15+
unzip \
16+
-y --no-install-recommends
17+
18+
# Install PHP Extensions
19+
RUN docker-php-ext-install zip pdo_mysql
20+
21+
# RUN pecl install -o -f xdebug-3.1.3 \
22+
# && rm -rf /tmp/pear
23+
24+
# Copy composer installable
25+
COPY ./install-composer.sh ./
26+
27+
# Copy php.ini
28+
COPY ./php.ini /usr/local/etc/php/
29+
30+
# Cleanup packages and install composer
31+
RUN apt-get purge -y g++ \
32+
&& apt-get autoremove -y \
33+
&& rm -r /var/lib/apt/lists/* \
34+
&& rm -rf /tmp/* \
35+
&& sh ./install-composer.sh \
36+
&& rm ./install-composer.sh
37+
38+
# Change the current working directory
39+
WORKDIR /var/www
40+
41+
# Change the owner of the container document root
42+
RUN chown -R www-data:www-data /var/www
43+
44+
# Start Apache in foreground
45+
CMD ["apache2-foreground"]
46+

‎docker/install-composer.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
4+
SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
5+
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
6+
7+
if [ "$EXPECTED_SIGNATURE" != "$SIGNATURE" ]
8+
then
9+
echo 'ERROR: Invalid installer signature'
10+
rm composer-setup.php
11+
exit 1
12+
fi
13+
14+
php composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer
15+
RESULT=$?
16+
rm composer-setup.php
17+
exit $RESULT

‎docker/mysql-config.cnf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[client]
2+
default-character-set = utf8mb4
3+
4+
[mysql]
5+
default-character-set = utf8mb4
6+
7+
[mysqld]
8+
init-connect='SET NAMES utf8mb4'
9+
collation_server=utf8mb4_unicode_ci
10+
character_set_server=utf8mb4
11+
default_authentication_plugin= mysql_native_password

‎docker/php.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; General
2+
upload_max_filesize = 200M
3+
post_max_size = 220M

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /