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

ethar's avatar
Level 5

php shown as plaintext (mac monterey)

I upgrade my Mac to the new version, after install I use homebrew to install PHP 8, but when run a project (Laravel) its shown as plain text

0 likes
15 replies
tykus's avatar

Seems that the web server is not handing off to PHP-FPM; what is your set up?

1 like
ethar's avatar
Level 5

@tykus

 brew install php  

php -v 8.0

sudo atom /etc/hosts
127.0.0.1       www.fb.test

sudo atom /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/fb/public"
    Servername fb
    ServerAlias www.fb.test
    <Directory "/Library/WebServer/Documents/fb/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

sudo apachectl restart
jlrdw's avatar

Is anything in apache error log? Is php enabled in conf file? Just a suggestion to check.

1 like
Snapey's avatar

is apache server running?

1 like
Snapey's avatar

create a file in the public folder phpinfo.php

visit the url fb.test/phpinfo.php

if you see the plain text then php is not installed in apache, and it's nothing to do with your laravel project

1 like
ethar's avatar
Level 5

@Snapey php installed

etharshrouf@Ethars-MacBook-Pro ~ % php -v
PHP 8.0.10 (cli) (built: Aug 26 2021 15:36:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
Snapey's avatar

The CLI. is , yes. you already said

1 like
ethar's avatar
Level 5

@Snapey in terminal php executed successfully but again in browser shown as plaintext

tykus's avatar
tykus
Best Answer
Level 104

@ethar in your /usr/local/etc/httpd/httpd.conf, you can load the PHP apache module and configure Apache to handle PHP files:

atom /usr/local/etc/httpd/httpd.conf

Add the following line to the end of the LoadModule list:

LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so

Then, in the same file, find the IfModule dir_module directive and add the FilesMatch directive after (like this):

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Restart the httpd service:

brew services restart httpd

Now check that the phpinfo() script from earlier replies is working.

1 like
ethar's avatar
Level 5

@tykus thanks when add

LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so

server stoped

note there is no path

/usr/local/etc/httpd/httpd.conf

i have path

atom /etc/apache2/httpd.conf 

i add LoadModule in this path

atom /etc/apache2/httpd.conf 

but server stoped from work

tykus's avatar

Stop the OS version of Apache, and install instead using Homebrew apache-httpd

2 likes
ThreeBros's avatar

seems that the location of the LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so and httpd.conf files is changed in MacOS BigSur and Monterey

so you update the location to the correct one (after installing php with homebrew) you should be able to run php 8.

here is a link to a how to from GetGrav CMS - (part 1 is what you are interested in but please update the paths to homebrew paths)

Please or to participate in this conversation.