How to automatically enable php extensions in Homestead on vagrant up
In case there's still a need for this :
=> Run the 3 first commands :
sudo apt-get update sudo apt-get install php7.0-apcu -y sudo service php7.0-fpm restart
Or simply add to after.sh:
sudo apt-get install php7.x-apcu -y
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 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.
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.
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
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
Now, if you have homestead up, in the terminal,
cd to your Homestead dir, for me
cd ~/Homestead and then run
vagrant up --provision
To check that the extensions installed correctly, while inside
/Homestead run these two commands:
php -r "print_r(get_loaded_extensions());"
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/ [email protected]:~$ php -r "print_r(get_loaded_extensions());" Array (  => Core  => date  => libxml  => openssl  => pcre  => zlib  => filter  => hash  => pcntl  => Reflection  => SPL  => session  => standard  => mysqlnd  => PDO  => xml  => apcu  => apc  => bcmath  => calendar  => ctype  => curl  => dom  => mbstring  => fileinfo  => ftp  => gd  => gettext  => iconv  => igbinary  => imap  => intl  => json  => ldap  => exif  => mcrypt  => msgpack  => mysqli  => pdo_mysql  => pdo_pgsql  => pdo_sqlite  => pgsql  => Phar  => posix  => readline  => shmop  => SimpleXML  => soap  => sockets  => sqlite3  => sysvmsg  => sysvsem  => sysvshm  => tokenizer  => wddx  => xmlreader  => xmlwriter  => xsl  => zip  => memcached  => blackfire  => Zend OPcache  => xdebug )
Like I stated at the beginning, I cant say this is the right way, but it's working for me so far.