Skip to content

Commit

Permalink
Merge pull request #1 from Anthony14FR/Release-01
Browse files Browse the repository at this point in the history
Using now nginx with nginx conf and fix somes bugs
  • Loading branch information
Anthony14FR authored Mar 13, 2024
2 parents 84e9290 + 1caa3fa commit f1d3d5c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 41 deletions.
13 changes: 3 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Utiliser l'image PHP avec Apache, PHP 8.3
FROM php:8.2-fpm
# Installer les extensions PHP nécessaires pour Laravel et nettoyer le cache après installation
FROM php:8.3-fpm

RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
Expand All @@ -14,17 +13,11 @@ RUN apt-get update && apt-get install -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Activer le mod_rewrite pour Apache
RUN a2enmod rewrite

# Donner la propriété du répertoire à l'utilisateur www-data
RUN chown -R www-data:www-data /var/www/html

# Les droits d'accès au répertoire
RUN chmod -R 755 /var/www/html

# Installer une version spécifique de Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.1.3

# Exposer le port 80
EXPOSE 80
EXPOSE 9000
32 changes: 9 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
.PHONY: setup docker-build laravel-install app-install update-env key-generate migrate down
setup: build laravel-setup key-generate migrate

# Définition de la commande par défaut
setup: docker-build laravel-install app-install update-env key-generate migrate
build:
docker-compose down -v
docker-compose up -d --build

# Construction des images Docker
docker-build:
docker compose down -v && docker-compose up -d --build
laravel-setup: laravel-install update-env

# Installation de Laravel via Composer
laravel-install:
if [ ! -d "app" ]; then \
mkdir -p app && cd app && composer create-project --prefer-dist laravel/laravel . ; \
fi

# Installation des dépendances de Laravel (Utilisable après la première installation si nécessaire)
app-install:
cd app && composer install
[ -d "laravel-project" ] || (mkdir -p laravel-project && cd laravel-project && composer create-project --prefer-dist laravel/laravel . && cd ..)
cd laravel-project && composer install

update-env:
cp .env.example app/.env
cp .env.example laravel-project/.env

# Génération de la clé d'application Laravel
key-generate:
docker-compose exec app php artisan key:generate

# Migration de la base de données
migrate:
docker-compose exec app php artisan migrate

# Arrêt des conteneurs Docker
down:
docker-compose down -v

reload:
docker-compose down -v && docker-compose up -d

build:
docker-compose down -v && docker-compose up -d --build
reload: down build
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
# LaravelWithDockerSingleCommand
# Laravel with Docker - Single Command Setup

## Prerequisites

Before you begin, ensure you have installed all of the following on your development machine:
- Docker and Docker Compose
- Make (for using the `Makefile` commands)


## Getting Started

To get your Dockerized Laravel environment up and running, follow these steps:

1. **Clone the Repository**

Start by cloning this repository to your local machine:

```sh
git clone [email protected]:Anthony14FR/LaravelWithDockerSingleCommandSetup.git
```

2. **Run the Setup Command**

Navigate to the root directory of the cloned repository and run the setup command:

```sh
make setup
```

This command builds the Docker images, creates a new Laravel project, and sets up the environment.

3. **Access Your Laravel Application**

After the setup is complete, your Laravel application will be accessible at `http://localhost:8080`.


## Features

- **Dockerized Environment**: Includes configurations for `app` (PHP-FPM), `db` (MySQL), and `nginx` as a web server.
- **Automatic Laravel Installation**: Automates the installation and setup of a new Laravel project.
- **Environment Customization**: Easy customization through `.env` files and Docker Compose configurations.
- **Simplified Commands**: Utilizes a `Makefile` for common tasks such as setup, teardown, and environment management.


## Makefile Commands

The `Makefile` includes several commands to simplify the management of your Docker environment:

- `make setup`: Initializes the environment and sets up the Laravel project.
- `make build`: Builds or rebuilds services defined in `docker-compose.yml`.
- `make down`: Stops and removes containers, networks, and volumes.
- `make reload`: Stops all services and starts them again.
- `make key-generate`: Generates a new application key for Laravel.
- `make migrate`: Runs the database migrations.

## Customization

You can customize your Laravel and Docker setup by editing the `.env` files for Laravel and modifying the `docker-compose.yml` file according to your requirements.

## Troubleshooting

- If you encounter any issues during the setup process, ensure Docker and Docker Compose are correctly installed and up-to-date.
- Check the Docker and application logs for any errors that might indicate what went wrong.

## License

This project is open-sourced under the MIT License. See the LICENSE file for more information.
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ services:
context: .
dockerfile: Dockerfile
volumes:
- ./app:/var/www/html
- ./laravel-project:/var/www/html
restart: unless-stopped
networks:
- laravel
ports:
- "80:80"
container_name: app
depends_on:
- db

Expand All @@ -24,7 +23,6 @@ services:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- dbdata:/var/lib/mysql
networks:
Expand All @@ -35,7 +33,7 @@ services:
ports:
- "8080:80"
volumes:
- .:/var/www/html
- ./laravel-project:/var/www/html
- ./laravel.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
Expand Down
4 changes: 2 additions & 2 deletions laravel.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
server {
listen 80;
server_name serveur1;
server_name localhost;

root /var/www/html/public;
index index.php index.html index.htm;
Expand All @@ -11,7 +11,7 @@ server {

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php1:9000;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Expand Down

0 comments on commit f1d3d5c

Please sign in to comment.