How to automatically enable php extensions in Homestead on vagrancy

Im using Laravel 5.3 in Homestead with Vagrant 1.8.7 running on VirtualBox.

I need to enable some php extensions.

I know I could do ssh in the field and edit php.ini to enable the extension, but this seems like a very anti-wandering way for this.

I want to say that Vagrant provided a box with certain php extensions so that I can just call vagrant up --provision and the field will be ready to work (does it seem like the vagrant point is correct?)

So, How can we automatically activate php extensions in Homestead on upstairs?

+11
source share
3 answers

After some rework, this is what I came up with. I am not assuring that this is the right way to do this, just that, in my case, this works:

Find after.sh that was created when setting up the estate . For me, on Mac El Capitain, the file is created in ~/.homestead/after.sh , I think .bat in a similar place on the windows.

Make no mistake editing ~/Homestead/src/stubs/after.sh , this is the template file from the estate installation, and not the actual copy created.


Edit after.sh

Add the following lines to after.sh (this is my entire file, only the first 5 lines of comments 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 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 mentally do not know the exact name of sudo apt-cache search php7-* you extensions (I did not know), you can use sudo apt-cache search php7-* or similar to view the list of available


tramp destroy

Now, if you have a homestead, in the terminal, cd to your Homestead directory, for me cd ~/Homestead and then run vagrant destroy


roving up

While inside /Homestead run vagrant up --provision


Check installation

To verify that the extensions are installed correctly, while inside /Homestead run these two commands:

vagrant ssh

php -r "print_r(get_loaded_extensions());"

My conclusion (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 ) 

As I said at the beginning, I can’t say that this is the right way, but so far it works for me.

If someone sees a flaw in this approach, feel free to tell me that I'm doing everything wrong :)

+6
source

you should first log in to your Homestead server using ssh (you may already know this is "ssh tramp").

then go to "/etc/php/7.0/fpm/" there is also for cli in this place "/etc/php/7.0/cli/" edit it with "sudo vi php.ini" (esc and: wq for save changes).

then you must restart nginx: "sudo nginx -s reload"

and after that restart php-fpm: "sudo service php7.0-fpm restart"

if you are not sure if this is php 5.x or 7.x on your farm, use "find / -name php.ini" to find php.ini, you will probably get 2 or 3 results.

+1
source

In case it is still necessary:

=> https://guides.wp-bullet.com/install-apcu-object-cache-for-php7-for-wordpress-ubuntu-16-04/

=> Run the first 3 commands:

 sudo apt-get update sudo apt-get install php7.0-apcu -y sudo service php7.0-fpm restart 

Or just add to after.sh:

 sudo apt-get install php7.x-apcu -y 
0
source

Source: https://habr.com/ru/post/1012384/


All Articles