# PHP mit Apache24



## petros (Sep 14, 2020)

Hi everyone,
for 2 hours now I am scratching my head and try to figure out why a new jail with Apache 2.4 and PHP 7.2 does not execute PHP scripts - it just echos the script's source code instead.

it should just replace an old jail I installed 3 years ago, so I followed the same recipe. It is FreeBSD 12.1, and I use compiled packages from the FreeBSD repositories.

First I installed apache24 and mod_php72, and wrote under /usr/local/etc/apache/24/Includes/php.conf

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

I also saw, that there is a LoadModule line in httpd.conf, as expected.

Did not work, so I deinstalled mod_php72 and tried to use PHP-FPM instead.

service php-fpm start

and a php-fpm.conf:

<FilesMatch "\.php$">
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>

FPM is listening on port 9000, i can telnet to it. Still - the web page shows the source code only (checked again the blank page with looking at the page  source).

What am I missing here?

The old server is running fine with mod_php56, and the same php.conf as shown above.

What am I missing?

Please let me know.

Thank you
Peter


----------



## anlashok (Sep 14, 2020)

Check that the httpd.conf file is set to read the Includes folder configs, that might be commented out

Is this a typo in posting to the forum 
/usr/local/etc/apache*/*24/Includes/php.conf 
verses the correct /usr/local/etc/apache24/Includes/php.conf


----------



## ekvz (Sep 14, 2020)

Does it have to be Apache? I happen to find Nginx's configuration way easier to deal with. Might be worth a thought unless you have some hard requirement on Apache like needing to support .htaccess files.


----------



## richardtoohey2 (Sep 14, 2020)

Apache 2.4 and PHP 7.x run fine on FreeBSD 11.x and 12.x.

But, first off, you need to choose mod_php OR php-fpm - I see you tried both - which one do you want to work?

php-fpm is the modern way, mod_php is deprecated but still works very well.

Side note: PHP 7.2 is EOL in 2 months so you might want to consider going to 7.3 or 7.4 if you can.

If mod_php - have you loaded the module as well?  You said yes, so don't think that's the problem:


```
LoadModule php7_module        libexec/apache24/libphp7.so
```

Next - I've got this:


```
<IfModule php7_module>
    AddType application/x-httpd-php .php
</IfModule>
```

Instead of using an include file - just try both the above in httpd.conf to see if that makes any difference.

Are you restarting Apache each time you've made any changes to httpd.conf?


----------



## petros (Sep 16, 2020)

Thanks everyone for the answers. It works now.

I just deinstalled apache24, deleted /usr/local/etc/apache24, installed it again and mod_php72 afterwards, with the apache config as posted above.

I am not sure what fooled me a few days ago. I might not even role out my browser cache.

Thanks for pointing out the life span of PHP 7.2. It was installed as a Wordpress dependency.

Well, the Wordpress upgrade mangled the website, so I rolled back for now (using the old jail). I need to investigate that. But that's another story.

Thanks again.

Peter


----------

