I'm having trouble to config my Laravel application to run on my web server.
The problem is that I'm getting the Welcome to nginx! page and not my laravel app when using the browser.
The set up is the following
- It's a server running on Ubuntu 20.04 LTS
- The nginx service is installed directly on the machine (not using docker)
- I have a docker-compose to run 3 containers: postgres (database) + keycloak (auth server) + My laravel app.
Keycloak and the postgres db are running like charms for months.
Laravel app path -> /var/www/dev.mycompany.com/
Laravel Dockerfile -> /var/www/dev.mycompany.com/Dockerfile
FROM php:8.0-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www.dev.mycompany.com
# Set working directory
WORKDIR /var/www.dev.mycompany.com
# Install dependencies
RUN apt update && apt install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www.dev.mycompany.com
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Nginx - Laravel Config path: /etc/nginx/sites-available/www/dev.mycompany.com HTTP is not configured yet, I was just testing with 443 before writing a rule to redirect all none https requests
server {
listen 443;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/dev.mycompany.com;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass dev.mycompany.com:9000;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
docker-compose.yml - path: srv/
version: '3.1'
volumes:
postgres_data:
driver: local
services:
postgres:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: **********************
POSTGRES_PASSWORD: **********************
networks:
- app-network
keycloak:
image: jboss/keycloak:latest
restart: unless-stopped
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
DB_DATABASE: keycloak
DB_USER: **********************
DB_PASSWORD: **********************
KEYCLOAK_USER: ************
KEYCLOAK_PASSWORD: **********************
PROXY_ADDRESS_FORWARDING: "true"
ports:
- 8080:8080
depends_on:
- postgres
networks:
- app-network
app-backend:
image: digitalocean.com/php
build:
context: .
dockerfile: /var/www/dev.mycompany.com/Dockerfile
restart: unless-stopped
container_name: web-backend
tty: true
environment:
SERVICE_NAME: app
SERICE_TAGS: dev
working_dir: /var/www/dev.mycompany.com
volumes:
- /var/www/dev.mycompany.com:/var/www/dev.mycompany.com
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
networks:
app-network:
driver: bridge
Thanks A LOT by advance
NotGael
#fastcgi_pass dev.mycompany.be:9000;commented out? The Dockerfile runsphp-fpmand exposes port 9000. Since all containers are running on the same machine, the php container should be accessible via localhost withfastcgi_pass localhost:9000fastcgi_pass localhost:9000; #fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;COPY composer.lock composer.json /var/www/dev.mycompany.com WORKDIR /var/www/dev.mycompany.comChanges/var/www.dev.mycompany.com to /var/www/dev.mycompany.comBut still ... nothing changes Entering into the container I've checked that the app files are in /var/www/dev.mycompany.com and that the Laravel app is working properly. The app has been builded and the key generated, ... php artisan is working just fine ....