mirror of
https://github.com/jkaninda/laravel-php-fpm.git
synced 2025-12-06 08:59:38 +01:00
Add checking if the project is based on Laravel
This commit is contained in:
23
Dockerfile
23
Dockerfile
@@ -1,4 +1,4 @@
|
||||
FROM php:8.1-fpm
|
||||
FROM php:8.1.0-fpm
|
||||
ENV WORKDIR=/var/www
|
||||
ENV STORAGE_DIR=/var/www/storage
|
||||
# Install system dependencies
|
||||
@@ -33,6 +33,11 @@ RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\
|
||||
&& make all -j 5 \
|
||||
&& make install
|
||||
|
||||
# Install Rdkafka and enable it
|
||||
RUN docker-php-ext-enable rdkafka \
|
||||
&& cd .. \
|
||||
&& rm -rf /php-rdkafka
|
||||
|
||||
# Install PHP extensions zip, mbstring, exif, bcmath, intl
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
|
||||
RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl
|
||||
@@ -40,9 +45,7 @@ RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl
|
||||
# Install Redis and enable it
|
||||
RUN pecl install redis && docker-php-ext-enable redis
|
||||
|
||||
# Install Rdkafka and enable it
|
||||
RUN docker-php-ext-enable rdkafka \
|
||||
&& rm -rf /php-rdkafka
|
||||
|
||||
|
||||
# Install the php memcached extension
|
||||
RUN pecl install memcached && docker-php-ext-enable memcached
|
||||
@@ -61,7 +64,8 @@ COPY php.ini $PHP_INI_DIR/conf.d/
|
||||
|
||||
# Install Laravel Envoy
|
||||
RUN composer global require "laravel/envoy=~1.0"
|
||||
|
||||
# Set working directory
|
||||
WORKDIR $WORKDIR
|
||||
|
||||
COPY ./entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
@@ -69,13 +73,14 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
# Set working directory
|
||||
WORKDIR $WORKDIR
|
||||
|
||||
|
||||
RUN usermod -u 1000 www-data
|
||||
RUN groupmod -g 1000 www-data
|
||||
|
||||
RUN chmod 755 $WORKDIR
|
||||
|
||||
|
||||
EXPOSE 9000
|
||||
# Run Supervisor
|
||||
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
|
||||
# entrypoint
|
||||
CMD [ "entrypoint" ]
|
||||
|
||||
31
README.md
31
README.md
@@ -1,3 +1,8 @@
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
# Laravel PHP-FPM Docker image
|
||||
|
||||
> 🐳 Docker image for a PHP-FPM container crafted to run Laravel or any php based applications.
|
||||
@@ -30,7 +35,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
php-fpm:
|
||||
image: jkaninda/laravel-php-fpm:<Tagname> or latest
|
||||
image: jkaninda/laravel-php-fpm:<tagname> or latest
|
||||
container_name: php-fpm
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
@@ -44,13 +49,13 @@ services:
|
||||
```
|
||||
## Laravel `artisan` command usage:
|
||||
### Open php-fpm
|
||||
```bash
|
||||
```sh
|
||||
docker-compose exec php-fpm /bin/bash
|
||||
|
||||
```
|
||||
|
||||
### Laravel migration
|
||||
```bash
|
||||
```sh
|
||||
php atisan migrate
|
||||
|
||||
```
|
||||
@@ -60,14 +65,17 @@ php atisan migrate
|
||||
version: '3'
|
||||
services:
|
||||
php-fpm:
|
||||
image: jkaninda/laravel-php-fpm:<Tagname> or latest
|
||||
image: jkaninda/laravel-php-fpm
|
||||
container_name: php-fpm
|
||||
working_dir: /var/www #Optional If you want to use a custom directory
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
#Project root
|
||||
- ./:/var/www/
|
||||
- ~/.ssh:/root/.ssh # If you use private CVS
|
||||
|
||||
environment:
|
||||
- APP_ENV=development # or production
|
||||
- WORKDIR=/var/www #Optional If you want to use a custom directory
|
||||
networks:
|
||||
- default #if you're using networks between containers
|
||||
#Nginx server
|
||||
@@ -79,13 +87,13 @@ services:
|
||||
- 80:80
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./nginx/conf.d/:/etc/nginx/conf.d/
|
||||
- ./default.conf:/etc/nginx/conf.d/default.conf
|
||||
networks:
|
||||
- default
|
||||
|
||||
```
|
||||
## Simple Nginx config file content
|
||||
### nginx/conf.d/default.conf
|
||||
### default.conf
|
||||
|
||||
```conf
|
||||
|
||||
@@ -94,12 +102,12 @@ server {
|
||||
index index.php index.html;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
##Root directory
|
||||
##Public directory
|
||||
root /var/www/public;
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
## PHP FPM ( php-fpm:9000 )
|
||||
## PHP FPM ( php-fpm:9000 ) or [servicename:9000]
|
||||
fastcgi_pass php-fpm:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
@@ -123,8 +131,11 @@ server {
|
||||
|
||||
```
|
||||
## Docker run
|
||||
```bash
|
||||
```sh
|
||||
docker-compose up -d
|
||||
|
||||
```
|
||||
|
||||
> P.S. please give a star if you like it :wink:
|
||||
|
||||
|
||||
|
||||
3
build.sh
Normal file → Executable file
3
build.sh
Normal file → Executable file
@@ -6,4 +6,5 @@ if [ $# -eq 0 ]
|
||||
tag=$1
|
||||
fi
|
||||
|
||||
docker build -t jkaninda/laravel-php-fpm:$tag .
|
||||
#docker build -t jkaninda/laravel-php-fpm:$tag .
|
||||
docker build -t jkaninda/php-fpm:$tag .
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
Red='\033[0;31m' # Red
|
||||
Green='\033[0;32m' # Green
|
||||
|
||||
echo ""
|
||||
echo "***********************************************************"
|
||||
echo " Starting LARAVEL PHP-FPM Docker Container "
|
||||
@@ -6,6 +9,7 @@ echo "***********************************************************"
|
||||
|
||||
set -e
|
||||
|
||||
## Create PHP-FPM worker process
|
||||
TASK=/etc/supervisor/conf.d/worker.conf
|
||||
touch $TASK
|
||||
cat > "$TASK" <<EOF
|
||||
@@ -22,10 +26,21 @@ stderr_logfile=/var/log/php-fpm_consumer.err.log
|
||||
stdout_logfile=/var/log/php-fpm_consumer.out.log
|
||||
user=root
|
||||
priority=100
|
||||
EOF
|
||||
|
||||
## Check if the artisan file exists
|
||||
if [ -f $WORKDIR/artisan ]; then
|
||||
echo "${Green} artisan file found, creating laravel supervisor config"
|
||||
##Create Laravel Scheduler process
|
||||
TASK=/etc/supervisor/conf.d/laravel-worker.conf
|
||||
touch $TASK
|
||||
cat > "$TASK" <<EOF
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
[program:Laravel-scheduler]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=/bin/sh -c "while [ true ]; do (php /var/www/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
|
||||
command=/bin/sh -c "while [ true ]; do (php $WORKDIR/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
numprocs=1
|
||||
@@ -35,15 +50,33 @@ redirect_stderr=true
|
||||
|
||||
[program:Laravel-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php /var/www/artisan queue:work --sleep=3 --tries=3
|
||||
command=php $WORKDIR/artisan queue:work --sleep=3 --tries=3
|
||||
autostart=true
|
||||
autorestart=true
|
||||
numprocs=2
|
||||
user=root
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/laravel_worker.log
|
||||
|
||||
EOF
|
||||
echo "${Green} Laravel supervisor config created"
|
||||
else
|
||||
echo "${Red} artisan file not found"
|
||||
fi
|
||||
#check if storage directory exists
|
||||
echo "Checking if storage directory exists"
|
||||
if [ -d "$STORAGE_DIR" ]; then
|
||||
echo "Directory $STORAGE_DIR exist. Fixing permissions..."
|
||||
chown -R www-data:www-data $STORAGE_DIR
|
||||
chmod -R 775 $STORAGE_DIR
|
||||
echo "${Green} Permissions fixed"
|
||||
|
||||
else
|
||||
echo "${Red} Directory $STORAGE_DIR does not exist"
|
||||
echo "Fixing permissions from $WORKDIR"
|
||||
chown -R www-data:www-data $WORKDIR/storage
|
||||
chmod -R 775 $WORKDIR/storage
|
||||
echo "${Green} Permissions fixed"
|
||||
fi
|
||||
|
||||
supervisord -c /etc/supervisor/supervisord.conf
|
||||
|
||||
|
||||
Reference in New Issue
Block a user