Docker engine, PHP and an IDE.
You'll need PHP 8.1 or higher installed in your machine. Preferrable the same version as you want to work with your project.
Required PHP extensions:
- ctype
- curl
- dom
- filter
- hash
- json
- libxml
- mbstring
- openssl
- pcre
- pdo
- pdo_mysql
- phar
- simplexml
- tokenizer
- xml
- xmlwriter
mkdir ~/tutorial
composer create-project byjg/rest-reference-architecture ~/tutorial 4.9.*
or the latest development version:
mkdir ~/tutorial
composer -sdev create-project byjg/rest-reference-architecture ~/tutorial master
This process will ask some questions to setup your project. You can use the following below as a guide:
> Builder\PostCreateScript::run
========================================================
Setup Project
Answer the questions below
========================================================
Project Directory: /tmp/tutorial
PHP Version [7.4]: 8.1
Project namespace [MyRest]: Tutorial
Composer name [me/myrest]:
MySQL connection DEV [mysql://root:mysqlp455w0rd@mysql-container/mydb]:
Timezone [UTC]:
Press <ENTER> to continue
Tip: The docker composer will create MySQL container named as mysql-container
(ref).
If you want to be able to access your MySQL container from your machine you need to add the following entry in your /etc/hosts
file:
127.0.0.1 mysql-container
cd ~/tutorial
docker-compose -f docker-compose-dev.yml up -d
# Important this will destroy ALL DB data and create a fresh new database based on the migration
APP_ENV=dev composer run migrate -- reset --yes
# *IF* your local PHP is not properly setup you can run this instead:
# export CONTAINER_NAME=# it is the second part of the composer name. e.g. me/myrest, it should be "myrest"
# docker exec -it $CONTAINER_NAME composer run migrate -- reset --yes
The result should be:
> Builder\Scripts::migrate
> Command: reset
Doing reset, 0
Doing migrate, 1
curl http://localhost:8080/sample/ping
The result:
{"result":"pong"}
APP_ENV=dev composer run test # Alternatively you can run `./vendor/bin/phpunit`
# OR: docker exec -it $CONTAINER_NAME composer run test
open http://localhost:8080/docs
You can continue this tutorial by following the next step: creating a new table and crud.