在Laravel框架中$PATH变量设置的流程步骤
Laravel  /  管理员 发布于 1个月前   56
在Laravel开发过程中,我们经常会键入 ./vendor/bin/pest 等命令来运行特定于项目的命令。
这样做有点麻烦,为了解决这个问题,我们可以更新 Mac(或 Linux 或 windows)的 $PATH 变量。
什么是$PATH?
$PATH 变量用于设置系统在查找要运行的命令时所查找的目录。
例如,我们可以键入 <cmd> 查找任何指定命令的路径:
$ which git
/usr/local/bin/git
我的系统知道git位于/usr/local/bin,因为 /usr/local/bin 是我的$PATH中的一个目录!
您现在就可以回显您的路径了:
# Output the whole path
echo $PATH
# For human-readability, split out each
# directory into a new line:
echo "$PATH" | tr ':' '\n'
PATH中的相对目录
我们可以编辑$PATH变量,添加任何我们想要的目录!
一个非常方便的技巧就是在$PATH变量中设置相对目录。
两个例子是添加 ./vendor/bin 和 ./node_modules/.bin:
# In your ~/.zshrc, ~/.bashrc or, ~/.bash_profile or similar
# Each directory is separated by a colon
PATH=./vendor/bin:./node_modules/.bin:$PATH
在这里,我们将两个新路径添加到现有的 $PATH 变量中。
现在,无论我们嵌入了哪个Laravel应用程序,我们都可以运行
./vendor/bin/pest
知道我们正在运行
./vendor/bin/phpunit
(./node_modules/.bin 中的任何 Node 命令也是如此)。
我们还可以在$PATH 中设置当前目录 :
# In your ~/.zshrc, ~/.bashrc or, ~/.bash_profile or similar
# Each directory is separated by a colon
# Here we also set the current directory in our PATH
PATH=.:./vendor/bin:./node_modules/.bin:$PATH
这样我们就可以输入artisan 而不是 ./artisan 或 php artisan。
这就是我在 Chipper CI 中的设置,这样用户就可以运行 pest 或 phpunit,而不必担心命令在 CI 环境中的位置。
注意点
在$PATH中,顺序也很重要。
在搜索命令时,会先搜索较早的目录。
系统将使用最先找到的命令,这意味着你可以将系统命令放在 $PATH 中较早的目录中,从而取代该命令。
这就是我们将 ./vendor/bin 和 ./node_modules/.bin 添加到 $PATH 而不是追加的原因。
你可以像这样查找命令的所有位置:
$ which -a git
git is /usr/local/bin/git
git is /usr/bin/git
git is /usr/local/bin/git
git is /usr/bin/git
最后,在这里的所有情况下,命令都应具有可执行权限才能这样工作。
这一点在创建自己的命令(如自定义 bash 脚本)时要牢记。
路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..博主 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..mashrdn 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..张伟 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 3q!有用,不过免费节点隔天就要去git上复制新的导进去..博主 在
科学上网翻墙访问Google , 上外网神器佛跳墙VPN(永久免费)使用流程步骤中评论 该篇教程已不能用了,告知大家,免的老有老铁问我!..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号