当前位置: 首页 > news >正文

衡水做企业网站的公司互联网网络推广公司

衡水做企业网站的公司,互联网网络推广公司,网站开发数据库技术,杂志社网站建设方案书为 Laravel 提供生产模式下的容器化环境:打造现代开发环境的终极指南 在现代开发中,容器化已经成为一种趋势。使用 Docker 可以让我们轻松地管理和部署应用程序。本文将带你一步步构建一个高效的 Laravel 容器化环境,确保你的应用程序在开发…

为 Laravel 提供生产模式下的容器化环境:打造现代开发环境的终极指南

在现代开发中,容器化已经成为一种趋势。使用 Docker 可以让我们轻松地管理和部署应用程序。本文将带你一步步构建一个高效的 Laravel 容器化环境,确保你的应用程序在开发和生产环境中都能顺畅运行。

功能:

  1. 拆分队列运行容器和web服务容器
  2. 开发环境和生产环境分离
  3. 日志监控
  4. 方便升级
  5. 可推送K8s环境,实现弹性伸缩.

最终文件结构,laravel 源代码在 src中.
在这里插入图片描述

一、Docker Compose 文件配置

首先,我们需要创建一个 docker-compose.yml 文件,这个文件定义了我们的服务及其配置。

version: '3'
services:      app:build:context: .dockerfile: Dockerfileenvironment:- COMPOSER_PROCESS_TIMEOUT=6000      ports:- 8290:80volumes:- /etc/hosts:/etc/hosts      - ../src:/var/www/htmllogging: # 可以使用loki将log采集,并在grafana中设置监控和告警 driver: lokioptions:loki-url: "http://localhost:3100/loki/api/v1/push"loki-retries: "5"loki-batch-size: "100"no-file: "true"command: bash -c "chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache && service nginx start && php-fpm"worker:build:context: .dockerfile: Dockerfileenvironment:- COMPOSER_PROCESS_TIMEOUT=6000      command: php artisan horizonvolumes:- /etc/hosts:/etc/hosts    - ../src:/var/www/html# laravel 的源代码我们可以放在上层文件夹中logging:driver: lokioptions:loki-url: "http://localhost:3100/loki/api/v1/push"loki-retries: "5"loki-batch-size: "100"no-file: "true"      links:- app
二、Dockerfile 配置

接下来,我们需要编写 Dockerfile 文件,定义应用程序的运行环境。这样可以很容易的拆分开开发和生产环境

# Use the base PHP image with the specified version
FROM php:8.2.14-fpm# Set the working directory inside the container
WORKDIR /var/www/html# Update package lists and install necessary dependencies
RUN apt-get update && apt-get install -y \curl \libpng-dev \libonig-dev \libxml2-dev \zip \unzip \libzip-dev \libjpeg-dev \libfreetype6-dev \libssl-dev \libcurl4-openssl-dev # Install Nginx
RUN apt-get install -y nginx# Install PHP extensions required by your application
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip 
RUN docker-php-ext-install soap
RUN docker-php-ext-install ctype 
RUN docker-php-ext-install curl
RUN docker-php-ext-install dom
RUN docker-php-ext-install fileinfo 
RUN docker-php-ext-install filter
RUN docker-php-ext-install session
RUN docker-php-ext-install xml
RUN docker-php-ext-install ftp# Install and enable the Redis extension
RUN pecl install redis && docker-php-ext-enable redis# Install Xdebug extension
# RUN pecl install xdebug && docker-php-ext-enable xdebug# Copy the application files into the container
# COPY . .# Change ownership of directories used by the application
# RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cacheRUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer# RUN composer install --optimize-autoloader --no-devCOPY nginx.conf /etc/nginx/sites-available/defaultRUN rm /var/www/html/index.nginx-debian.html# Expose ports 80 and 443 to the outside world
EXPOSE 80
EXPOSE 443# Set the default command to run when the container starts
CMD service nginx start && php-fpm
三、Nginx 配置

创建一个 nginx.conf 文件,配置 Nginx 以服务我们的 Laravel 应用程序。

server {listen 80;server_name localhost;root /var/www/html/public;index index.php index.html index.htm;location / {try_files $uri $uri/ /index.php?$query_string;}location ~ \.php$ {include fastcgi_params;fastcgi_pass  127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_read_timeout 3000;fastcgi_connect_timeout 3000;fastcgi_send_timeout 3000;}location ~ /\.ht {deny all;}
}
四、Makefile 配置

为了更方便地管理 Docker 容器,我们可以使用 Makefile 定义常用的命令。

install: build docker compose run --rm app composer install docker compose run --rm app cp -f .env.prod .envupdate:docker compose run --rm app composer updatecache:docker compose run --rm app php artisan route:cachedocker compose run --rm app php artisan config:cachedocker compose run --rm app composer dump-autoload  -obuild: build-app build-work build-app:docker compose -f docker-compose.yml build appbuild-work:docker compose -f docker-compose.yml build workerstart:docker compose -f docker-compose.yml up -dstop:docker compose -f docker-compose.yml downrestart: docker compose -f docker-compose.yml restartexec:docker compose exec app /bin/bashinfo:docker compose run --rm app php -i

通过以上配置,我们可以轻松地为 Laravel 应用提供一个容器化环境。这不仅提高了开发效率,还确保了生产环境的稳定性。赶快试试吧!喜欢这篇文章的话,不要忘了点赞、收藏和分享哦!


希望这篇文章对你有帮助!如果有任何疑问或建议,欢迎在评论区留言。你的支持是我继续创作的动力!

http://www.hrbkazy.com/news/27674.html

相关文章:

  • 做网站能改吗网站制作费用一览表
  • 学做网站论坛会员怎么样如何做好网络营销推广
  • 海南建设工程股份有限公司网站seo优化排名易下拉效率
  • 网站备案是否关闭郑州搜索引擎优化公司
  • 质量好网站建设商家网站网络推广推广
  • wifi扩展器做网站现在百度推广有用吗
  • 猪八戒设计网站如何做兼职广州百度seo代理
  • 深圳建设网站top028google收录查询
  • 网站建设微信运营推广新手怎么做网络推广
  • 网页制作与前端开发西安优化网站公司
  • 苏州吴江建设局招投标网站标题优化
  • 闲置服务器做网站挣钱黑科技引流工具
  • 陇南市响应式网站建设惊艳的网站设计
  • 闲鱼做网站靠谱吗网络推广长沙网络推广
  • wordpress指定id文章seo做关键词怎么收费的
  • 郑州网站建设三猫网络免费推广方法
  • 营销策划书怎么写格式芭嘞seo
  • 清河县做网站故事式的软文广告例子
  • 贵阳58同城做网站最牛餐饮营销手段
  • 建设云购网站搜一搜排名点击软件
  • 小说网站开发环境那个号东莞网站制作公司联系方式
  • 找做牙工作上哪个网站网站下载
  • 上海长城建设有限公司网站比百度强大的搜索引擎
  • 政府网站集约化建设存在的问题百度自己的宣传广告
  • 福田做网站报价外包网站
  • 做投标网站条件百度门店推广
  • 杭州 做网站广州谷歌优化
  • 新手学做网站代码太原百度推广排名优化
  • 网站开发外包费用的会计分录保定seo外包服务商
  • python18前端seo是什么意思