- https://docs.google.com/document/d/1lkJQ-pVw1q4SR7appH6KRTOHF_mkFCsU7Vz3t-X27c0/edit#heading=h.55sbk8djw69w
- Create a backoffice / clients portal
- Should use the latest technology to learn
- Should use workers for edge computing
- Laravel, postgressql, tailwind, docker, cloudflare workers
$ ./update.sh
$ docker compose up -d
$ docker compose exec app npm run dev
$ docker exec -it laravel_app sh
$ docker compose exec app php artisan migrate
$ docker compose exec app php artisan migrate:fresh --seed
> http://local.host:8082/
$ docker compose exec app npm install Note: The queue worker runs automatically via Supervisor when the container starts. No need to manually start it.
$ docker compose exec app php artisan
$ docker compose exec app php artisan make
$ docker compose exec app php artisan help migrate:fresh
$ docker --version //Docker version 26.1.4, build 5650f9b
$ docker compose --version //docker compose version 1.29.2, build unknown
$ node -v
$ php artisan --version$ psql -h localhost -p 5439 -U administrator -d portal
-
clore repository:
$ git clone [email protected]:aristos32/portal.git
$ cd portal -
create .env file
$ cp my-laravel/.env.example my-laravel/.env -
In the .env, update these variables to match the ones in the docker compose
# db
DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=portal
DB_USERNAME=administrator
DB_PASSWORD=password
- Install composer dependencies
$ docker compose run --rm composer install
$ docker compose run --rm composer require barryvdh/laravel-debugbar --dev
- If any permission errors like this occurs:
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log
then set correct permissions and ownership:
$ docker compose exec app chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache && docker compose exec app chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
-
if cannot save file: Failed to save '2024_10_28_185159_create_accounts_table.php': Insufficient permissions.
-
file_put_contents(/var/www/html/storage/framework/views/bae129cef9e600352d1c88ca55b5c61c.php): Failed to open stream: Permission denied
$ sudo chown -R aristos:aristos my-laravel/
-
install Laravel Sanctum for api
$ docker compose exec app php artisan install:api -
build and start all docker services
$ docker compose up -d --build -
verify that all services are up
$ docker compose ps -
Run migrations
$ docker compose exec app php artisan migrate -
install npm
$ docker compose exec app npm install - Generate Laravel application encryption key - missing key exception
$ docker compose exec app php artisan key:generate
- Tinker CLI - command line playground.
$ docker compose exec app php artisan tinker
> \App\Models\Job::factory(100)->create();
> \App\Models\User::all();
> \App\Models\Customer::find(1);
> App\Models\User::factory()->unverified()->create();
- Assets related - is vite running
http://localhost:5173/
php artisan view:clear
php artisan config:clear
$ docker compose exec app npm run dev
➜ Local: http://localhost:5173/
- start the scheduler
$ docker compose exec app php artisan schedule:work
http://127.0.0.1:8082/
http://127.0.0.1:8082/dashboard
http://127.0.0.1:8082/test
$ tail -f my-laravel/storage/logs/laravel.log
$ docker compose exec redis redis-cli
-- KEYS * (see all keys)
-- GET key_name
-- DEL key_name
Connect to the database from the host machine
$ psql -h localhost -p 5432 -U administrator -d portal
$ mysql -h 127.0.0.1 -P 3308 -u laravel -p
Clean and seed again
$ docker compose exec app php artisan migrate:fresh --seed
$ docker compose exec app php artisan vendor:publish
$ docker compose exec app php artisan test
"pathMappings": {
"/var/www/html": "${workspaceFolder}/my-laravel"
}
The application uses Supervisor to manage processes in the app container. Supervisor automatically starts and manages:
- PHP-FPM - Handles web requests
- Laravel Queue Worker - Processes queued jobs automatically
The queue worker starts automatically when the container starts and will restart if it crashes.
Check Supervisor Status:
$ docker compose exec app supervisorctl statusManage Queue Worker:
# Restart queue worker
$ docker compose exec app supervisorctl restart laravel-queue
# Stop queue worker
$ docker compose exec app supervisorctl stop laravel-queue
# Start queue worker
$ docker compose exec app supervisorctl start laravel-queue
# Restart all processes
$ docker compose exec app supervisorctl restart allView Logs:
# Queue worker logs
$ docker compose exec app tail -f /var/log/supervisor/queue-worker.log
# PHP-FPM logs
$ docker compose exec app tail -f /var/log/supervisor/php-fpm.out.log
# Supervisor main log
$ docker compose exec app tail -f /var/log/supervisor/supervisord.logConfiguration:
- Supervisor config:
docker/supervisor/supervisord.conf - Queue worker settings can be customized in the supervisor config file
- Access via:
http://127.0.0.1:8082/api/documentation
https://chatgpt.com/c/69551d75-1ac8-832e-8010-9c157d06b38c
- Install
$ docker compose run --rm composer require darkaonline/l5-swagger
$ docker compose exec app php artisan vendor:publish --provider="L5Swagger\L5SwaggerServiceProvider"
- Generate Swagger documentation
Run:
$ docker compose exec app php artisan l5-swagger:generate
- sending emails
https://mailtrap.io/
copy smtp settings in .env
Run test route:
Route::get('/test', function () {
Mail::to('[email protected]')->send(new ContractExpiringSoon(Contract::find(1)));
return 'Email sent';
//return new ContractExpiringSoon(Contract::find(1));
});
with:
http://127.0.0.1:8082/test
check email in mailtrap inbox