Skip to content

Commit 26152c3

Browse files
Update
1 parent e5ef8c4 commit 26152c3

File tree

13 files changed

+342
-10
lines changed

13 files changed

+342
-10
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2004-2022 Evgeniy Mykhalichenko
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
init:
2+
cp .env_example .env;

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1-
# Lamp Doker skeleton PHP + Nginx + Mysql + Redis
2-
This project will allow you to quickly start working with php.
1+
# Lamp Docker skeleton PHP + Nginx + Mysql + Redis
2+
![](https://img.shields.io/github/issues/krepysh-spec/lamp-docker-php-skeleton) ![](https://img.shields.io/github/forks/krepysh-spec/lamp-docker-php-skeleton) ![](https://img.shields.io/github/stars/krepysh-spec/lamp-docker-php-skeleton) ![](https://img.shields.io/github/license/krepysh-spec/lamp-docker-php-skeleton)
3+
4+
Stop installing the entire development stack on your local machine. This project will allow you to quickly start working with php.
35
To install, you need to install docker locally.
6+
47
### Features
58
- Simple and clear project structure;
69
- Php the latest version 8.1 (can be changed if you need);
710
- All necessary php extensions including composer and xDebug3;
811
- Output all necessary logs (nginx, php, mysql, redis), including slow mysql queries;
912
- Supervisor and cron support
1013
- Quick, easy setup for everything you need
11-
- Lots of useful examples
14+
- Lots of useful examples
15+
16+
### How start work
17+
First make sure you have [Docker](https://docs.docker.com/get-docker/) installed locally.
18+
19+
1. Clone current project:
20+
21+
`git clone https://github.com/krepysh-spec/lamp-docker-php-skeleton.git && cd lamp-docker-php-skeleton`
22+
2. Create .env file from .env_example:
23+
24+
`cp .env_example .env` and fill configuration in .env file
25+
26+
3. `docker-compose build && docker-compose up` and after open in browser [http://localhost](http://localhost)
27+
28+
### Support
29+
30+
For support, email evgeniymykhalichenko@gmail.com or telegram @krep1sh
31+
32+
### License
33+
34+
MIT

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ services:
4848
- .env
4949
volumes:
5050
- ./src:/var/www/backend
51+
- ./logs/supervisor/:/var/log/supervisor/
52+
ports:
53+
- "9001:9001" # Access GUI with http://localhost:9001/
5154
networks:
5255
- backend-network
5356

docker/backend/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ RUN apt-get update && apt-get install -y \
1212
# Clear cache
1313
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
1414

15-
# Copy php confjgurations files
15+
# Copy confjgurations files
1616
COPY php/conf.d/php.ini $PHP_INI_DIR/
1717
COPY php/conf.d/xdebug.ini $PHP_INI_DIR/conf.d/
18+
COPY supervisor/supervisord.conf /etc/supervisor
19+
COPY supervisor/conf.d/* /etc/supervisor/conf.d
1820

1921
# Install and enable pecl php extentions
2022
RUN pecl install xdebug redis
@@ -26,4 +28,6 @@ RUN docker-php-ext-install pdo_mysql
2628
# Get latest Composer
2729
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
2830

29-
WORKDIR "/var/www/backend"
31+
WORKDIR "/var/www/backend"
32+
33+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[program:example]
2+
command=php supervisor.php -DFOREGROUND
3+
directory=/var/www/backend/src/bin
4+
autostart=true
5+
autorestart=true
6+
startretries=5
7+
startsecs=0
8+
user=root
9+
numprocs=1
10+
process_name=%(program_name)s_%(process_num)02d
11+
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
12+
stderr_logfile_maxbytes=10MB
13+
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
14+
stdout_logfile_maxbytes=10MB

docker/backend/supervisor/supervisor.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[unix_http_server]
2+
file=/var/run/supervisor.sock
3+
chmod=0770
4+
chown=nobody:nogroup
5+
6+
[supervisord]
7+
logfile=/var/log/supervisor/supervisord.log
8+
pidfile=/var/run/supervisord.pid
9+
nodaemon=true
10+
11+
[rpcinterface:supervisor]
12+
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
13+
14+
[supervisorctl]
15+
serverurl=unix:///var/run/supervisor.sock
16+
17+
[inet_http_server]
18+
port = 9001
19+
username = root
20+
password = root
21+
22+
[program:php]
23+
command=docker-php-entrypoint php-fpm # This is our main process so let us put it here
24+
25+
[include]
26+
files=/etc/supervisor/conf.d/*.conf

src/public/index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
<?php
22

3+
use KrepyshSpec\LampDockerPhpSkeleton\Application;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
(new Application())->start();

src/src/Application.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace KrepyshSpec\LampDockerPhpSkeleton;
4+
5+
use PDO;
6+
use PDOException;
7+
use Redis;
8+
use RedisException;
9+
10+
class Application
11+
{
12+
/**
13+
* @return void
14+
*/
15+
public function start()
16+
{
17+
$databaseConnectionStatus = $this->checkConnectMysql();
18+
$redisConnectionStatus = $this->checkConnectRedis();
19+
20+
require_once __DIR__ . '/views/index.php';
21+
}
22+
23+
/**
24+
* @return bool
25+
*/
26+
private function checkConnectMysql(): bool
27+
{
28+
$servername = "mysql";
29+
$username = "root";
30+
$password = "root";
31+
$dbname = "testwork";
32+
$port = "3306";
33+
34+
try{
35+
36+
$conn = new PDO("mysql:host=$servername;port=$port;dbname=$dbname",$username,$password);
37+
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
38+
39+
} catch(PDOException $e){
40+
return false;
41+
}
42+
43+
return true;
44+
}
45+
46+
/**
47+
* @return bool
48+
*/
49+
private function checkConnectRedis(): bool
50+
{
51+
try {
52+
53+
$redis = new Redis();
54+
$redis->connect('redis');
55+
56+
if ($redis->ping()) {
57+
return true;
58+
}
59+
60+
} catch (RedisException $e) {
61+
return false;
62+
}
63+
64+
return false;
65+
}
66+
67+
}

0 commit comments

Comments
 (0)