{"id":1755,"date":"2022-11-16T19:02:21","date_gmt":"2022-11-16T11:02:21","guid":{"rendered":"https:\/\/qishiya.com\/?p=1755"},"modified":"2022-11-16T19:02:47","modified_gmt":"2022-11-16T11:02:47","slug":"1755","status":"publish","type":"post","link":"https:\/\/qishiya.com\/?p=1755","title":{"rendered":"<strong>Laravel Docker Centos8 \u4f7f\u7528<\/strong>"},"content":{"rendered":"\n<p>fanyi \u8fd9\u4e2a\u5c0f\u5de5\u5177\uff0c\u4ee5\u524d\u662f\u76f4\u63a5\u8dd1\u5728\u817e\u8baf\u4e91\u7684\u8f7b\u91cf\u670d\u52a1\u5668\u4e0a\u7684\uff0c\u7528 Golang \u5199\u7684\uff0c\u6700\u8fd1\u52a0\u4e86\u4e00\u4e2a\u5c0f\u529f\u80fd\uff0c\u7528 php \u91cd\u5199\u4e86\uff0cphp \u5c31\u8981\u642d\u5efa\u5404\u79cd\u73af\u5883\uff0c\u76f4\u63a5\u5728\u817e\u8baf\u4e91\u7684\u8f7b\u91cf\u670d\u52a1\u5668\u4e0a\u7f16\u8bd1 php \u4e0d\u6210\u529f\uff0c\u4e3b\u8981\u662f\u4f60 cpu \u9ad8\uff0c\u4ed6\u5c31\u76f4\u63a5\u7ed9\u4f60 kill \u4e86\uff0c\u6240\u4ee5\u5c31\u7528 docker \u6765\u89e3\u51b3\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_61 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ff6200;color:#ff6200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ff6200;color:#ff6200\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E6%9E%84%E5%BB%BA_PHP_%E7%9A%84%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83\" title=\"\u6784\u5efa PHP \u7684\u8fd0\u884c\u73af\u5883\">\u6784\u5efa PHP \u7684\u8fd0\u884c\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E7%BC%96%E6%8E%92%E6%96%87%E4%BB%B6\" title=\"\u7f16\u6392\u6587\u4ef6\">\u7f16\u6392\u6587\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E5%9D%91\" title=\"\u5751\">\u5751<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/qishiya.com\/?p=1755\/#Nginx_%E9%85%8D%E7%BD%AE\" title=\"Nginx \u914d\u7f6e\">Nginx \u914d\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E8%B4%9F%E8%BD%BD_nginx_%E9%85%8D%E7%BD%AE\" title=\"\u8d1f\u8f7d nginx \u914d\u7f6e\">\u8d1f\u8f7d nginx \u914d\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E5%9D%91-2\" title=\"\u5751\">\u5751<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/qishiya.com\/?p=1755\/#Laravel_%E9%85%8D%E7%BD%AE\" title=\"Laravel \u914d\u7f6e\">Laravel \u914d\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/qishiya.com\/?p=1755\/#laravel_%E5%88%9D%E5%A7%8B%E5%8C%96\" title=\"laravel \u521d\u59cb\u5316\">laravel \u521d\u59cb\u5316<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/qishiya.com\/?p=1755\/#%E5%8F%82%E8%80%83\" title=\"\u53c2\u8003\">\u53c2\u8003<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%9E%84%E5%BB%BA_PHP_%E7%9A%84%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83\"><\/span>\u6784\u5efa PHP \u7684\u8fd0\u884c\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ece php:8.1-fpm \u5f00\u59cb\u6784\u5efa\uff0c\u5b89\u88c5\u4e0a\u76f8\u5173\u4f9d\u8d56\uff0c\u7136\u540e\u8bbe\u7f6e\u8fd0\u884c\u7528\u6237\u7684\u76f8\u5173\u6743\u9650\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim Dockerfile<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM php:8.1-fpm\n\n# Arguments defined in docker-compose.yml\nARG user\nARG uid\n\n# Install system dependencies\nRUN apt-get update &amp;&amp; apt-get install -y \\\n    git \\\n    curl \\\n    libpng-dev \\\n    libonig-dev \\\n    libxml2-dev \\\n    zip \\\n    unzip\n\n# Clear cache\nRUN apt-get clean &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\n# Install PHP extensions\nRUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd\n\n# Get latest Composer\nCOPY --from=composer:latest \/usr\/bin\/composer \/usr\/bin\/composer\n\n# Create system user to run Composer and Artisan Commands\nRUN useradd -G www-data,root -u $uid -d \/home\/$user $user\nRUN mkdir -p \/home\/$user\/.composer &amp;&amp; \\\n    chown -R $user:$user \/home\/$user\n\n\n# Set working directory\nWORKDIR \/var\/www\n\nUSER $user<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%BC%96%E6%8E%92%E6%96%87%E4%BB%B6\"><\/span>\u7f16\u6392\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u628a PHP\uff0cnginx\uff0cmysql 8.0 \u7f16\u6392\u5728\u4e00\u8d77\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim docker-compose.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>version: \"3.7\"\nservices:\n  app:\n    build:\n      args:\n        user: lighthouse\n        uid: 1000\n      context: .\/\n      dockerfile: Dockerfile\n    image: travellist\n    container_name: travellist-app\n    restart: unless-stopped\n    working_dir: \/var\/www\/\n    volumes:\n      - .\/:\/var\/www\n    networks:\n      - travellist\n\n  db:\n    image: mysql:8.0\n    container_name: travellist-db\n    restart: unless-stopped\n    environment:\n      MYSQL_DATABASE: ${DB_DATABASE}\n      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}\n      MYSQL_PASSWORD: ${DB_PASSWORD}\n      MYSQL_USER: ${DB_USERNAME}\n      SERVICE_TAGS: dev\n      SERVICE_NAME: mysql\n    volumes:\n      - .\/mysql\/:\/var\/lib\/mysql\n    networks:\n      - travellist\n\n  nginx:\n    image: nginx:alpine\n    container_name: travellist-nginx\n    restart: unless-stopped\n    ports:\n      - 8000:80\n    volumes:\n      - .\/:\/var\/www\n      - .\/docker-compose\/nginx:\/etc\/nginx\/conf.d\/\n    networks:\n      - travellist\n\nnetworks:\n  travellist:\n    driver: bridge<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%9D%91\"><\/span>\u5751<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6743\u9650\u7684\u95ee\u9898\uff0c\u5982\u679c php \u6ca1\u6709\u5199\u7684\u6743\u9650\uff0c\u4e00\u5b9a\u662f user: lighthouse\uff0c uid: 1000<br>\u8bbe\u7f6e\u7684\u4e0d\u5bf9\uff0c\u8fd9\u4e2a user \u5fc5\u987b\u5728\u7cfb\u7edf\u4e2d\u5b58\u5728\uff0c\u4e14 uid \u4e00\u5b9a\u8981\u5bf9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Nginx_%E9%85%8D%E7%BD%AE\"><\/span>Nginx \u914d\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5bb9\u5668\u91cc\u9762\u7684 nginx \u9700\u8981\u628a\u8bf7\u6c42\u8f6c\u53d1\u7ed9 php-fpm<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim vim docker-compose\/nginx\/travellist.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    index index.php index.html;\n    error_log  \/var\/log\/nginx\/error.log;\n    access_log \/var\/log\/nginx\/access.log;\n    root \/var\/www\/public;\n    location ~ \\.php$ {\n        try_files $uri =404;\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        fastcgi_pass app:9000;\n        fastcgi_index index.php;\n        include fastcgi_params;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        fastcgi_param PATH_INFO $fastcgi_path_info;\n    }\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n        gzip_static on;\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%B4%9F%E8%BD%BD_nginx_%E9%85%8D%E7%BD%AE\"><\/span>\u8d1f\u8f7d nginx \u914d\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8981\u52a0\u8fd9\u4e2a nginx\uff0c\u5176\u5b9e\u4e5f\u53ef\u4ee5\u4e0d\u52a0\uff0c\u4e3b\u8981\u662f\u8fd9\u4e2a\u673a\u5668\u4e0a\u6211\u8fd8\u8dd1\u4e86\u53e6\u5916\u51e0\u4e2a\u670d\u52a1\uff0c\u6240\u4ee5\u624d\u5171\u7528\u8fd9\u4e2a \u8d1f\u8f7d nginx\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> server {\n\n        server_name  fanyi1.qishiya.com;\n        root         \/usr\/share\/nginx\/html;\n\n        # Load configuration files for the default server block.\n        include \/etc\/nginx\/default.d\/*.conf;\n\n        location \/ {\n                proxy_pass http:\/\/127.0.0.1:8000;\n                proxy_set_header X-Forward-For $remote_addr;\n                proxy_set_header Host  fanyi1.qishiya.com;\n                proxy_set_header X-Real-IP $remote_addr;\n                proxy_set_header  X-Appengine-Remote-Addr $remote_addr;\n        }\n\n        error_page 404 \/404.html;\n            location = \/40x.html {\n        }\n\n        error_page 500 502 503 504 \/50x.html;\n            location = \/50x.html {\n        }\n\n\n\n\n    listen 443 ssl; # managed by Certbot\n    ssl_certificate \/etc\/letsencrypt\/live\/fanyi.qishiya.com\/fullchain.pem; # managed by Certbot\n    ssl_certificate_key \/etc\/letsencrypt\/live\/fanyi.qishiya.com\/privkey.pem; # managed by Certbot\n    include \/etc\/letsencrypt\/options-ssl-nginx.conf; # managed by Certbot\n    ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem; # managed by Certbot\n\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%9D%91-2\"><\/span>\u5751<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5728\u8d1f\u8f7d\u7684 nginx\uff0c\u4e0d\u52a0 host \u7684\u8bdd\uff0c\u53d6\u4e0d\u5230 host\uff0c\u9ed8\u8ba4\u7684\u8d44\u6e90\u4f9d\u8d56\u90fd\u53d8\u6210 127.0.0.1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>proxy_set_header Host  fanyi1.qishiya.com; <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Laravel_%E9%85%8D%E7%BD%AE\"><\/span>Laravel \u914d\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e00\u5b9a\u8981\u914d\u7f6e APP_URL \u548c ASSET_URL\uff0c\u4e0d\u7136\u53d6\u7684\u8d44\u6e90\u7684\u57df\u540d\u4e0d\u5bf9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>APP_URL=https:\/\/fanyi1.qishiya.com\nASSET_URL=https:\/\/fanyi1.qishiya.com<\/code><\/pre>\n\n\n\n<p>\u5f3a\u5236 https\uff0claravel \u5728\u524d\u7aef\u6a21\u677f\u8c03\u7528 {{ router(&#8216;login&#8217;) }} \u4e4b\u7c7b\u7684\u6307\u4ee4\u65f6\uff0c\u9ed8\u8ba4\u662f http\uff0c\u4fee\u6539\u5982\u4e0b\u4ee3\u7801\uff0c\u53ef\u4ee5\u5f3a\u5236 https<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>namespace App\\Providers;\n\nuse Illuminate\\Support\\Facades\\URL;\nuse Illuminate\\Support\\ServiceProvider;\n\nclass AppServiceProvider extends ServiceProvider\n{\n    public function boot()\n    {\n        URL::forceScheme('https');\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"laravel_%E5%88%9D%E5%A7%8B%E5%8C%96\"><\/span>laravel \u521d\u59cb\u5316<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u670d\u52a1\u8dd1\u8d77\u6765\u540e\uff0c\u9700\u8981\u5bf9\u73af\u5883\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose exec app composer install\n\ndocker compose exec app php artisan key:generate\n\ndocker compose exec app php artisan migrate --force<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/28402726\/laravel-5-redirect-to-https\">https:\/\/stackoverflow.com\/questions\/28402726\/laravel-5-redirect-to-https<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/pentacent.medium.com\/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71\">nginx-and-lets-encrypt-with-docker<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>fanyi \u8fd9\u4e2a\u5c0f\u5de5\u5177\uff0c\u4ee5\u524d\u662f\u76f4\u63a5\u8dd1\u5728\u817e\u8baf\u4e91\u7684\u8f7b\u91cf\u670d\u52a1\u5668\u4e0a\u7684\uff0c\u7528 Golang \u5199\u7684\uff0c\u6700\u8fd1\u52a0\u4e86\u4e00\u4e2a\u5c0f\u529f\u80fd\uff0c\u7528 php \u91cd\u5199\u4e86\uff0cphp \u5c31\u8981\u642d\u5efa\u5404\u79cd\u73af\u5883\uff0c\u76f4\u63a5\u5728\u817e\u8baf\u4e91\u7684\u8f7b\u91cf\u670d\u52a1\u5668\u4e0a\u7f16\u8bd1 php \u4e0d\u6210\u529f\uff0c\u4e3b\u8981\u662f\u4f60 cpu \u9ad8\uff0c\u4ed6\u5c31\u76f4\u63a5\u7ed9\u4f60 ki &#8230; <a title=\"Laravel Docker Centos8 \u4f7f\u7528\" class=\"read-more\" href=\"https:\/\/qishiya.com\/?p=1755\" aria-label=\"\u66f4\u591a Laravel Docker Centos8 \u4f7f\u7528\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/template-full-width.php","format":"standard","meta":{"footnotes":""},"categories":[457],"tags":[434,531,383,532],"class_list":["post-1755","post","type-post","status-publish","format-standard","hentry","category-457","tag-centos8","tag-docker","tag-laravel","tag-nginx"],"_links":{"self":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/1755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1755"}],"version-history":[{"count":3,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/1755\/revisions"}],"predecessor-version":[{"id":1758,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/1755\/revisions\/1758"}],"wp:attachment":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}