Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phylaxis's avatar

Strange ''Unexpected character in input: " error in Homestead on macOS Mojave

Unfortunately there is not a "Homestead" channels so hopefully this is the right place for this.

I'm posting this for any others who might be upgrading to macOS Mojave, because after upgrading I ran into an issue where I could no longer update any of the files in Laravel without getting a PHP warning like this one:

PHP message: PHP Warning: Unexpected character in input: ' in /home/vagrant/code/site/app/Http/Controllers/PagesController.php on line 38

Not only that, the Laravel files (views, etc) didn't seem to update at all on my front end. I also couldn't even call debug functions like dd(). It took me a long time to figure out what was happening and I couldn't find anything online with Google searches.

Anyone who has upgraded to macOS Mojave (and also possibly High Sierra) may already know Apple is severely tightened down security and what apps are allowed to do and not do. This includes file system access and this is what turned out to be the issue for me.

I am running my Homestead install using the Parallels provider, but I assume this issue could crop up for any provider you might be using. The solution is to add your provider app to the 'Full Disk Access' permissions in System Preferences > Security & Privacy in the Privacy tab.

Screenshot

I believe the issue is Homestead trying to access mapped directories in the macOS filesystem via the provider. Because the provider doesn't have access that means Homestead and Laravel also do not have access and thus the error. What's odd is how it manifests itself as a simple PHP warning, but really it presents more like a Fatal error, but without any Fatal warning indicators.

Hope this post might help others out there not waste a bunch of time Google searching and coming up empty.

0 likes
8 replies
phylaxis's avatar

OK. I take it ALL back, this did not fix my issue with migrations AT ALL. I have no idea what is happening here, but when I create a new migration with php artisan migrate:make and then run php artisan migrate everything is fine. The minute I add ANY lines of code to my migration using SublimeText (or any text editor) on my Mac and then run php artisan migrate I get thee errors:

PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41
PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41
PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41
PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41
PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41
PHP Warning:  Unexpected character in input:  ' in /home/vagrant/code/podman/database/migrations/2018_10_24_223202_create_sub_episodes_table.php on line 41

The really odd thing is the number of warnings correspond 1 for 1 to the number of characters in the code that I added to the migration. So if I add a comment like //TEST I will get "6" of these warning messages.

My PHP version is PHP 7.1.23-2+ubuntu16.04.1+deb.sury.org+1 (cli)

I am at a total loss here. I tried saving my code in various encodings in case it was an issue there, but that doesn't seem to make ANY difference.

1 like
phylaxis's avatar

BTW, even thought these are just PHP warnings whatever line I added doesn't get added into the table, so this is somehow related to an issue I posted here.

Snapey's avatar

so is it something about whatever comes before line 41?

phylaxis's avatar

That's a bit of a red herring I'm afraid @Snapey because that is actually the last line in the file. No matter where I place the code that triggers the "warning" it will always reference the last line of the file.

phylaxis's avatar

Ok. This definitely seems to be some sort of issue between how macOS Mojave, Homestead, Parallels, and Laravel (artisan) are interacting. It seems like the problem is somewhere in the directory mapping and how code changes made on the Mac are then sync'd/copied into Homestead (Vagrant).

If I make a code change on the Mac the code also updates on Homestead but I get these strange issues. If I change the code directly while SSH's into Homestead everything is fine and the code change is also reflected on the Mac. Finally if I change the code on the Mac and then just open and write out the file inside Homestead I also have no issues.

I'm open to any thoughts/theories.

1 like
basher's avatar

I am having exactly the same issue with Mojave and Homestead. Usually I have to go back to the file, add an empty line and save. Issue disappears. Not sure what is causing this exactly but does feel like a file syncing issue.

4 likes
cosmicvibes's avatar

Same thing happens to me on Linux + Homestead + Vagrant + Virtualbox. I believe the problem is in the folder sync happening in Virtualbox. I often get a similar issue when running npm run within the virtual machine (so run it on the host instead). Some suggestions I've seen are to switch to NFS for the shared folders (i.e https://bizwind.github.io/2019-06-26/improving-synced-folder-performance-in-vagrant) but that has it's own problems. For now I have been doing the same as @basher with the empty line trick.

ashrug's avatar

Same outcome as @cosmicvibes, being on Linux + Homestead + Vagrant + Virtualbox. the migrations ran with the warnings and the tables were not being created.

what did it for me was reload and provision the vm with

vagrant reload --provision

Please or to participate in this conversation.