我在Homestead使用Laravel 5.3,在VirtualBox上运行Vagrant 1.8.7。
我需要启用一些php扩展。
我知道我可以通过ssh登录并编辑php.ini来启用扩展,但这似乎是一种非常反迁移的方式。
我想告诉Vagrant为盒子提供特定的php扩展,这样我就可以简单地调用vagrant up --provision
,盒子就会准备好了(有点像Vagrant的意思,对吗?)
那么,我们如何在Homestead上自动启用php扩展?
经过一些修改,下面是我想到的。我不保证这是正确的方法只是,在我的情况下,它似乎是有效的:
找到安装homestead时生成的after.sh
。对我来说,在Mac El capitan上,文件是在~/.homestead/after.sh
创建的,我想象在windows上有一个.bat
在类似的位置。
不要在中编辑~/Homestead/src/stubs/after.sh
,这是homestead安装的模板文件,而不是你实际生成的副本。
Edit 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-*
或类似的列出可用的
的流浪汉摧毁
现在,如果你有homestead,在终端中,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
)
就像我在开头所说的,我不能说这是正确的方法,但到目前为止,它对我来说是有效的。
如果有人看到这种方法的缺陷,请随时告诉我我做错了:)
如果仍然需要这个:
=> https://guides.wp-bullet.com/install-apcu-object-cache-for-php7-for-wordpress-ubuntu-16-04/
=>执行前3个命令:
sudo apt-get update
sudo apt-get install php7.0-apcu -y
sudo service php7.0-fpm restart
或者直接添加到。sh后面:
sudo apt-get install php7.x-apcu -y
您应该首先使用ssh登录到Homestead服务器(可能您已经知道了- "vagrant ssh")。
然后进入"/etc/php/7.0/fpm/"/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。在你的宅基地上,使用
find / -name php.ini
查找php.ini,您可能会得到2或3个结果