This repository contains a Dockerized Laravel application with PostgreSQL as the database. Follow the steps below to configure the environment and run the application using Docker.
Note: Please make sure to read and follow all the steps mentioned below carefully to ensure a successful setup of the project. Nothing is skippable.
Before you begin, make sure you have the following software installed on your machine:
If any of the above software is not installed, please follow the provided links to download and install the required tools.
-
Clone the Repository:
git clone https://github.com/rifatcse09/custom-ecommerce.git cd wibazaar-portal
Note: Ensure you are on the master branch:
git checkout master
-
Create
.env
file and.yml
file for Docker Compose:cp application/.env.example application/.env cp docker-compose.yml.example docker-compose.yml ln -s application/.env .env
Edit the
.env
file at the root of your project with your preferred text editor. Update the following configurations according to your setup:-
Docker Compose Settings:
DB_CONNECTION=pgsql DB_HOST=host.docker.internal DB_PORT=5432 DB_DATABASE=app_db DB_USERNAME=root DB_PASSWORD=secret DB_CHUNK_SIZE=500 DB_TIMEZONE=UTC WIACCOUNT_HOST=host.docker.internal WIACCOUNT_PORT=5433 WIACCOUNT_DATABASE=account_db WIACCOUNT_USERNAME=root WIACCOUNT_PASSWORD=secret # ... (other Docker settings)
configure your ngrok variable
NGROK=false #if you use dev environment it's false NGROK=true #if you use production environment it's true
Save the changes.
-
Docker Compose Service Descriptions:
-
nginx:
- Nginx web server for serving the Laravel application.
- Maps the application code and Nginx configuration.
- Depends on the
app
service.
-
app:
- Builds and runs the Laravel application code.
- Maps the application code.
- Extra hosts entry to resolve
host.docker.internal
to the host machine's IP.
-
app_db:
- PostgreSQL database service for the Laravel application.
- Uses the specified environment variables for configuration.
- Maps a volume for persistent data storage.
-
minio:
- Minio service for S3 storage (optional).
- Provides S3-compatible storage for your Laravel application.
- Requires additional configuration if you want to use Minio as the S3 driver.
Note: Comment out services that are not needed for your specific setup. Minio is optional and can be omitted if S3 storage is not required.
-
-
-
Build and Start the Docker Container:
docker-compose up -d --build
This command will build the Docker image and start the container in the background. Use the
-d
flag for detached mode. -
Access the Docker Container Shell:
To interact with the app container and run commands, you can use the following:
docker-compose exec app sh
Once inside the container shell, you can execute various commands.
For example:php -v # or any-valid-command
Alternatively, you can run commands directly without entering the shell terminal by using the following syntax:
docker-compose exec app php -v # or docker-compose exec app any-valid-command
Replace
any-valid-command
with the specific command you want to run within the app container.This allows you to perform actions such as running Artisan commands, executing Composer tasks, or any other command needed for your Laravel application without the need to enter the shell interactively.
-
Install Composer Dependencies:
docker-compose exec app composer install docker-compose exec app php artisan horizon:publish docker-compose exec app php artisan telescope:publish docker-compose exec app npm install docker-compose exec app npm run dev #if your Environmental Development use dev
This command installs the necessary PHP dependencies for the Laravel application inside the Docker container.
-
Create
.env
file for Laravel Application:Edit the
application/.env
file with your preferred text editor. Update the following configurations according to your setup:-
Database Connection Settings:
# Primary Database Connection DB_CONNECTION=pgsql DB_HOST=host.docker.internal DB_PORT=5435 DB_DATABASE=app_db DB_USERNAME=root DB_PASSWORD=secret # Additional Database Connection for Wi-Account WIACCOUNT_HOST=host.docker.internal WIACCOUNT_PORT=5433 WIACCOUNT_DATABASE=account_db WIACCOUNT_USERNAME=root WIACCOUNT_PASSWORD=secret # ... (other Laravel settings)
Note: Ensure that the additional database connection values for Wi-Account match the corresponding Wi-Account database credentials:
POSTGRES_PORT=5433 DB_NAME=account_db DB_USER=root DB_PASSWORD=secret
Also make sure that the following values match the corresponding
Docker Compose
settings in the main.env
file:POSTGRES_PORT=5432 DB_NAME=account_db DB_USER=root DB_PASSWORD=secret
Specifically, make sure that
DB_DATABASE
matchesDB_NAME
,DB_USERNAME
matchesDB_USER
, andDB_PORT
matchesPOSTGRES_PORT
. -
Filesystem Configuration for Minio as S3 Driver
if you want to use Minio as the S3 driver.FILESYSTEM_DRIVER=minio MINIO_ACCESS_KEY_ID=IjrPE4xpR19a1cyGj5Bj MINIO_SECRET_ACCESS_KEY=nXg97kO3fB1ZWnA1PKygzlMdccRIRq95RaVN0OUh MINIO_DEFAULT_REGION=us-east-1 MINIO_BUCKET=bazar MINIO_ENDPOINT=http://172.19.0.2:9000 MINIO_USE_PATH_STYLE_ENDPOINT=true
Note: Make sure to adjust these values according to your Minio configuration.
When using Minio as the S3 driver, you need to obtain the
MINIO_ENDPOINT
. To do this, run the following command:docker-compose logs minio
Look for the Minio server's log output, and you'll find the endpoint information like these.
S3-API: http://172.19.0.2:9000 http://127.0.0.1:9000 Console: http://172.19.0.2:9001 http://127.0.0.1:9001
Copy the correct
S3-API
value and replace it in yourapplicaion/.env
file.With these configurations, your Laravel application will use Minio as the S3 driver for file storage.
When using Minio as the S3 driver, ensure that the
minio
service is defined in yourdocker-compose.yml
file.services: # other services minio: image: minio/minio ports: - "${MINIO_S3_PORT}:9000" - "${MINIO_CONSOLE_PORT}:9001" environment: MINIO_ROOT_USER: ${MINIO_ROOT_USER} MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD} volumes: - minio:/data command: server /data --address ":${MINIO_S3_PORT}" --console-address ":${MINIO_CONSOLE_PORT}" networks: - wi_shop_internal_network volumes: # other volumes minio:
With these configurations, your Laravel application will use Minio as the S3 driver for file storage.
-
Laravel Application Settings:
MIX_WI_ACCOUNT_BASE_URL=http://192.168.220.1:8004 WI_ACCOUNT_CLIENT_ID=5 WI_ACCOUNT_CLIENT_SECRET=pg1y0O36Z5XB3ZtC9WVTVFC0Z0MxLm6LxWZ6FfNV SYSTEM_ADMIN_EMAIL=admin@wibazaar.com WIPAY_BASE_URL=http://192.168.220.1:8005 #for example # ... (other Laravel settings)
Note: Make sure to adjust these values according to your configuration.
Save the changes.
-
-
Run Migrations and Seed Database:
docker-compose exec app php artisan migrate --seed
It's used to run migrations and seed the database with initial data.
-
Import Dummy Product and Offer:
To imports dummy products.
docker-compose exec app php artisan dummy:product
To imports dummy offers.
docker-compose exec app php artisan dummy:offer
-
Access the Application:
Once the container is up and running, you can access the Laravel application in your web browser. If your application is running on a port other than 80, make sure to include the port number in the URL:
Replace
your-port
with the actual port number you have configured in the.env
file. -
Stopping the Container:
To stop the Docker container, run:docker-compose down
This will stop and remove the containers defined in the
docker-compose.yml
file.
-
Setting Permissions for Storage Directory:
After starting the Docker container, it's important to
set the appropriate write permissions for the storage
directory in your Laravel application. This directory is used for storing logs, cached views, and other temporary files.docker-compose exec app chmod -R 775 storage
This command grants
read, write, and execute permissions
to thestorage
directory and its subdirectories.If you encounter any issues related to file or directory permissions, ensure that the web server user (usually www-data for Apache or nginx for Nginx) has the necessary permissions to write to the storage directory.
- Make sure the required ports are not already in use on your machine.
- Ensure that the following database-related values match between Laravel application and Docker Compose environments:
- Laravel:
DB_PORT=5435
,DB_DATABASE=app_db
,DB_USERNAME=root
,DB_PASSWORD=secret
- Docker Compose:
POSTGRES_PORT=5432
,DB_NAME=app_db
,DB_USER=root
,DB_PASSWORD=secret
- Laravel:
- Customize the Dockerfile and docker-compose.yml as needed for your specific project requirements.
- For more detailed information, refer to the Laravel documentation: https://laravel.com/docs
To backup your PostgreSQL database and upload it to S3, follow these steps:
-
add your appliction
appliction/.env
file and fill in the required details:ACCESS_KEY_ID= SECRET_ACCESS_KEY= REGION= S3_BUCKET= BUCKET_PATH= CONTAINER_NAME= DB_NAME= DB_USER= DUMP_PATH_ON_HOST=
Provide your
S3 credentials
,container name
,database name
,database user
, anddump file storage path
. -
Grant execute permissions to your
backup.sh
file:chmod +x backup.sh
-
Configure your cron job like this:
crontab -e 0 0 * * * /full/path/to/backup.sh