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

中山的网站建设公司建设网站制作汉狮团队

中山的网站建设公司,建设网站制作汉狮团队,深圳低价做网站,seo短视频网页入口引流免费为 Laravel 提供生产模式下的容器化环境#xff1a;打造现代开发环境的终极指南 在现代开发中#xff0c;容器化已经成为一种趋势。使用 Docker 可以让我们轻松地管理和部署应用程序。本文将带你一步步构建一个高效的 Laravel 容器化环境#xff0c;确保你的应用程序在开发…为 Laravel 提供生产模式下的容器化环境打造现代开发环境的终极指南 在现代开发中容器化已经成为一种趋势。使用 Docker 可以让我们轻松地管理和部署应用程序。本文将带你一步步构建一个高效的 Laravel 容器化环境确保你的应用程序在开发和生产环境中都能顺畅运行。 功能: 拆分队列运行容器和web服务容器开发环境和生产环境分离日志监控方便升级可推送K8s环境实现弹性伸缩. 最终文件结构laravel 源代码在 src中. 一、Docker Compose 文件配置 首先我们需要创建一个 docker-compose.yml 文件这个文件定义了我们的服务及其配置。 version: 3 services: app:build:context: .dockerfile: Dockerfileenvironment:- COMPOSER_PROCESS_TIMEOUT6000 ports:- 8290:80volumes:- /etc/hosts:/etc/hosts - ../src:/var/www/htmllogging: # 可以使用loki将log采集并在grafana中设置监控和告警 driver: lokioptions:loki-url: http://localhost:3100/loki/api/v1/pushloki-retries: 5loki-batch-size: 100no-file: truecommand: bash -c chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache service nginx start php-fpmworker:build:context: .dockerfile: Dockerfileenvironment:- COMPOSER_PROCESS_TIMEOUT6000 command: php artisan horizonvolumes:- /etc/hosts:/etc/hosts - ../src:/var/www/html# laravel 的源代码我们可以放在上层文件夹中logging:driver: lokioptions:loki-url: http://localhost:3100/loki/api/v1/pushloki-retries: 5loki-batch-size: 100no-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 --filenamecomposer# 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.hkea.cn/news/14381741/

相关文章:

  • 行业论坛网站青海商城网站建设
  • 苏州外贸网站建设公司wordpress 仿 主题下载
  • 保养车哪个网站做的好网站定位的核心意义
  • 电子商务模拟实训报告企业网站建设外贸业务流程图
  • wordpress如何搭建一个购物网站网站建设可以用350摸板
  • 导航类网站怎么做孝感建设局网站
  • php网站系统关键词推广方案
  • 中文网站建设技术srcache缓存wordpress
  • 站嗨建站安卓软件下载安装
  • 没有备案的交易网站wordpress域名 文件
  • 清远网站推广优化公司网站建设自建服务器
  • 如何做360网站优化怎么做网站推广电话
  • 网站建设灵寿海外网站有哪些
  • 体育网站模版专业优定软件网站建设
  • 查询网站ftp地址海南封岛最新消息
  • php网站建设模板logo设计 公司 免费
  • 一个网站的基调网站建设哪个便宜
  • 公司已经有域名 怎么建网站安徽专业做网站的公司
  • 网站建设程序流程图如何制作动漫网站模板下载
  • 中国建设招投标网站清远建设局网站
  • 青岛网站设计微动力重庆建设工程管理网
  • 如何做可以微信转发的网站龙岗专业网站建设
  • 网站设计理念上海网站建设,迈
  • 做公众好号的网站公司网站可以自己做么
  • 手机网站怎么制作软件html的所有代码大全
  • 建站基础:wordpress安装教程图解 - 天缘博客wordpress 数据库 破解版
  • 请简述网站制作流程jsp网站怎么运行
  • 上海备案证查询网站查询网站查询网络营销策略案例
  • 各大网站提交入口网站搜索排名优化
  • 网站建设插件代码大全网站优化图片