Project Name
This is a PHP application built with Laravel, running in Docker containers. It uses MySQL as the database and is designed for easy deployment on any machine.
===========================
- Prerequisites ===========================
Ensure the following software is installed on your machine:
- Docker (https://www.docker.com/get-started)
- Docker Compose (https://docs.docker.com/compose/)
Follow these steps to get the application running in Docker:
Clone the project repository to your local machine:
git clone cd
Copy the .env.example
file to .env
:
cp .env.example .env
Update the .env
file with the following database configuration:
DB_CONNECTION=mysql DB_HOST=db DB_PORT=3306 DB_DATABASE=myapp_db DB_USERNAME=user DB_PASSWORD=user_password
Note:
DB_HOST=db
: Refers to the MySQL container name defined in thedocker-compose.yml
.DB_PORT=3306
: The MySQL port.DB_DATABASE=myapp_db
: The name of the database as defined indocker-compose.yml
.DB_USERNAME=user
&DB_PASSWORD=user_password
: The MySQL user credentials.
Build the Docker containers:
docker-compose build
This command will create the PHP application container and the MySQL database container.
Start the containers:
docker-compose up -d
This will run the containers in the background (-d
flag). The PHP application will be available on port 9000, and MySQL will be available on port 3306.
Once the containers are running, execute the following command to run database migrations:
docker-compose exec app php artisan migrate
This will create the necessary tables in the MySQL database.
To populate the database with initial data, run:
docker-compose exec app php artisan db:seed
This will execute the seeders defined in the DatabaseSeeder.php
file.
After setting up the database, you can access the application in your browser:
When you're done working with the containers, you can stop and remove them with:
docker-compose down
This will stop and remove all containers, networks, and volumes created by Docker Compose.
Docker uses the following files to configure the environment:
Dockerfile
: Defines the PHP environment with necessary extensions (pdo
,pdo_mysql
,gd
) and installs Composer for dependency management.docker-compose.yml
: Defines theapp
(PHP container) anddb
(MySQL container) services.
Error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
This occurs when there is ambiguity regarding the id
column in your query. The solution is to explicitly define which table's id
you're referring to, for example, use activities.id
instead of just id
.
Error: docker-compose: command not found
If you see this error, Docker Compose may not be installed. Follow the installation guide here: https://docs.docker.com/compose/install/
This project is licensed under the MIT License - see the LICENSE file for details.