2

I am trying to get an old Laravel 4.1.x app up and running again so that it can be modernized. This requires an environment with PHP 5.6 and the Mcrypt extension. I have installed Homestead 9.0.3 (the latest stable version). Within the VM, I have set the PHP version to 5.6

sudo update-alternatives --config php

I have then installed the php-mcrypt extension

sudo apt-get install php5.6-mcrypt

I am now able to create a new Laravel 4.1.x project, which is a process that requires Mcrypt to complete, so we're certainly getting somewhere:

composer create-project laravel/laravel="4.1.*" myAppName

However, when I browse to the webpage for myAppName, I see the message:

Mcrypt PHP extension required.

I have also tried steps that are usually recommended for this problem, ie:

sudo ln -s /etc/php/5.6/conf.d/mcrypt.ini /etc/php/5.6/mods-available/mcrypt.ini
sudo phpenmod mcrypt
sudo service php5.6-fpm restart

But I still get the same message in the browser.

What step have I missed?

jsm
  • 111
  • 1
  • 14

2 Answers2

2

With homestead v9 you should be up and running with php5.6 out of the box as stated in here, but unfortunately it is not your case, and I understand that...

Old packages were not installed by default (php5.6-mcrypt), as you mentioned and they should be added by hand via: sudo apt-get install php5.6-mcrypt

After that all packages are ready, up and working, especially php5.6-mcrypt.

The root of your problem is in multiple site definitions under your homestead.yaml. Most probably some of them are overlapping and your nginx is referring to the wrong resource/site_definition, and wrong paths.

Therefore you might think some strange php versions or routes are run/executed.

You can verify that, by deleting some/all of them, leaving the only one important for you - in (/etc/nginx/sites-enabled/...).

Of course please do that inside the container and issue sudo service nginx restart, afterwards...

All of your problems should be gone after that.

If something goes wrong. You could easily recover your current installation to current state using vagrant destroy and vagrant up afterwards, cause all is saved in Homestead.yaml.

In my installation Homestead v9 is running with php5.6 on laravel 4.1 without any problems...

Hope it helps @jsm...

Bart
  • 1,889
  • 1
  • 21
  • 38
  • 1
    I really appreciate your help. leonardo-vitali gave the exact info I needed, but you kept me on track too. Wish I could mark you both as correct. – jsm Jul 24 '19 at 22:10
1

Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.

First check what version the server is running with phpinfo();

Check the file /etc/nginx/sites-enabled/homestead.test and look for this line:

fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;

If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock. In this case the version 5.6 has mcrypt installed, but 7.3 don't.

You can just replace the line

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

for

fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;

and then reload nginx with sudo nginx -s reload.

Or set the php version on Homestead.yaml:

sites:
- map: homestead.test
  to: /home/vagrant/code/public
  php: "5.6"

And then run vagrant provision, it will change the nginx configuration for PHP 5.6.

Leonardo Vitali
  • 306
  • 1
  • 5
  • Thank you! The problem arose because I did not appreciate that the CLI and FPM versions of PHP were being set separately. I was using sudo update-alternatives --config php, but this only changed the CLI. Importantly, it did NOT update the FPM version. Your suggestion to create a phpinfo() page made the problem clear. After that, a quick update of the Homestead.yaml file got everything up and running as expected. Brilliant! – jsm Jul 24 '19 at 22:08