docker 安裝 Laravel 環境 (nginx mariadb PHP7.2)

Vckin發表於2019-12-02

1,安裝mariadb

    docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mariadb mariadb:latest

檢視

mysql -h127.0.0.1 -uroot -proot

2 ,安裝nginx

    docker run -d -p 80:80 -p 443:443 --name nginx_laravel \
    --restart always \
    -v /Users/vckin/Desktop/vckin/app/code:/var/www \
    -v /Users/vckin/Desktop/vckin/nginx:/etc/nginx/conf.d nginx

配置php-fpm

    docker inspect dcID(nginx)

測試nginx 建立test.conf

server {
        #偵聽80埠
        listen       80;
        index index.php index.html index.htm;
        #設定本虛擬主機的訪問日誌
        server_name  localhost;
        root /var/www/public;
        #rewrite_log on;
        #access_log  logs/hc-admin.access.log  main;
        #error_log  logs/hc-admin.access.log  main;
    location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css|ttf|woff|woff2)$
    {
        root /var/www/public;
    }
    location / {  
        index  index.htm index.html index.php;  

        if (!-e $request_filename) {  
           rewrite  ^/(.*)$  /index.php/$1  last;  
           break;  
        }  
    }  
    location ~ \.php/?.*$ {  
        root        /var/www/public;  
        #此處為docker Gateway ip
        fastcgi_pass   172.17.0.1:9000;  
        fastcgi_index  index.php;  
        #載入Nginx預設"伺服器環境變數"配置  
        #include        fastcgi.conf;  
        include fastcgi_params; 

        set $fastcgi_script_name2 $fastcgi_script_name;  
        if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
            set $fastcgi_script_name2 $1;  
            set $path_info $2;  
        }  
        fastcgi_param   PATH_INFO $path_info;  
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;  
    }
    } 

建立 index.html

    <html>
        nginx_test
    </html>

訪問localhost 顯示為test

3,安裝php7.2

docker run -dit --name php-alpine -p 9000:9000 -v /Users/vckin/Desktop/vckin/app/code:/var/www mikechernev/php7-fpm-laravel 

安裝composer

進入docker
docker exec -it dcID bash
安裝composer
    php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    mv composer.phar /usr/local/bin/composer

4,測試

建立 index.php
    phpinfo();
重啟nginx
    docker restart nginx
訪問localhost/index.php

docker 安裝 Laravel 環境 (nginx mariadb PHP7.2)
docker 安裝 Laravel 環境 (nginx mariadb PHP7.2)

相關文章