如何在流浪汉上自动启用Homestead中的php扩展 [英] How to automatically enable php extensions in Homestead on vagrant up
问题描述
我在Homestead中使用Laravel 5.3,并在VirtualBox上运行了Vagrant 1.8.7.
Im using Laravel 5.3 in Homestead with Vagrant 1.8.7 running on VirtualBox.
我需要启用一些php扩展名.
I have need to enable some php extensions.
我知道我可以将其插入框并编辑php.ini以启用扩展,但这似乎是一种非常浪费的方法.
I know that I could ssh into the box and edit the php.ini to enable the extension but this seems like a very anti-vagrant way to do this.
我想告诉Vagrant为盒子提供特定的php扩展名,以便我可以简单地调用vagrant up --provision
,盒子就可以准备好了(请问这是无业游民的观点对吗?)
I want to tell Vagrant to provision the box with specific php extensions enabled so that I can simply call vagrant up --provision
and the box will be ready to go (kinda the point of vagrant right?)
那么,如何在无家可归的情况下在Homestead中自动启用php扩展?
推荐答案
经过一番修补,下面是我的想法.我不能保证这是正确的方法,仅就我而言,这似乎是可行的:
After some tinkering, the below is what I came up with. I make no assurances that this is the right way to do it only that, in my case, it seems to be working:
找到您已安装宅基时生成的after.sh
.对我来说,在Mac El Capitain上,文件是在~/.homestead/after.sh
上创建的,我想在Windows的类似位置中有一个.bat
.
Find the after.sh
that was generated when you installed homestead. For me, on Mac El Capitain, the file is created at ~/.homestead/after.sh
, I imagine there is a .bat
in a similar location on windows.
请勿犯错误,即编辑~/Homestead/src/stubs/after.sh
,这是Homestead安装中的模板文件,而不是您实际生成的副本.
Do not make the mistake of editing ~/Homestead/src/stubs/after.sh
, thats the template file from the homestead installation, not your actual generated copy.
将以下几行添加到after.sh
(这是我的整个文件,默认文件中只有前5条注释行):
Add the below lines to after.sh
(this is my whole file, only the first 5 comment lines were in the default file):
#!/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-*
或类似名称列出可用的扩展名
If you dont psychically know the exact name for the extension you need (I didnt) you can use sudo apt-cache search php7-*
or similar to list the available ones
现在,如果您有宅基地,请在终端机中cd
到您的宅基地目录,对我来说cd ~/Homestead
然后运行vagrant destroy
Now, if you have homestead up, in the terminal, cd
to your Homestead dir, for me cd ~/Homestead
and then run vagrant destroy
在/Homestead
内部运行vagrant up --provision
要检查扩展件是否正确安装,请在/Homestead
中运行以下两个命令:
To check that the extensions installed correctly, while inside /Homestead
run these two commands:
vagrant ssh
php -r "print_r(get_loaded_extensions());"
我的输出(添加了33和61):
My output (33 and 61 were added):
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
)
就像我一开始所说的那样,我不能说这是正确的方法,但是到目前为止,它对我来说是行之有效的.
Like I stated at the beginning, I cant say this is the right way, but it's working for me so far.
这篇关于如何在流浪汉上自动启用Homestead中的php扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!