These instructions are for the initial installation of this application.
- Create project
- Define environment variables
- Configure the app
- Set file permissions
- Database migration
- Scheduled jobs
- Exception links
- Message events
- Resource pruning
- Deployment
- Assets
composer create-project bayfrontmedia/bones-api PROJECT_NAME
Rename .env.example
to .env
and update. (See docs)
NOTE: Be sure to define a cryptographically secure app key for the APP_KEY variable.
Once Bones is installed, you can use the php bones install:key
command to replace SECURE_APP_KEY
with a valid key,
or you can use the php bones make:key
command to generate a key you can define manually.
Update all configuration files at config/*.php
as needed. (See configuration)
The web server must have write permissions to the storage/app
directory.
Typically, this is done by granting the www-data
group ownership and write access:
chgrp -R www-data /path/to/storage/app
chmod -R 775 /path/to/storage/app
Run the initial database migration using:
php bones migrate:up
The API service includes an optional database seeding to add an initial admin user and all the necessary permissions:
php bones api:seed [email protected] password
# Force seeding (no input/confirmation required)
php bones api:seed [email protected] password --force
The password is optional. If not provided, one will be created automatically.
The php bones schedule:run
command must be setup to run every minute.
If a cron job will be used to run the scheduled jobs, add a new entry to your crontab to run every minute:
* * * * * cd /path/to/your/app && php bones schedule:run >> /dev/null 2>&1
# Path to PHP binary may need to be defined
* * * * * /path/to/php/bin cd /path/to/your/app && php bones schedule:run >> /dev/null 2>&1
Update the resources/api/api-errors.php
file as needed to provide links to be returned with API errors.
For more information, see exceptions.
The app/Events/MessageEvents
event subscriber exists for events which may send messages.
These events must be updated to be handled as desired.
Until these are set up, authentication abilities may be restricted if a TFA/OTP code is required.
All soft-deleted resources which no longer need to exist in the database should be periodically pruned with purgeTrashed. In addition, the logs table should be periodically exported/saved and pruned.
These can be done using a scheduled job.
Self-hosted deployment can be handled with the deploy:app
console command.
To deploy to DigitalOcean app platform:
When deploying to DigitalOcean, be sure to update the environment variables in .do/deploy.template.yaml
and encrypt the APP_KEY
and applicable DB_*
values.
Postman collection and environment export files which cover all the routes and functionality of this project are available in the API service repository.