DEV Community

loading...

Adding PHP 8 to Laragon

Dendi Handian
I am that backend programmer who doesn't return 200 OK for errors and doesn't write only POST method for all endpoints.
Updated on ・2 min read

Currently I'm using Laragon Lite version, it has PHP 7.4.16 and apache 2.4.35 running well in my machine. Meanwhile PHP now has version 8 and it looks like it still supported in Windows machine. Here is my step to change version to PHP 8.

Downloading the PHP 8 Binaries

You can go to https://windows.php.net/download and you can see the option to download the latest available PHP 8 version, I got PHP 8.0 (8.0.8) at the time. If you want to try the same version as me, you can directly download it by this link https://windows.php.net/downloads/releases/php-8.0.8-Win32-vs16-x64.zip

After it downloaded, you can create a folder inside C:\laragon\bin\php (or your own custom directory) named after the downloaded zip file. The folder name for me is php-8.0.8-Win32-vs16-x64 and then extract anything inside php-8.0.8-Win32-vs16-x64.zip to this folder.

Switching the PHP version to 8

Try to right-click on Laragon desktop app, choose PHP, and click the php-8.0.8-Win32-vs16-x64 to change to this version.

Now run the apache too. When the apache starting to run, Laragon will pop this message:

image

Something is wrong and we need figure the error out.

Fixing the Apache Error when using PHP 8

When I'm looking on the laragon forum https://forum.laragon.org/topic/2232/php-8-and-apache-2-compatibility, someone found how to fix the error with video explanation https://www.youtube.com/watch?v=P0ahcFoMwnM.

So to fix it, we need to open the C:\laragon\etc\apache2\mod_php.conf file that contains this code:

# This file is auto-generated, so please keep it intact.
LoadModule php8_module "C:/laragon/bin/php/php-8.0.8-Win32-vs16-x64/php8apache2_4.dll"
PHPIniDir "C:/laragon/bin/php/php-8.0.8-Win32-vs16-x64"
<IfModule mime_module>
    AddType application/x-httpd-php .php
</IfModule>
Enter fullscreen mode Exit fullscreen mode

Look at the php8_module. You only need to change it into php_module so the code will be like this:

# This file is auto-generated, so please keep it intact.
LoadModule php_module "C:/laragon/bin/php/php-8.0.8-Win32-vs16-x64/php8apache2_4.dll"
PHPIniDir "C:/laragon/bin/php/php-8.0.8-Win32-vs16-x64"
<IfModule mime_module>
    AddType application/x-httpd-php .php
</IfModule>
Enter fullscreen mode Exit fullscreen mode

Save the file, now turn-off apache and restart it. When you access the localhost in the browser, you should see this now:

Alt Text

This solution will temporary fix the issue. When you switch back to version 7.4 or else, the above configuration will reset back and you have to change it when using PHP 8. We're looking forward for the permanent solution.

Discussion (0)