# Apache and PHP



## lucas1 (May 27, 2021)

Good day.

Installed Apache24 and php74 with mod_php74.

Created for verification index.php with `<?php phpinfo(); ?>`.
But apache does not process files .php - just outputs the content.

In log :

```
[mpm_prefork:notice] [pid 4503] AH00163: Apache/2.4.46 (FreeBSD) PHP/7.4.19 mod_perl/2.0.11 Perl/v5.32.1 configured -- resuming normal operations
```
What you need to tell Apache to process PHP files ?


----------



## SirDice (May 27, 2021)

lucas1 said:


> What you need to tell Apache to process PHP files ?


Read `pkg info -D mod_php74`

```
******************************************************************************

    Make sure index.php is part of your DirectoryIndex.

    You should add the following to your Apache configuration file:

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

    ******************************************************************************

    If you are building PHP-based ports in poudriere(8) or Synth with ZTS enabled,
    add WITH_MPM=event to /etc/make.conf to prevent build failures.

    ******************************************************************************
```


----------



## lucas1 (May 27, 2021)

I did exactly that (quote):

`pkg install mod_php74`
Next, you need to tell Apache to process PHP files by creating a php.conf configuration file under /usr/local/etc/apache24/Includes/ with the following contents;

`vim /usr/local/etc/apache24/Includes/php.conf`

```
<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>
```
Save the file and restart Apache for the changes to take effect.

this through php-fpm is how it worked :apache process files .php

```
LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so

<FilesMatch \.php$>
     SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
```
But through  php7_module not worked.


----------



## SirDice (May 27, 2021)

You use mod_php OR php-fpm, not both.


----------



## lucas1 (May 27, 2021)

It's clear. 
Perhaps I do not know exactly which modules yet for mod_php enabled.
I decided to run in apache-php the classic way due to the fact that it is not possible to start ocsinventory-server through php-fpm .


----------



## SirDice (May 27, 2021)

lucas1 said:


> Perhaps I do not know exactly which modules yet for mod_php enabled.


The module is automatically enabled in httpd.conf when you install www/mod_php74. Using php-fpm is recommended but not all web applications seem to like it.



lucas1 said:


> I decided to run in apache-php the classic way due to the fact that it is not possible to start ocsinventory-server through php-fpm .


Yeah, that can happen. Add that `<FilesMatch>` bit of code to your vhost configuration, I assume ocsinventory has a `<VirtualHost>` configuration?


----------



## lucas1 (May 27, 2021)

Good.

But what logs to look at to determine the reason that mod_php not worked?


----------



## SirDice (May 27, 2021)

The standard Apache error logs. But if you get to see the source of the PHP scripts then it's a safe bet those `<FilesMatch>` directives haven't been applied correctly. You won't find an error in that case, it just doesn't work as expected.


----------



## lucas1 (May 27, 2021)

Generally, launched ocsinventory-server through php_fpm.

mod_php is deprecated as FPM is now used by default with httpd in event mode
# mod_php is only used when explicitly enabled or httpd switch to prefork mode

Maybe because of deprecated mod_php <FilesMatch> directives haven't been applied correctly .


----------



## SirDice (May 27, 2021)

mod_php isn't deprecated, php-fpm is _preferred_ yes, because it can handle Apache's event mode and that's the _preferred_ way to run Apache. mod_php only works in the "old" prefork mode. If you try to start Apache in event mode and have mod_php loaded it's going to complain about it and fail to start entirely.


----------

