Quickly setup local Laravel development using docker without php installed locally

Quickly setup local Laravel development using docker without php installed locally

The following will create the Laravel hello world application in your current working directory, without haveing needing to have the correct php version installed locally.

docker run --rm --interactive --tty   --volume $PWD:/app composer create-project --prefer-dist laravel/laravel blog 

Replace 'blog' with whatever you want to call your project.

After running your directory will be populated with the Laraval source code.

You will need to change the owner of the directory from root to your user because by default the container runs as root :/

e.g.

sudo chown -R chris:chris blog/

Now you can create a docker file, build and run

Laravel Docker file

Create Dockerfile

FROM php:7.3.19-alpine AS build
WORKDIR src

Copy source code into ./src folder

COPY . .
COPY --from=composer /usr/bin/composer /usr/bin/composer

Build and optimise ./vendor folder

FROM php:7.3.19-alpine AS build                                                                                                    
WORKDIR src                                                                      
# Copy source code into ./src folder                                             
COPY . .                                                                         
COPY --from=composer /usr/bin/composer /usr/bin/composer                         
# Build and optimise ./vendor folder                                             
RUN composer install --no-dev --optimize-autoloader                                                                                
                                                                                 
FROM php:7.3.19-apache-buster                                                    
COPY --from=build src /var/www/html/                                             
                                                                                 
RUN a2enmod rewrite                                                              
COPY vhost.conf /etc/apache2/sites-available/                       
RUN a2dissite 000-default.conf                                                   
RUN a2ensite vhost.conf                                                    
RUN service apache2 restart 
docker build -t test .
docker run -p 8083:80 test
Collect recurring payments with Subscribie - Try Now