Laravel Homestead php-7 "php5-fpm: unrecognized service" on vagrant up
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
.
For a quick fix, I found this answer from laracasts very helpful:
cd ~/Homestead && git pull && vagrant destroy && vagrant box update && vagrant up
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 issecret
.) - 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. Usevagrant 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/sitessites: - map: site1.app to: /home/vagrant/sites/site1/public - map: site2.app to: /home/vagrant/sites/site2/publicdatabases: - 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 -vPHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )[...]