Skip to content

Instantly share code, notes, and snippets.

@rolambert
Last active October 25, 2023 23:38
Show Gist options
  • Save rolambert/664863ef865b5b7af9c8ffa5ea5469a9 to your computer and use it in GitHub Desktop.
Save rolambert/664863ef865b5b7af9c8ffa5ea5469a9 to your computer and use it in GitHub Desktop.
Create a php dev enviroment on windows using podman.
# Author: Robert Lambert
# OS: Windows
# Creation: 2023
# Configuration variable names.
$nginx_conf = "webdev_config.conf"
$nginx_conf_dir = "~\.podman_nginx_configs"
$website_src_files = "c:\Users\robertlambert\.webdevphp"
$website_name = "webdev"
$web_page_src = "https://github.com/banago/simple-php-website.git"
$podmanVersion = podman --version
if ([String]::IsNullorEmpty($podmanVersion))
{
Write-Host "Podman not found, check installation or enviroment variable."
start-sleep -seconds 5
Exit
} else {
Write-Host $podmanVersion
}
# Create
podman pod create --name webdev -p 8080:80
# Image list
podman image list
# Build the image
podman pull php:7.4-fpm-alpine -q
podman pull nginx:alpine -q
podman pull mysql -q
# Build nginx config
mkdir $nginx_conf_dir -ErrorAction SilentlyContinue
$nginx_conf_str = @"
server {
listen 80;
server_name localhost;
root /var/www/webdev;
location / {
try_files `$uri `$uri/ /index.php?`$uri&`$args;
index index.php index.html;
}
location ~ \.php`$ {
try_files `$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)`$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME `$document_root`$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PATH_INFO `$fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
"@
Set-Content -Value $nginx_conf_str -path "$($nginx_conf_dir)\$($nginx_conf)" -Force
rm "$($website_src_files)" -Force -Recurse
$dest = mkdir "$($website_src_files)" -Force
git clone $web_page_src "$($dest.FullName)"
# Run and attach the nginx pod.
podman run -dt --name nginx --pod webdev `
--volume "$((ls $nginx_conf_dir).DirectoryName):/etc/nginx/conf.d:ro" `
--volume "$($dest.FullName):/var/www/$($website_name)" `
--restart on-failure docker.io/library/nginx:alpine
# Run and attach the php pod.
podman run -dt `
--name php7 `
--pod webdev `
--volume "$($dest.FullName):/var/www/$($website_name):rw" `
--restart on-failure `
docker.io/library/php:7.4-fpm-alpine
# Run and attach the mysql pod.
podman run -dt `
--name mysql `
--pod webdev `
--volume mysql:/var/lib/mysql `
--restart on-failure `
--env MYSQL_ROOT_PASSWORD=rootPasswordMakeYourOwn `
docker.io/library/mysql
# Run
podman pod start webdev
# Status
podman pod ps
start http:\\localhost:8080
# Halt
# podman pod stop webdev
# Nuclear Halt and remove all
# podman stop -a
# podman rm -a
# podman exec -it <container_name> /bin/bash
# alpine
podman exec -it php7 /bin/sh
# https://docs.phpunit.de/en/10.4/fixtures.html
wget -O phpunit.phar https://phar.phpunit.de/phpunit-10.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
phpunit --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment