
Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria .
If you feel this website help you, you can donate at saweria .
What I Used in This Tutorial
-
Docker version 24.0.7, build afdd53b
How To
Di sini saya pake Unit nya menggunakan docker biar lebih ringkas
-
Buat file docker-compose.yml
version: '3.8' services: nginx-unit: container_name: nginx-unit-ctr image: unit:1.31.1-php8.2 restart: always ports: - "8080:8080" volumes: - $PWD/config.json:/docker-entrypoint.d/config.json - $PWD/www/:/www/
-
Buat file baru di folder www
mkdir www echo '<?php echo "Hello pono"; ?>' > www/index.php
-
Buat file config Unit, beri nama config.json
{ #use port 8080 "listeners": { "*:8080": { #proxy pass name "pass": "applications/php_app" } }, "applications": { "php_app": { #type runtime "type": "php", "root": "/www/" } } }
-
Jalankan menggunakan
docker-compose up -d
Menjalankan Laravel dengan Unit
-
Buat project laravel baru dengan
composer
composer create-project laravel/laravel app
-
Then change storage directory permission
sudo find . -type f -exec chmod 664 {} \; sudo find . -type d -exec chmod 775 {} \; sudo chgrp -R www-data storage bootstrap/cache sudo chmod -R ug+rwx storage bootstrap/cache
-
Create file
docker-compose.yml
version: '3.8' services: nginx-unit-laravel: container_name: nginx-unit-laravel-ctr #user: 'www-data:www-data' image: unit:1.31.1-php8.2 restart: always ports: - "8081:8081" volumes: - $PWD/config.json:/docker-entrypoint.d/config.json - $PWD:/www/
-
Create config.json
{ "listeners": { "*:8081": { "pass": "routes" } }, "routes": [ { "match": { "uri": "!/index.php" }, "action": { "share": "/www/public$uri", "fallback": { "pass": "applications/laravel" } } } ], "applications": { "laravel": { "type": "php", "root": "/www/public/", "script": "index.php" } }
-
Jalankan
docker-compose up

Jangan Pake -d
Biar Bisa Baca Log-nya

Deploy Laravel Pake Nginx Unit Sukses
Kelebihan & Kekurangan
Kelebihan:
- Ga perlu install runtime untuk jalanin aplikasi. Ini di php yg paling kerasa, jadi ga usah install php-fpm sama Nginx, cuma install Unit aja
*Kekurangan:
-
Belum bisa setup certbot kaya di nginx (bisa otomatis pake hook tapi ini ribet)
-
Walaupun dokumentasi lengkap, tapi tutorial di “dunia nyata” masih sedikit.
Referensi: