PHP + Laravel + Nginx App Setup is slow to load

PHP + Laravel Dockerfile :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM php:7.3-fpm AS builder
# Clean-up Repo list
RUN rm -rf /var/lib/apt/lists/*
RUN curl -sS -o /tmp/icu.tar.gz -L https://github.com/unicode-org/icu/releases/download/release-57-1/icu4c-57_1-src.tgz && tar -zxf /tmp/icu.tar.gz -C /tmp && cd /tmp/icu/source/ && ./configure --prefix=/usr/local && make && make install
# Install common php extension dependencies
RUN apt-get clean && apt-get update && apt-get install -y
coreutils
libfreetype-dev
libjpeg62-turbo-dev
libpng-dev
zlib1g-dev
libzip-dev
unzip
git
# Enable Apache mod_rewrite for URL rewriting
RUN a2enmod rewrite
# Install PHP Extensions
RUN mkdir -p /usr/src/php/ext/redis;
curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/5.3.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1;
docker-php-ext-install redis
RUN docker-php-ext-configure zip &&
docker-php-ext-install zip
RUN docker-php-ext-configure gettext &&
docker-php-ext-install gettext
RUN docker-php-ext-configure intl &&
docker-php-ext-install intl
RUN docker-php-ext-configure pdo_mysql &&
docker-php-ext-install pdo_mysql
RUN docker-php-ext-configure mysqli &&
docker-php-ext-install mysqli &&
docker-php-ext-enable mysqli
RUN apt-get update && apt-get install -y
libfreetype6-dev
libjpeg62-turbo-dev
libpng-dev
&& docker-php-ext-install -j$(nproc) iconv
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
&& docker-php-ext-install -j$(nproc) gd
COPY apache-site-config/develop.conf /etc/apache2/sites-available/develop.conf
# Configure Apache DocumentRoot to point to Laravel's public directory
# and update Apache configuration files
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# Copy existing application directory
COPY . /var/www/html
# Set working directory
WORKDIR /var/www/html
RUN chown -R www-data:www-data /var/www/html
&& chmod -R 775 /var/www/app/storage
# Install composer
COPY --from=composer:1.6.3 /usr/bin/composer /usr/local/bin/composer
RUN mkdir -p ~/.ssh &&
chmod 0700 ~/.ssh &&
ssh-keyscan bitbucket.org > ~/.ssh/known_hosts
# Copy composer.json to workdir
COPY composer.* ./
# RUN omposer install & Clone private repository
RUN --mount=type=ssh composer install
COPY dotenv/.env.development .env
ARG NODE_VERSION=8.16.2
RUN curl https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz | tar -xz -C /usr/local --strip-components 1
RUN npm install
RUN npm run dev
# Command to start the Artisan server
# CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"]
</code>
<code>FROM php:7.3-fpm AS builder # Clean-up Repo list RUN rm -rf /var/lib/apt/lists/* RUN curl -sS -o /tmp/icu.tar.gz -L https://github.com/unicode-org/icu/releases/download/release-57-1/icu4c-57_1-src.tgz && tar -zxf /tmp/icu.tar.gz -C /tmp && cd /tmp/icu/source/ && ./configure --prefix=/usr/local && make && make install # Install common php extension dependencies RUN apt-get clean && apt-get update && apt-get install -y coreutils libfreetype-dev libjpeg62-turbo-dev libpng-dev zlib1g-dev libzip-dev unzip git # Enable Apache mod_rewrite for URL rewriting RUN a2enmod rewrite # Install PHP Extensions RUN mkdir -p /usr/src/php/ext/redis; curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/5.3.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; docker-php-ext-install redis RUN docker-php-ext-configure zip && docker-php-ext-install zip RUN docker-php-ext-configure gettext && docker-php-ext-install gettext RUN docker-php-ext-configure intl && docker-php-ext-install intl RUN docker-php-ext-configure pdo_mysql && docker-php-ext-install pdo_mysql RUN docker-php-ext-configure mysqli && docker-php-ext-install mysqli && docker-php-ext-enable mysqli RUN apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && docker-php-ext-install -j$(nproc) iconv && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd COPY apache-site-config/develop.conf /etc/apache2/sites-available/develop.conf # Configure Apache DocumentRoot to point to Laravel's public directory # and update Apache configuration files ENV APACHE_DOCUMENT_ROOT=/var/www/html/public RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf # Copy existing application directory COPY . /var/www/html # Set working directory WORKDIR /var/www/html RUN chown -R www-data:www-data /var/www/html && chmod -R 775 /var/www/app/storage # Install composer COPY --from=composer:1.6.3 /usr/bin/composer /usr/local/bin/composer RUN mkdir -p ~/.ssh && chmod 0700 ~/.ssh && ssh-keyscan bitbucket.org > ~/.ssh/known_hosts # Copy composer.json to workdir COPY composer.* ./ # RUN omposer install & Clone private repository RUN --mount=type=ssh composer install COPY dotenv/.env.development .env ARG NODE_VERSION=8.16.2 RUN curl https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz | tar -xz -C /usr/local --strip-components 1 RUN npm install RUN npm run dev # Command to start the Artisan server # CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"] </code>
FROM php:7.3-fpm AS builder

# Clean-up Repo list
RUN rm -rf /var/lib/apt/lists/*

RUN curl -sS -o /tmp/icu.tar.gz -L https://github.com/unicode-org/icu/releases/download/release-57-1/icu4c-57_1-src.tgz && tar -zxf /tmp/icu.tar.gz -C /tmp && cd /tmp/icu/source/ && ./configure --prefix=/usr/local && make && make install

# Install common php extension dependencies
RUN apt-get clean && apt-get update && apt-get install -y 
    coreutils 
    libfreetype-dev 
    libjpeg62-turbo-dev 
    libpng-dev 
    zlib1g-dev 
    libzip-dev 
    unzip 
    git

# Enable Apache mod_rewrite for URL rewriting
RUN a2enmod rewrite

# Install PHP Extensions
RUN mkdir -p /usr/src/php/ext/redis; 
    curl -fsSL --ipv4 https://github.com/phpredis/phpredis/archive/5.3.2.tar.gz | tar xvz -C "/usr/src/php/ext/redis" --strip 1; 
    docker-php-ext-install redis

RUN docker-php-ext-configure zip && 
    docker-php-ext-install zip

RUN docker-php-ext-configure gettext && 
    docker-php-ext-install gettext

RUN docker-php-ext-configure intl && 
    docker-php-ext-install intl

RUN docker-php-ext-configure pdo_mysql && 
    docker-php-ext-install  pdo_mysql

RUN docker-php-ext-configure mysqli && 
    docker-php-ext-install  mysqli && 
    docker-php-ext-enable mysqli

RUN apt-get update && apt-get install -y 
        libfreetype6-dev 
        libjpeg62-turbo-dev 
        libpng-dev 
    && docker-php-ext-install -j$(nproc) iconv 
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ 
    && docker-php-ext-install -j$(nproc) gd

COPY apache-site-config/develop.conf /etc/apache2/sites-available/develop.conf
# Configure Apache DocumentRoot to point to Laravel's public directory
# and update Apache configuration files
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/example/current/public!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Copy existing application directory
COPY . /var/www/html

# Set working directory
WORKDIR /var/www/html

RUN chown -R www-data:www-data /var/www/html 
    && chmod -R 775 /var/www/app/storage

# Install composer
COPY --from=composer:1.6.3 /usr/bin/composer /usr/local/bin/composer

RUN mkdir -p ~/.ssh && 
    chmod 0700 ~/.ssh && 
    ssh-keyscan bitbucket.org > ~/.ssh/known_hosts

# Copy composer.json to workdir
COPY composer.* ./
# RUN omposer install & Clone private repository
RUN --mount=type=ssh composer install

COPY dotenv/.env.development .env

ARG NODE_VERSION=8.16.2
RUN curl https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz | tar -xz -C /usr/local --strip-components 1
RUN npm install
RUN npm run dev
# Command to start the Artisan server
# CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"]

This service listen at website:8000

Nginx Config :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> # limit_req_zone $binary_remote_addr zone=login:10m rate=25r/s;
# upstream website {
# server website:8000;
# }
upstream assets {
server poc.assets.example.com:80;
}
upstream drupal {
server drupal.cms-prod.svc.cluster.local:80;
}
server {
listen 80 default_server;
server_name localhost;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 30;
send_timeout 30;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;
location / {
proxy_pass http://website:8000;
}
location /images/ {
proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/;
proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/ /images/;
}
location /toolbox/ {
proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/;
proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/ /toolbox/;
}
location /downloads/ {
proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/;
proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/ /downloads/;
}
location /sites/default/files/ {
proxy_pass http://drupal/sites/default/files/;
proxy_redirect http://drupal/sites/default/files/ /sites/default/files/;
}
location /nginx_status {
stub_status on;
allow all;
}
}
</code>
<code> # limit_req_zone $binary_remote_addr zone=login:10m rate=25r/s; # upstream website { # server website:8000; # } upstream assets { server poc.assets.example.com:80; } upstream drupal { server drupal.cms-prod.svc.cluster.local:80; } server { listen 80 default_server; server_name localhost; proxy_connect_timeout 30; proxy_send_timeout 30; proxy_read_timeout 30; send_timeout 30; sendfile on; tcp_nopush on; tcp_nodelay on; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component; location / { proxy_pass http://website:8000; } location /images/ { proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/; proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/ /images/; } location /toolbox/ { proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/; proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/ /toolbox/; } location /downloads/ { proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/; proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/ /downloads/; } location /sites/default/files/ { proxy_pass http://drupal/sites/default/files/; proxy_redirect http://drupal/sites/default/files/ /sites/default/files/; } location /nginx_status { stub_status on; allow all; } } </code>
    # limit_req_zone $binary_remote_addr zone=login:10m rate=25r/s;

    # upstream website {
    #     server website:8000;
    # }

    upstream assets {
        server poc.assets.example.com:80;
    }

    upstream drupal {
        server drupal.cms-prod.svc.cluster.local:80;
    }

    server {
        listen         80 default_server;
        server_name    localhost;
        proxy_connect_timeout 30;
        proxy_send_timeout   30;
        proxy_read_timeout   30;
        send_timeout         30;

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;

        gzip on;
        gzip_disable "msie6";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types
            application/atom+xml
            application/javascript
            application/json
            application/rss+xml
            application/vnd.ms-fontobject
            application/x-font-ttf
            application/x-web-app-manifest+json
            application/xhtml+xml
            application/xml
            font/opentype
            image/svg+xml
            image/x-icon
            text/css
            text/plain
            text/x-component;


        location / {
             proxy_pass http://website:8000;
        }

        location /images/ {
            proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/;
            proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/images/ /images/;
        }

        location /toolbox/ {
            proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/;
            proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/toolbox/ /toolbox/;
        }

        location /downloads/ {
            proxy_pass http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/;
            proxy_redirect http://dev.example.com.s3-website-us-west-2.amazonaws.com/assets/downloads/ /downloads/;
        }

        location /sites/default/files/ {
            proxy_pass http://drupal/sites/default/files/;
            proxy_redirect http://drupal/sites/default/files/ /sites/default/files/;
        }

        location /nginx_status {
              stub_status on;
              allow all;
        }

    }

All requests for dev.example.com hits nginx first and requests are forwarded to PHP + Laravel App. This setup is deployed Kubernetes.

But this Webpage is taking too long to load in browser.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật