This is my first experience of developing Laravel with PHP. Instead of using Laravel Homestead, I will try run the envrionment with docker tools to not pollute my dev machine with VM. The following commands is run in windows. Mac and Linux users may need change sytax a little bit.
Please install docker, if you like me use windows. If you use mac machine, you can use Valet to configure your computer.
[comment]: # install all laravel depedencies
docker run --rm --interactive --tty --volume ${PWD}:/app composer install
[comment]: # start all the services
docker-compose up -d
[comment]: # migrate database
docker-compose exec app php artisan migrate
[comment]: # also can load some sample data
docker-compose exec app php artisan db:seed --class=SampleTasksSeeder
[comment]: # run some unit tests
docker-compose exec app ./vendor/bin/phpunit --filter TaskTest
Visit http://localhost:8080/
yarn install
yarn run watch
or you prefer npm
npm install
npm run watch
to build FED assets
yarn run dev
yarn run production
- Initialize a repo
- Copy laravel 5.7 download
- Rename readme.md to laravel.md, so I can put the document here.
- Install laravel depedency via composer docker image
docker run --rm --interactive --tty --volume ${PWD}:/app composer install
PS: You may see a list of suggestions to ask you install some php extensions. Just keep in mind these are not necessary. However, it is useful for us to setup our application image later.
- Prepare php application image
laravel 5.7 dependencies:
- PHP >= 7.1.3
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
- Ctype PHP Extension
- JSON PHP Extension
We use php:7.2-fpm image which already have all the dependencies installed. To confirm we can run the following command
docker run -it --rm php:7.2-fpm php -m
PS: Why we still need app.dockerfile if everything is ready. Because we want to control what we can install on them later.
- Prepare reverse proxy image
We choose nginx:1.14 docker image and create a conf file vhost.conf to enable php
- Create docker-compose.yml file to spin up all the containers. You can use the same command to update the running container as well.
docker-compose up -d
To confirm all the container is up
docker ps
- Copy .env.example to .env for development, then generate the key
docker-compose exec app php artisan key:generate
-
Visit http://localhost:8080/
-
Create Model and Controller, keep add logic.
-
Use assets from this Sample. Config build with laravel-mix, so we can build js and scss in laravel. Use yarn instead of npm. Use axios talk to back end instead of localStorage.