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

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
# Laravel PHP-FPM Docker image
|
# Laravel PHP-FPM Docker image
|
||||||
|
|
||||||
> 🐳 Docker image for a PHP-FPM container crafted to run Laravel or any php based applications.
|
> 🐳 Docker image for a PHP-FPM container crafted to run Laravel or any php based applications.
|
||||||
@@ -30,7 +35,7 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
php-fpm:
|
php-fpm:
|
||||||
image: jkaninda/laravel-php-fpm:<Tagname> or latest
|
image: jkaninda/laravel-php-fpm:<tagname> or latest
|
||||||
container_name: php-fpm
|
container_name: php-fpm
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
@@ -44,13 +49,13 @@ services:
|
|||||||
```
|
```
|
||||||
## Laravel `artisan` command usage:
|
## Laravel `artisan` command usage:
|
||||||
### Open php-fpm
|
### Open php-fpm
|
||||||
```bash
|
```sh
|
||||||
docker-compose exec php-fpm /bin/bash
|
docker-compose exec php-fpm /bin/bash
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Laravel migration
|
### Laravel migration
|
||||||
```bash
|
```sh
|
||||||
php atisan migrate
|
php atisan migrate
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -60,14 +65,17 @@ php atisan migrate
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
php-fpm:
|
php-fpm:
|
||||||
image: jkaninda/laravel-php-fpm:<Tagname> or latest
|
image: jkaninda/laravel-php-fpm
|
||||||
container_name: php-fpm
|
container_name: php-fpm
|
||||||
restart: unless-stopped
|
working_dir: /var/www #Optional If you want to use a custom directory
|
||||||
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
#Project root
|
#Project root
|
||||||
- ./:/var/www/
|
- ./:/var/www/
|
||||||
- ~/.ssh:/root/.ssh # If you use private CVS
|
- ~/.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:
|
networks:
|
||||||
- default #if you're using networks between containers
|
- default #if you're using networks between containers
|
||||||
#Nginx server
|
#Nginx server
|
||||||
@@ -79,13 +87,13 @@ services:
|
|||||||
- 80:80
|
- 80:80
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/var/www
|
- ./:/var/www
|
||||||
- ./nginx/conf.d/:/etc/nginx/conf.d/
|
- ./default.conf:/etc/nginx/conf.d/default.conf
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
|
|
||||||
```
|
```
|
||||||
## Simple Nginx config file content
|
## Simple Nginx config file content
|
||||||
### nginx/conf.d/default.conf
|
### default.conf
|
||||||
|
|
||||||
```conf
|
```conf
|
||||||
|
|
||||||
@@ -94,12 +102,12 @@ server {
|
|||||||
index index.php index.html;
|
index index.php index.html;
|
||||||
error_log /var/log/nginx/error.log;
|
error_log /var/log/nginx/error.log;
|
||||||
access_log /var/log/nginx/access.log;
|
access_log /var/log/nginx/access.log;
|
||||||
##Root directory
|
##Public directory
|
||||||
root /var/www/public;
|
root /var/www/public;
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
## PHP FPM ( php-fpm:9000 )
|
## PHP FPM ( php-fpm:9000 ) or [servicename:9000]
|
||||||
fastcgi_pass php-fpm:9000;
|
fastcgi_pass php-fpm:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
@@ -123,8 +131,11 @@ server {
|
|||||||
|
|
||||||
```
|
```
|
||||||
## Docker run
|
## Docker run
|
||||||
```bash
|
```sh
|
||||||
docker-compose up -d
|
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
|
tag=$1
|
||||||
fi
|
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,11 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
Red='\033[0;31m' # Red
|
||||||
|
Green='\033[0;32m' # Green
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "***********************************************************"
|
echo "***********************************************************"
|
||||||
echo " Starting LARAVEL PHP-FPM Docker Container "
|
echo " Starting LARAVEL PHP-FPM Docker Container "
|
||||||
echo "***********************************************************"
|
echo "***********************************************************"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
## Create PHP-FPM worker process
|
||||||
TASK=/etc/supervisor/conf.d/worker.conf
|
TASK=/etc/supervisor/conf.d/worker.conf
|
||||||
touch $TASK
|
touch $TASK
|
||||||
cat > "$TASK" <<EOF
|
cat > "$TASK" <<EOF
|
||||||
@@ -22,28 +26,57 @@ stderr_logfile=/var/log/php-fpm_consumer.err.log
|
|||||||
stdout_logfile=/var/log/php-fpm_consumer.out.log
|
stdout_logfile=/var/log/php-fpm_consumer.out.log
|
||||||
user=root
|
user=root
|
||||||
priority=100
|
priority=100
|
||||||
|
|
||||||
[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"
|
|
||||||
autostart=true
|
|
||||||
autorestart=true
|
|
||||||
numprocs=1
|
|
||||||
user=root
|
|
||||||
stdout_logfile=/var/log/laravel_scheduler.out.log
|
|
||||||
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
|
|
||||||
autostart=true
|
|
||||||
autorestart=true
|
|
||||||
numprocs=2
|
|
||||||
user=root
|
|
||||||
redirect_stderr=true
|
|
||||||
stdout_logfile=/var/log/laravel_worker.log
|
|
||||||
|
|
||||||
EOF
|
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 $WORKDIR/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
numprocs=1
|
||||||
|
user=root
|
||||||
|
stdout_logfile=/var/log/laravel_scheduler.out.log
|
||||||
|
redirect_stderr=true
|
||||||
|
|
||||||
|
[program:Laravel-worker]
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
|
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
|
supervisord -c /etc/supervisor/supervisord.conf
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user