Home > Backend Development > PHP Tutorial > 用docker 做 laravel的开发环境 , 顺便介绍一下如何将docker 容器设置成本地命令

用docker 做 laravel的开发环境 , 顺便介绍一下如何将docker 容器设置成本地命令

WBOY
Release: 2016-06-20 12:30:55
Original
892 people have browsed it

需要用 laravel 开发,想到用docker。 Laravel 是2015年最热门的php 开发框架之一。

网上有些类似介绍,但是觉得还是自己写一个。

先建个文件, 赋予可执行权限。目的是将coomposer镜像当做本地命令运行。

$ cat /usr/local/bin/composer
Copy after login

!/bin/sh

export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

echo "Current working directory: '"$(pwd)"'"

docker run --rm -v $(pwd):/app -v ~/.ssh:/root/.ssh composer/composer $@

$ chmod +x /usr/local/bin/composer

确认环境变量的 PATH里含 /usr/local/bin

当然,你也可以用alias的方式

alias composer="docker run --rm -v $(pwd):/app -v ~/.ssh:/root/.ssh composer/composer"
Copy after login

建个composer.json的需求模版

$ cat composer.json{"require": {    "laravel/installer": ">=1.3.3"}}
Copy after login

安装 laravel 环境

composer install
Copy after login

其实,这个时候,运行了 /usr/local/bin/composer, 而脚本里调用了 composer/composer的镜像。

创建第一个项目

$ composer create-project --prefer-dist laravel/laravel blog...phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)Writing lock fileGenerating autoload files> Illuminate\Foundation\ComposerScripts::postUpdate> php artisan optimizeGenerating optimized class loader
Copy after login

APP_KEY会自动更新。 如果没有更新,你可以手动更新

$ cd blog$ php artisan key:generate
Copy after login

启动php 服务器

$ cd blog/public$ php -S localhost:8000
Copy after login

这样你就可以看到laravel 初始网站了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template