Search code examples
apacheredhat

Laravel: how to specify the php version?


I have a Laravel (5.7.19) app running with apache2 on a redhat7 machine. There are php5.6, php7.1 and php7.4 installed on the machine and somehow apache uses php5.6 as the default and the app doesn't work with php5.6. Is there a way to specify a php version for a Laravel app, such as setting the php version in .env or some other config file of the app? I've googled around and couldn't find an answer. Right now the only way I could make the app to work is to disable php5.6 and then apache would use php7.1 as the default.


Solution

  • "Is there a way to specify a php version for a Laravel app, such as setting the php version in .env or some other config file of the app?"

    • No. The PHP interpetor isn't aware of itself. The application's dotenv file is read by the application itself, which means there's already an interpretor doing the job so if it's picked up by php5, there's no way for the interpretor to pass it along to a php7 interpreter.

    • If you're using Apache (and assuming a single Apache running), you can setup multiple PHP versions under the same Apache server by using the fastcgi module as described here: https://medium.com/@sivaschenko/apache-running-multiple-php-versions-simultaneously-570fc1541580 and then depending on application you can setup virtual hosts using different php versions

    • THe better way is with nginx + fpm, where you can have different php versions with different fpm instances running on different ports and you can setup server blocks where php requests are routed appropriately.