如何在vagtead上自动启用Homestead中的php扩展

前端之家收集整理的这篇文章主要介绍了如何在vagtead上自动启用Homestead中的php扩展前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Homestead中使用Laravel 5.3,在VirtualBox上运行Vagrant 1.8.7.

我需要启用一些PHP扩展.

我知道我可以ssh到框中并编辑PHP.ini以启用扩展,但这似乎是一种非常反流浪的方式来做到这一点.

我想告诉Vagrant配置启用特定PHP扩展的盒子,以便我可以简单地调用vagrant –provision并且盒子将准备好(有点流浪的权利吗?)

那么,我们如何在vagtead中自动启用Homestead中的PHP扩展?

经过一些修补,下面是我想出的.我不保证这是正确的方式,只是在我的情况下,它似乎工作:

找到installed homestead生成的after.sh.对于我,在Mac El Capitain上,文件是在〜/ .homestead / after.sh创建的,我想在Windows上的类似位置有一个.bat.

不要错误地编辑〜/ Homestead / src / stubs / after.sh,这就是来自宅基地安装的模板文件,而不是你实际生成的副本.

编辑after.sh

将以下行添加到after.sh(这是我的整个文件,只有前5个注释行在默认文件中):

#!/bin/sh

# If you would like to do some extra provisioning you may
# add any commands you wish to this file and they will
# be run after the Homestead machine is provisioned.

# in the below --assume-yes is to avoid confirms [y/N]
# DEBIAN_FRONTEND=noninteractive is to avoid a big menu asking if it's ok to 
# overwrite the PHP.ini file,may make --assume-yes redundant,not sure

# run apt-get update first,without it I was getting errors not finding the extensions 
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes update

# load any extensions you like here 
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install PHP-xdebug 
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install PHP7.0-ldap # update to PHP7.2-ldap if using PHP 7.2 etc...

如果你不精神上知道你需要的扩展的确切名称(我没有)你可以使用sudo apt-cache搜索PHP7- *或类似的列出可用的

流浪汉毁灭

现在,如果你有家园,在终端,cd到你的Homestead目录,为我cd~ / Homestead然后运行vagrant destroy

流浪汉

在内部/ Homestead运行流浪汉 – 提供

检查安装

要检查扩展是否正确安装,在/ Homestead内部运行以下两个命令:

流浪汉ssh

PHP -r“print_r(get_loaded_extensions());”

我的输出(添加了33和61):

DoDSoftware:Homestead DOoDSoftware$vagrant ssh
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
vagrant@homestead:~$PHP -r "print_r(get_loaded_extensions());"
Array
(
    [0] => Core
    [1] => date
    [2] => libxml
    [3] => openssl
    [4] => pcre
    [5] => zlib
    [6] => filter
    [7] => hash
    [8] => pcntl
    [9] => Reflection
    [10] => SPL
    [11] => session
    [12] => standard
    [13] => MysqLnd
    [14] => PDO
    [15] => xml
    [16] => apcu
    [17] => apc
    [18] => bcmath
    [19] => calendar
    [20] => ctype
    [21] => curl
    [22] => dom
    [23] => mbstring
    [24] => fileinfo
    [25] => ftp
    [26] => gd
    [27] => gettext
    [28] => iconv
    [29] => igbinary
    [30] => imap
    [31] => intl
    [32] => json
    [33] => ldap
    [34] => exif
    [35] => mcrypt
    [36] => msgpack
    [37] => MysqLi
    [38] => pdo_MysqL
    [39] => pdo_pgsql
    [40] => pdo_sqlite
    [41] => pgsql
    [42] => Phar
    [43] => posix
    [44] => readline
    [45] => shmop
    [46] => SimpleXML
    [47] => soap
    [48] => sockets
    [49] => sqlite3
    [50] => sysvmsg
    [51] => sysvsem
    [52] => sysvshm
    [53] => tokenizer
    [54] => wddx
    [55] => xmlreader
    [56] => xmlwriter
    [57] => xsl
    [58] => zip
    [59] => memcached
    [60] => blackfire
    [61] => Zend OPcache
    [62] => xdebug
)

就像我在开始时说的那样,我不能说这是正确的方法,但到目前为止它对我有用.

如果有人看到这种方法的缺陷,请随时告诉我我做错了:)

猜你在找的PHP相关文章