Simple LEMP server dockerized with Alpine Linux, a full dev environment for PHP that include some utilities like Xdebug, Composer and Vim.
nginx
php-fpm
mysql
$ git clone https://github.com/adrianolmedo/lempdock-alpine.git
$ mv lempdock-alpine lempdock && cd lempdock/
$ cp .env.example .env && vim .env
This project needs PHP 8 and MySQL 8:
APP_CODE_PATH_HOST=../hello-world
APACHE_HOST_HTTP_PORT=8080
PHP_VERSION=8
MYSQL_VERSION=8
MYSQL_DATABASE=lempdock
MYSQL_USER=admin
MYSQL_PASSWORD=1234567b
MYSQL_PORT=3307
MYSQL_ROOT_PASSWORD=1234567a
You must create your project directories outside of lempdock/
:
$ cd ..
$ mkdir hello-world
The structure of the full environment must be:
$ tree .
lempdock
hello-world
$ vim hello-world/index.php
<?php
$dbhost = 'mysql';
$dbname = 'lempdock';
$dbroot = 'root';
$dbpass = '1234567a';
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbroot, $dbpass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Connected successfully';
} catch(PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
$ cd lempdock
$ docker-compose up -d --build
Go to http://172.17.0.1:8080.
Get access to php-fpm
service executing:
$ docker-compose exec -u root php-fpm bash
Then to uncomment the first line in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
and then restart service:
$ docker restart php-fpm
Happy debbuging with your favorite IDE!
$ cd lempdock && code .
In .devcontainer/
rename devcontainer.example.json
to devcontainer.json
.
Put your settings and extensions favorites, example:
"settings": {
"terminal.integrated.sendKeybindingsToShell": true,
"terminal.integrated.tabs.enabled": true,
"php.validate.executablePath": "/usr/local/bin/php"
},
"extensions": [
"bmewburn.vscode-intelephense-client",
"ecmel.vscode-html-css",
"felixfbecker.php-debug",
"felixfbecker.php-intellisense",
"formulahendry.terminal",
"kakumei.php-xdebug",
"lonefy.vscode-JS-CSS-HTML-formatter"
]
Ctrl+Shitf+P
> Remote-Containers: Rebuild and Reopen in Container.
This way VSCode it will cache your extensions into the container, check it with:
$ docker diff php-fpm