溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Laravel應(yīng)用怎么部署

發(fā)布時(shí)間:2022-12-07 09:24:00 來(lái)源:億速云 閱讀:148 作者:iii 欄目:編程語(yǔ)言

這篇文章主要講解了“Laravel應(yīng)用怎么部署”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Laravel應(yīng)用怎么部署”吧!

  • 本文 php 基礎(chǔ)鏡像使用:php:7.3-apache

  • 本文 laravel 版本為:laravel:5.8.*

一、 準(zhǔn)備我們的 laravel 應(yīng)用

# 運(yùn)行 mix 命令,打包 js、css、img 文件,如果沒(méi)有用到 mix 這一步可以省略
npm install
npm run production
# 安裝 composer.lock 中的依賴
composer install --ignore-platform-reqs --optimize-autoloader --no-dev

二、 準(zhǔn)備 apache 配置文件 docker/000-default.conf

<virtualhost *:80>
 # the servername directive sets the request scheme, hostname and port that
 # the server uses to identify itself. this is used when creating
 # redirection urls. in the context of virtual hosts, the servername
 # specifies what hostname must appear in the request's host: header to
 # match this virtual host. for the default virtual host (this file) this
 # value is not decisive as it is used as a last resort host regardless.
 # however, you must set it for any further virtual host explicitly.
 #servername www.example.com

 serveradmin liuzhaowei55@gmail.com
 documentroot /var/www/html/public

 # available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 # error, crit, alert, emerg.
 # it is also possible to configure the loglevel for particular
 # modules, e.g.
 #loglevel info ssl:warn

 errorlog ${apache_log_dir}/error.log
 customlog ${apache_log_dir}/access.log combined

 # for most configuration files from conf-available/, which are
 # enabled or disabled at a global level, it is possible to
 # include a line for only one particular virtual host. for example the
 # following line enables the cgi configuration for this host only
 # after it has been globally disabled with "a2disconf".
 #include conf-available/serve-cgi-bin.conf
</virtualhost>

三、 準(zhǔn)備 dockerfile 文件

from php:7.3-apache

label maintainer="liuzhaowei55@gmail.com"

# 設(shè)置時(shí)區(qū)
arg tz=asia/shanghai
env tz ${tz}
run ln -snf /usr/share/zoneinfo/$tz /etc/localtime && echo $tz > /etc/timezone

# 安裝軟件 cron
run set -eux \
 && apt-get update \
 && apt-get install -y --no-install-recommends cron \
 && apt-get autoremove \
 && apt-get autoclean \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
# 安裝拓展
env php_extension \
 pdo_mysql \
 bcmath
env pecl_extension \
 redis
run docker-php-ext-install $php_extension \
 && pecl install $pecl_extension \
 && docker-php-ext-enable $pecl_extension \
    opcache \
 && a2enmod rewrite
 
# 訪問(wèn)端口
expose 80

arg app_env=development
env app_env ${app_env}

copy --chown=www-data:www-data . /var/www/html
copy docker/000-default.conf /etc/apache2/sites-available/000-default.conf
workdir /var/www/html

四、準(zhǔn)備 dockerignore 文件:.dockerignore(非必需)

/node_modules
/.dockerignore
/dockerfile

五、準(zhǔn)備鏡像入口文件:docker-entrypoint.sh(非必需)

注意一下,此文件需要執(zhí)行權(quán)限,不過(guò)此入口文件不是必須的,只是為了在應(yīng)用運(yùn)行前執(zhí)行一些緩存命令,具體可以了解一下。

#!/usr/bin/env bash

php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache

apache2-foreground

六、運(yùn)行鏡像

docker run -p 80:80 .

感謝各位的閱讀,以上就是“Laravel應(yīng)用怎么部署”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Laravel應(yīng)用怎么部署這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI