Mastering how to dockerize everything is a good starting point for any project.
Initially, you must install the PHP executable environment. (My OS is windows using Chocolatey cli)
choco install php --version=7.3.0
Next, proceed to install Composer using the Chocolatey CLI.
choco install composer --version=2.1.14
Now, you can utilize the Composer command to create the Laravel project.
composer create-project --prefer-dist laravel/laravel laraveldock "7.*.*"
It will auo-create a laravel project with composer which is similar as npm in JS, and with artisan which is a command-based interface to develop your app easily. For example, you can launch server by
php artisan serve
and synchronize the database with the migration version.
php artisan migrate
The folder structure of the project created by Composer is as follows:
The next step is to create a dockerized app using docker-compose in Laradock.
Firstly, you should add the Laradock repository as a submodule in your Laravel project.
git submodule add https://github.com/Laradock/laradock.git laradock
Then, go into the Laradock folder.
cd laradock
Rename the default environment file to .env.
mv env-example .env
Execute the docker-compose command as follows:
docker-compose up -d --build nginx
If you encounter the below issue,
Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease Could not connect to deb.debian.org:80 (127.0.0.1). - connect (111: Connection refused)
try to add this configuration into daemon.json of docker.
{
"dns": ["8.8.8.8"]
}
Type 127.0.0.1 into your browser, then you will be directed to the front page.
If you prefer not to use Laradock, you can create a Dockerfile based on the php:7.4-apache image by your own.
FROM php:7.4-apache
RUN docker-php-ext-install pdo_mysql
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
RUN apt-get install zip unzip
RUN apt-get install curl && \
curl -sS https://getcomposer.org/installer | php \
&& chmod +x composer.phar && mv composer.phar /usr/local/bin/composer
RUN apt-get install -y libpng-dev
RUN apt-get install -y zlib1g-dev
RUN docker-php-ext-install mysqli
WORKDIR /var/www/html
CMD bash -c "composer install && chmod 777 storage && chmod 777 -R bootstrap/cache && php artisan key:generate && php artisan storage:link"
Top comments (0)