I'm moving out! I'll take core of this repo in the future.
cd .docker
make build
You should place "laravel" folder with laravel app in it, and "mysql" with an installation of mysql (and a database, of course). If you don't have a mysql database placed, docker will create one for you.
Inside .docker folder, create .env file with this content:
MYSQL_DATABASE=laravel
MYSQL_USER=writeUsernameHere
MYSQL_PASSWORD=writePasswordHere
MYSQL_ROOT_PASSWORD=writePasswordForRootHere
- Enter into the container with:
docker compose exec laravel bash
- Install Laravel with composer (--prefer-dist will download Laravel as one compressed file. It's faster)
composer create-project --prefer-dist laravel/laravel .
- Enter into .docker folder and do:
make up
Docker container will start with all their 4 services (nginx, laravel, mysql, phpmyadmin)
Inside laravel folder, enter into .env file and catch this line:
DB_CONNECTION=sqlite
Change sqlite to mysql. Then use MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD and MYSQL_ROOT_PASSWORD variables from .env file in .docker folder to populate DB .env vars inside laravel folder. Mine looks like this:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=dbz
DB_USERNAME=writeUserForDBHere
DB_PASSWORD=writePasswordForRootHere
Make sure you have this line into your .env file, inside laravel folder:
SESSION_DRIVER=database
Now you have to restart docker, so inside .docker folder you need to execute:
make stop
make up
Then, execute bash inside container:
php artisan key:generate
php artisan migrate:refresh
php artisan migrate
This should migrate the db to mysql and get things ready for use.
I had permission issues and fresh-installed Laravel can't continue because can't write inside laravel folder. Also, I can't read or write inside that folder because the user who's editing code in my VSCode is santiago, and the user of the folder is www-data, indeed. I solved with these two commands:
In parent folder (where .docker it's placed, and probably laravel and mysql too) do this as sudo:
chmod 777 -R laravel
chmod 777 -R mysql
chown -R www-data:www-data laravel # just to be sure