Skip to content

honeyonsys/laravel-mysql-docker-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

To Setup The Docker For Laravel + VueJs Project.

  • Create a directory to store your project-specific files.
  • Let say we created the directory "helloworld" to store all the project files.
  • Now create the file docker-compose.yml at the root of your project directory as shown below.

docker-compose.yml

services:
  mongodb:
    image: mongo:5.0
    container_name: mongodb1
    ports:
      - "27017:27017"
  apache:
    container_name: apache
    build: ./docker/apache
    links:
      - php
    ports:
      - "7000:80"
    volumes:
      - ./logs/apache:/var/log/apache2
      - ./src/helloworld:/usr/local/apache2/htdocs/helloworld
  php:
    container_name: php
    build: ./docker/php
    ports:
      - "9000:9000"
    volumes:
      - ./src/helloworld:/usr/local/apache2/htdocs/helloworld
    working_dir: /usr/local/apache2/htdocs/helloworld
  composer:
    container_name: composer
    image: composer/composer
    volumes:
      - ./src/helloworld:/usr/local/apache2/htdocs/helloworld
    working_dir: /usr/local/apache2/htdocs/helloworld
    command: install
  vuejs:
    container_name: vuejs
    build:
      context: ./src/vuejs
    ports:
      - "5713:5713"
    volumes:
      - ./src/vuejs:/src
    working_dir: /src
    command: npm run dev -- --host

  • Now create the directories - docker and src within the project root directory.
  • Also, create two directories within the docker directory i.e. php and apache.
  • Create the directories helloworld/logs/apache to store the logs.
  • Create the Dockerfile within the PHP directory as shown below.

docker/php/Dockerfile

FROM php:8.3-fpm

RUN apt-get update
RUN apt-get install -y openssl zip unzip git curl
RUN apt-get install -y libzip-dev libonig-dev libicu-dev
RUN apt-get install -y autoconf pkg-config libssl-dev
RUN docker-php-ext-install bcmath mbstring intl opcache
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN pecl install mongodb
RUN docker-php-ext-enable mongodb
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/mongodb.ini

Create the Dockerfile within the Apache directory as shown below.

docker/apache/Dockerfile

FROM httpd:2.4.51

COPY helloworld.apache.conf /usr/local/apache2/conf/helloworld.apache.conf
RUN echo "Include /usr/local/apache2/conf/helloworld.apache.conf" \
    >> /usr/local/apache2/conf/httpd.conf

RUN echo "LoadModule rewrite_module modules/mod_rewrite.so" \
    >> /usr/local/apache2/conf/httpd.conf

docker/apache/helloworld.apache.conf

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so

<VirtualHost *:80>
	ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/usr/local/apache2/htdocs/helloworld/public/$1
	DocumentRoot /usr/local/apache2/htdocs/helloworld/public
	<Directory /usr/local/apache2/htdocs/helloworld>
		Options -Indexes +FollowSymLinks
		DirectoryIndex index.php
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>
  • After creating all the directories and files, the directory structure should be similar as shown below.
helloworld
-- docker
   -- php
      -- Dockerfile
   -- apache
      -- Dockerfile
      -- helloworld.apache.conf
-- src
   -- <laravel app directories and files>
-- logs
   -- apache
-- docker-compose.yml 
  • Next, we will install the Laravel project template files in the src directory using the command shown below.
  • It's required for the first time for the fresh installation of Laravel.

Clear Directory

cd <path to project>/src

Install Laravel

composer create-project --prefer-dist laravel/laravel:^8.0 helloworld

Output

Creating a "laravel/laravel:^8.0" project at "./helloworld" Installing laravel/laravel (v8.77.1)

  • Downloading laravel/laravel (v8.77.1)
  • Installing laravel/laravel (v8.77.1): Extracting archive Created project in E:\development\projects-study\php\docker\helloworld\src\helloworld

@php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies .... .... Package manifest generated successfully. 77 packages you are using are looking for funding. Use the composer fund command to find out more! @php artisan vendor:publish --tag=laravel-assets --ansi --force No publishable resources for tag [laravel-assets]. Publishing complete.

> @php artisan key:generate --ansi

Application key set successfully.

  • The above command installs Laravel at /src/helloworld.

  • Now, run the command docker-compose build to build the images for PHP and Apache Web Server.

  • After completing the build, we can run the application using the command docker-compose up .

-To Stop the Container

-- docker-compose down

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •