经过一番修改,下面是我想出的。我不保证这是正确的方法,就我而言,它似乎有效:
找到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...
# enable xdebug via cli
sudo phpenmod -s cli xdebug
# restart php and nginx
sudo service php7.3-fpm restart && sudo service nginx restart
如果您不知道所需扩展的确切名称(我不知道),您可以使用 sudo apt-cache search php7-* 或类似名称列出可用的扩展
流浪破坏
现在,如果你有宅基地,在终端,cd 到你的宅基地目录,我是cd ~/Homestead,然后运行vagrant destroy
流浪
在/Homestead 内部运行vagrant up --provision
检查安装
要检查扩展是否正确安装,在 /Homestead 中运行以下两个命令:
vagrant 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
)
就像我在开头所说的那样,我不能说这是正确的方法,但到目前为止它对我有用。
如果有人发现这种方法有缺陷,请随时告诉我我做错了:)