diff --git a/.gitignore b/.gitignore index 44d49db..57e9a47 100755 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ user_guide_src/cilexer/pycilexer.egg-info/* /.env /themeforest /documents +/writable diff --git a/README.md b/README.md new file mode 100644 index 0000000..c8d2783 --- /dev/null +++ b/README.md @@ -0,0 +1,166 @@ +# PHP Docker Template + +Template voor PHP projecten (CodeIgniter, plain PHP, etc.) met Xdebug support. + +## Snelle start + +### 1. Kopieer bestanden naar je project + +```bash +cp -r docker/ /pad/naar/jouw-project/ +cp docker-compose.yml /pad/naar/jouw-project/ +cp .env.example /pad/naar/jouw-project/.env +``` + +### 2. Configureer je project + +Pas `.env` aan: +```env +PROJECT_NAME=jouwproject +PROJECT_DOMAIN=jouwproject.test +DB_DATABASE=jouwproject_db +``` + +### 3. Pas PHP versie aan (indien nodig) + +In `docker-compose.yml`, wijzig de PHP_VERSION: +```yaml +args: + PHP_VERSION: "8.2" # Opties: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 +``` + +### 4. Pas document root aan (indien nodig) + +In `docker/nginx.conf`, wijzig root als je project geen `/public` map heeft: +```nginx +# Voor CodeIgniter 3: +root /var/www/html; + +# Voor CodeIgniter 4 / Laravel-style: +root /var/www/html/public; +``` + +### 5. DNS instellen + +Voeg toe aan `/etc/hosts`: +``` +127.0.0.1 jouwproject.test +``` + +Of gebruik dnsmasq voor automatische .test domeinen. + +### 6. Database aanmaken + +```bash +docker exec -it shared-mysql mysql -u root -proot -e "CREATE DATABASE jouwproject_db;" +``` + +### 7. Start het project + +```bash +# Zorg dat shared services draaien +cd /Volumes/development/sites/docker-shared +docker compose up -d + +# Start je project +cd /pad/naar/jouw-project +docker compose up -d --build +``` + +Je project is nu beschikbaar op http://jouwproject.test + +--- + +## Xdebug met PHPStorm + +### 1. PHPStorm configureren + +1. **Preferences → PHP → Servers** + - Klik op `+` + - Name: `jouwproject.test` + - Host: `jouwproject.test` + - Port: `80` + - Debugger: `Xdebug` + - ✅ Use path mappings + - Map `/pad/naar/jouw-project` → `/var/www/html` + +2. **Preferences → PHP → Debug** + - Debug port: `9003` + - ✅ Can accept external connections + +3. **Preferences → PHP → Debug → DBGp Proxy** + - IDE key: `PHPSTORM` + +### 2. Debugging starten + +1. Klik op de telefoon-icoon in PHPStorm: "Start Listening for PHP Debug Connections" +2. Zet een breakpoint +3. Open je pagina in de browser +4. PHPStorm stopt automatisch bij je breakpoint + +--- + +## Handige commando's + +```bash +# Start containers +docker compose up -d + +# Herbouw na Dockerfile wijzigingen +docker compose up -d --build + +# Stop containers +docker compose down + +# Bekijk logs +docker compose logs -f + +# Shell in PHP container +docker exec -it jouwproject-app bash + +# Composer commands +docker exec -it jouwproject-app composer install +docker exec -it jouwproject-app composer update + +# Artisan commands (als je Laravel-achtige CLI hebt) +docker exec -it jouwproject-app php artisan migrate +``` + +--- + +## Structuur + +``` +jouw-project/ +├── docker/ +│ ├── Dockerfile # PHP container configuratie +│ ├── nginx.conf # Nginx configuratie +│ ├── php.ini # PHP settings +│ └── xdebug.ini # Xdebug settings +├── docker-compose.yml # Container orchestratie +├── .env # Project variabelen +└── ... je project bestanden +``` + +--- + +## Troubleshooting + +### Container kan shared-mysql niet bereiken +Controleer of shared services draaien: +```bash +docker ps | grep shared-mysql +``` + +### Xdebug werkt niet +1. Check of xdebug actief is: + ```bash + docker exec -it jouwproject-app php -m | grep xdebug + ``` +2. Check PHPStorm luistert op poort 9003 +3. Controleer path mapping in PHPStorm + +### Permission denied errors +```bash +docker exec -it jouwproject-app chown -R www:www /var/www/html/storage +``` diff --git a/app/Config/App.php b/app/Config/App.php new file mode 100644 index 0000000..2e8e5b9 --- /dev/null +++ b/app/Config/App.php @@ -0,0 +1,87 @@ + + */ + public array $allowedHostnames = []; + + /** + * Index File + */ + public string $indexPage = ''; + + /** + * URI Protocol + */ + public string $uriProtocol = 'REQUEST_URI'; + + /** + * Default Locale + */ + public string $defaultLocale = 'nl'; + + /** + * Negotiate Locale + */ + public bool $negotiateLocale = false; + + /** + * Supported Locales + * + * @var list + */ + public array $supportedLocales = ['nl', 'en']; + + /** + * Application Timezone + */ + public string $appTimezone = 'Europe/Amsterdam'; + + /** + * Default Character Set + */ + public string $charset = 'UTF-8'; + + /** + * Force Global Secure Requests + */ + public bool $forceGlobalSecureRequests = false; + + /** + * Reverse Proxy IPs + * + * @var array + */ + public array $proxyIPs = []; + + /** + * Content Security Policy + */ + public bool $CSPEnabled = false; + + public function __construct() + { + parent::__construct(); + + // Set baseURL from environment + $this->baseURL = $_ENV['APP_URL'] ?? 'http://localhost'; + + // Force HTTPS in production + if (($_ENV['ENVIRONMENT'] ?? 'development') === 'production') { + $this->forceGlobalSecureRequests = true; + } + } +} diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php new file mode 100644 index 0000000..1cb8d07 --- /dev/null +++ b/app/Config/Autoload.php @@ -0,0 +1,44 @@ +|string> + */ + public $psr4 = [ + APP_NAMESPACE => APPPATH, + ]; + + /** + * Class Maps + * + * @var array + */ + public $classmap = []; + + /** + * Files to be autoloaded. + * + * @var list + */ + public $files = []; + + /** + * Helpers to be autoloaded. + * + * @var list + */ + public $helpers = ['common']; +} diff --git a/app/Config/Boot.php b/app/Config/Boot.php new file mode 100644 index 0000000..df6e723 --- /dev/null +++ b/app/Config/Boot.php @@ -0,0 +1,44 @@ +appDirectory . '/..') . DIRECTORY_SEPARATOR); + +// Path to the application directory +defined('APPPATH') || define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR); + +// Path to the public directory +defined('PUBLICPATH') || define('PUBLICPATH', realpath($paths->publicDirectory) . DIRECTORY_SEPARATOR); + +// Path to the writable directory +defined('WRITEPATH') || define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR); + +// Path to the tests directory +defined('TESTPATH') || define('TESTPATH', realpath($paths->testsDirectory) . DIRECTORY_SEPARATOR); + +/* + * --------------------------------------------------------------- + * GRAB THE CODEIGNITER BOOT CLASS + * --------------------------------------------------------------- + */ + +require ROOTPATH . 'vendor/codeigniter4/framework/system/Boot.php'; + +return Boot::bootWeb($paths); diff --git a/app/Config/Boot/development.php b/app/Config/Boot/development.php new file mode 100644 index 0000000..a868447 --- /dev/null +++ b/app/Config/Boot/development.php @@ -0,0 +1,34 @@ + WRITEPATH . 'cache/', + 'mode' => 0640, + ]; + + /** + * ------------------------------------------------------------------------- + * Memcached settings + * ------------------------------------------------------------------------- + * + * Your Memcached servers can be specified below, if you are using + * the Memcached drivers. + * + * @see https://codeigniter.com/user_guide/libraries/caching.html#memcached + * + * @var array{host?: string, port?: int, weight?: int, raw?: bool} + */ + public array $memcached = [ + 'host' => '127.0.0.1', + 'port' => 11211, + 'weight' => 1, + 'raw' => false, + ]; + + /** + * ------------------------------------------------------------------------- + * Redis settings + * ------------------------------------------------------------------------- + * + * Your Redis server can be specified below, if you are using + * the Redis or Predis drivers. + * + * @var array{host?: string, password?: string|null, port?: int, timeout?: int, database?: int} + */ + public array $redis = [ + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'timeout' => 0, + 'database' => 0, + ]; + + /** + * -------------------------------------------------------------------------- + * Available Cache Handlers + * -------------------------------------------------------------------------- + * + * This is an array of cache engine alias' and class names. Only engines + * that are listed here are allowed to be used. + * + * @var array> + */ + public array $validHandlers = [ + 'dummy' => DummyHandler::class, + 'file' => FileHandler::class, + 'memcached' => MemcachedHandler::class, + 'predis' => PredisHandler::class, + 'redis' => RedisHandler::class, + 'wincache' => WincacheHandler::class, + ]; + + /** + * -------------------------------------------------------------------------- + * Web Page Caching: Cache Include Query String + * -------------------------------------------------------------------------- + * + * Whether to take the URL query string into consideration when generating + * output cache files. Valid options are: + * + * false = Disabled + * true = Enabled, take all query parameters into account. + * Please be aware that this may result in numerous cache + * files generated for the same page over and over again. + * ['q'] = Enabled, but only take into account the specified list + * of query parameters. + * + * @var bool|list + */ + public $cacheQueryString = false; +} diff --git a/app/Config/Constants.php b/app/Config/Constants.php new file mode 100644 index 0000000..671f59b --- /dev/null +++ b/app/Config/Constants.php @@ -0,0 +1,67 @@ +|string|null + */ + public $defaultSrc; + + /** + * Lists allowed scripts' URLs. + * + * @var list|string + */ + public $scriptSrc = 'self'; + + /** + * Lists allowed stylesheets' URLs. + * + * @var list|string + */ + public $styleSrc = 'self'; + + /** + * Defines the origins from which images can be loaded. + * + * @var list|string + */ + public $imageSrc = 'self'; + + /** + * Restricts the URLs that can appear in a page's `` element. + * + * Will default to self if not overridden + * + * @var list|string|null + */ + public $baseURI; + + /** + * Lists the URLs for workers and embedded frame contents + * + * @var list|string + */ + public $childSrc = 'self'; + + /** + * Limits the origins that you can connect to (via XHR, + * WebSockets, and EventSource). + * + * @var list|string + */ + public $connectSrc = 'self'; + + /** + * Specifies the origins that can serve web fonts. + * + * @var list|string + */ + public $fontSrc; + + /** + * Lists valid endpoints for submission from `
` tags. + * + * @var list|string + */ + public $formAction = 'self'; + + /** + * Specifies the sources that can embed the current page. + * This directive applies to ``, `