# php installation problem



## jniedospial (Dec 20, 2022)

When I tried to open a PHP page through my IP to test if PHP is working it says that "It Works", but when doing it by IP/folder my web browser tries to download the file. I had already modified the httpd.conf file and restarted the apache server. I am using FreeBSD 13.1
The thing is that after installing mod_php74 it doesn't work at all.


----------



## richardtoohey2 (Dec 20, 2022)

(PHP 7.4 is EOL but that's not directly related to your problem.  But you might be better starting with PHP 8.1 or 8.2).

I don't understand from your description what is working or not working.

The "It Works" screen is (in my experience) the basic HTML screen that Apache will show - nothing to do with PHP at all.

FreeBSD 13.1, Apache, and PHP 7.4 will work fine, so something in your configuration needs adjusting.

Look in /var/logs to see what Apache is complaining about.


----------



## Alain De Vos (Dec 21, 2022)

Current default is php80


----------



## richardtoohey2 (Dec 21, 2022)

Default has been 8.1 in ports for almost a month:






						ports - FreeBSD ports tree
					






					cgit.freebsd.org
				




Not sure when the filters through to packages.

Active support from PHP developers for 8.0 finished almost a month ago.


----------



## Alain De Vos (Dec 21, 2022)

It's because i'm on quarterly. There it is still php80


----------



## moriis (Dec 21, 2022)

It sounds like you may not have properly configured your Apache HTTP server to handle PHP files.

In order to serve PHP files with Apache, you will need to have the mod_php74 module installed and enabled. If you have already installed mod_php74, you can check if it is enabled by running the following command:

Copy code
apachectl -M | grep php

If mod_php74 is listed in the output, it means that it is enabled. If it is not listed, you will need to enable it by adding the following line to your Apache configuration file (usually located at /usr/local/etc/apache24/httpd.conf):

Copy code
LoadModule php7_module modules/mod_php74.so

After making this change, you will need to restart the Apache server in order for the change to take effect. You can do this by running the following command:

Copy code
service apache24 restart

Once Apache is configured to handle PHP files, you should be able to access PHP files through your web browser by visiting the URL of the PHP file. For example, if your PHP file is located at /usr/local/www/apache24/data/test.php, you should be able to access it by visiting http://your-server-ip/test.php.

If you are still having trouble after following these steps, you may want to check the Apache error log (usually located at /var/log/httpd-error.log) for any error messages that may provide more information about the problem.


----------



## SirDice (Dec 21, 2022)

For www/mod_php74 to work, read `pkg info -D mod_php74` (also applies to any of the other versions; adjust where needed). 

Simplest for Apache is to create a /usr/local/etc/apache24/modules.d/001_php.conf:

```
<IfModule php7_module>
  DirectoryIndex index.php index.html

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

If I recall correctly the module is named differently with 8.x, so it will need something like this:

```
<IfModule php_module>
  DirectoryIndex index.php index.html

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

Only loading the module isn't enough for it to work.


----------



## jniedospial (Dec 22, 2022)

That's the error i get in logs.


```
[Thu Dec 22 16:13:05.836735 2022] [mpm_prefork:notice] [pid 901] AH00163: Apache/2.4.54 (FreeBSD) configured -- resuming normal operations
[Thu Dec 22 16:13:05.838187 2022] [core:notice] [pid 901] AH00094: Command line: '/usr/local/sbin/httpd -D NOHTTPACCEPT'
[Thu Dec 22 16:19:02.109342 2022] [mpm_prefork:notice] [pid 901] AH00169: caught SIGTERM, shutting down
```

I also got such a message after mod_php installation:
This port is deprecated; you may wish to reconsider installing it:

Upstream Security Support ends on 2022-11-28.

It is scheduled to be removed on or after 2022-11-29.
And still after typing in "http://192.168.100.30/cms" it makes me download a file.


----------



## SirDice (Dec 22, 2022)

PHP 7.4 is slated to be removed some time soon because it's EoL upstream. If this is something new you're better off starting with PHP 8.1. If you have some application that _requires_ 7.4 then you may be in for a surprise in the near future (the PHP 7.4 ports are going to be removed).


----------



## richardtoohey2 (Dec 22, 2022)

jniedospial said:


> That's the error i get in logs.


There are no errors in the logs - just three notices.

Did you finish the Apache httpd.conf configuration as per SirDice's email?  You have to tell Apache what to do with .php files otherwise it will download them.

Everyone recommends you move off PHP 7.4 before it is removed, but whether you go to PHP 8.x or stay with PHP 7.4 you will still need to to tell Apache what to do.


----------

