我在Homestead中使用Laravel 5.3,在VirtualBox上运行Vagrant 1.8.7。
我需要启用一些php扩展。
我知道我可以在框中编辑并编辑php.ini以启用扩展程序,但这似乎是一种非常反流浪的方法。
我想告诉Vagrant配置启用特定php扩展的盒子,这样我就可以简单地调用vagrant up --provision
并且盒子就可以了(有点流浪吧?)
那么,我们怎样才能在家园中自动启用php扩展程序?
答案 0 :(得分:6)
经过一些修修补补,下面就是我想出来的。我不保证这是正确的方法只是在我的情况下,它似乎正在起作用:
找到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 search php7-*
或类似名单列出可用的名称
现在,如果你有家园,在终端,cd
到你的Homestead目录,对我来说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
)
就像我在开头所说的那样,我不能说这是正确的方法,但它到目前为止对我有用。
答案 1 :(得分:1)
你应该首先使用ssh登录Homestead服务器(可能你已经知道了 - “vagrant ssh”)。
然后转到“/etc/php/7.0/fpm/” 在这个位置也有cli“/etc/php/7.0/cli/” 用“sudo vi php.ini”编辑它(esc和:wq保存更改)。
然后你应该重新启动nginx:“sudo nginx -s reload”
之后,重启php-fpm:“sudo service php7.0-fpm restart”
如果你不确定你的家园是不是php 5.x或7.x,使用“find / -name php.ini”查找php.ini,你可能会得到2或3个结果。
答案 2 :(得分:0)
万一仍然有需要:
=> https://guides.wp-bullet.com/install-apcu-object-cache-for-php7-for-wordpress-ubuntu-16-04/
=>运行前三个命令:
async/await
或直接添加到after.sh:
sudo apt-get update
sudo apt-get install php7.0-apcu -y
sudo service php7.0-fpm restart