12

Whilst trying to use the php-7 version of Laravel Homestead in a per-project installation, I see this error during vagrant up:

php5-fpm: unrecognized service

I've tried vagrant destroy and reinstalling the Vagrant box, but it still comes back to this error.

I didn't get the error when using Homestead globally.

How might this be fixed?

MHG
  • 1,410
  • 3
  • 19
  • 32

4 Answers4

14

The issue was that whilst box: laravel/homestead-7 was set correctly in Homestead.yaml, the composer dependency for laravel/homestead was still using the php-5 version. This meant that the provisioning scripts for Vagrant in vendor/laravel/homestead were those for php-5 and not php-7.

That can be fixed by using a specific branch of laravel/homestead for the composer dependency.

In composer.json, add a custom repository for laravel/homestead:

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/laravel/homestead"
    }
]

And require the php-7 branch specifically for laravel/homestead:

"require-dev": {
    "laravel/homestead": "dev-php-7"
}

Then composer update and re-provisioning the Vagrant box will fix the issue.

UPDATE

laravel/homestead now has PHP 7.0 by default, and the old php-7 branch no longer exists. To resolve this issue, you simply need to update to the latest version of laravel/homestead via composer.json.

MHG
  • 1,410
  • 3
  • 19
  • 32
  • I followed your advice and updated my composer.json which is located in ~/.composer/composer.json It fixed the problem however I am no longer able to use the "homestead" alias that I was able to use previously for running commands such as "homestead up", "homestead ssh" and "homestead provision" Now I am forced to use vagrant xxxxxxx reload --provision Any idea why this is now happening? If I revert back to the ~2.1 version of homestead then this problem goes away. – vesperknight Nov 26 '15 at 15:05
  • @vesperknight It looks like you're changing it globally for composer? The answer is intended to change this on a per-project basis, not globally. – MHG Nov 26 '15 at 16:12
  • The problem is simply that the php-7 version is missing the homestead executable entirely for some reason: https://github.com/laravel/homestead/tree/php-7 The master tree has it but the php-7 doesn't – vesperknight Nov 26 '15 at 22:28
  • Hi, I tried to change the composer.json in the project folder, but it doesn't seem to work. Where should I put these lines? – Anh Pham Dec 14 '15 at 09:04
  • 1
    Getting a `The requested package laravel/homestead could not be found in any version, there may be a typo in the package name.` attempting this. As far as I can tell, there is no `dev-php-7` branch in the laravel/homestead repo, which I am guessing is the problem. Perhaps it's been merged into a release at this point, and deleted. – Brynn Bateman Jan 12 '16 at 04:50
  • @BrynnBateman Thanks, that's correct. This work around is no longer necessary; I've updated the answer to reflect that. – MHG Jan 12 '16 at 11:28
9

For a quick fix, I found this answer from laracasts very helpful:

cd ~/Homestead && git pull && vagrant destroy && vagrant box update && vagrant up
Bluesail20
  • 319
  • 6
  • 15
4

To elaborate a bit more on the "just destroy it and build again" approach... I favour this over the various instructions for in-place Homestead upgrades from PHP 5.6 to PHP 7 that are floating around the web - it doesn't take very long and also everything feels "cleaner" when you've finished.

(Of course, if you've made changes to your php.ini or any of the other software, you'll need to do these again.)

Preparation

  • your projects should in a directory on your host computer that's shared with the Vagrant box, not on Vagrant box only, as that's about to be wiped
  • vagrant ssh into your VM and put a mysqldump of each site's database in the site directory, e.g. mysqldump -u root -p [dbname] > [dbname]-backup.sql (the default homestead MySQL root pw is secret.)
  • take a backup of everything (e.g. Mac Time Machine and/or do what I do and keep your projects in a Dropbox folder). You've got your git repository stored somewhere safely too, of course?
  • Virtualbox users: no harm in exporting the entire box in case you get stuck and want to go bac to it (taking a snapshot isn't enough as any will also be wiped when the VM is destroyed.)

Process

  • vagrant halt (if you haven't already)
  • vagrant destroy [VM id] Adding the ID is a precaution against destroying the wrong box. Use vagrant global-status to get a list of your boxes; use 7-character hex code in first column.
  • in ~/Homestead on your host PC/Mac git pull origin master (as mentioned in the other answer, there's no separate PHP7 branch now)
  • you can re-run the bash script to create a clean Homestead.yaml file etc. - bash init.sh, but the files it copies are all templates, so you can also not do this and keep your previous versions.
  • vagrant box add laravel/homestead (now we're back on the standard installation instructions. This'll take about 10 minutes on a VDSL connection.
  • edit ~/.homestead/Homestead.yaml on your Mac/PC.

Here's an example of the folder mapping if you're confused by the docs:

folders:
    - map: ~/Dropbox/websites-homestead
      to: /home/vagrant/sites

sites:
    - map: site1.app
      to: /home/vagrant/sites/site1/public
    - map: site2.app
      to: /home/vagrant/sites/site2/public

databases:
    - site1
    - site2

So... my actual code lives in ~/Dropbox/websites-homestead/site1 and /site2 on my computer, and I've mapped their common parent directory to /home/vagrant/sites on the VM. Homestead will create empty databases with the name(s) you list.

  • vagrant up (this'll provision it)
  • vagrant ssh
  • cd sites (you should be able to see your code)
  • restore databases with `mysql -u root -p site1 < site1-backup.sql
  • Providing you have /etc/hosts entries on your computer, you should be able to view your site. Check the .env file if it can't connect to the database.

You should now be able to do this:

$sudo service php7.0-fpm status
* php-fpm7.0 is running

$php -v
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
[...]
William Turrell
  • 3,227
  • 7
  • 39
  • 57
2

open /etc/nginx/sites-available/your_site_conf then change this line:

fastcgi_pass: /var/run/php5-fpm.sock;

to:

fastcgi_pass: /var/run/php/php7.0-fpm.sock;

And then restart nginx.

Note: This is not a permanent solution, if you run provision command vagrant will try to setting up by itself and will overwrite with the first line.

SidOfc
  • 4,552
  • 3
  • 27
  • 50