-1

I've been trying to get PHP working locally on my machine in Fedora 26.

I have httpd installed, and that seems to be working. When I first had it set up, typing localhost in my browser showed me the HTML contents /var/www/html/index.html, but not the PHP contents. <?php phpinfo(); ?> was not working, either.

I think PHP is also working, since php -r "phpinfo();" works in the command line.

I tried following the advice in this thread by adding AddType application/x-httpd-php .php to my httpd.conf file, and this made my browser try to download the PHP files instead of displaying them. Weirdly, when I took this line back out and restarted httpd, my browser is still trying to download the files.

Yahya
  • 706
  • 8
  • 23
Alec
  • 623
  • 5
  • 9
  • 21
  • What error did you get on your browser? – Yahya Dec 02 '17 at 20:50
  • @Yahya No error, it's just trying to download the PHP file instead of displaying it. Before it was not displaying PHP at all. Same thing across multiple browsers. – Alec Dec 02 '17 at 20:55
  • Do you load php module in apache configurations? – Yahya Dec 02 '17 at 20:58
  • I didn't realize I needed to do that manually. I just tried adding `LoadModule php7_module modules/mod_php.so` to the httpd.conf file, but then Apache failed to start because `/etc/httpd/modules/mod_php.so` is missing. This distro already had PHP, but I had to install httpd. Should I try to reinstall PHP so it works with apache? – Alec Dec 02 '17 at 21:16
  • So you should install `mod_php` – Yahya Dec 02 '17 at 21:34
  • @Yahya I reinstalled PHP, but it did not add a `mod_php.so` file. – Alec Dec 02 '17 at 21:35
  • It's a module, and it's not install with php itself. – Yahya Dec 02 '17 at 21:36
  • @Yahya running `dnf install mod_php` says it's already installed? `Package php-7.1.11-1.fc26.x86_64 is already installed, skipping.`, but there is no mod_php.so file still – Alec Dec 02 '17 at 21:39
  • @Yahya Aha! The file isn't called `mod_php.so`, because I guess that would be too obvious. It's called `libphp7.so`. So manually loading that module does fix all my problems. PHP is now being displayed correctly. Thanks! – Alec Dec 02 '17 at 21:49
  • Isn't good to sum up all this to an answer? If you ok with that, let me do it?! – Yahya Dec 02 '17 at 22:22
  • @Yahya Yeah, thanks for your help. If you want to summarize it as an answer, I will checkmark it. The answer [here](https://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them) is good, except for that the `LoadModule` line should reference `libphp7.0.so` instead of `mod_php55.so` which I did not realize. – Alec Dec 03 '17 at 18:39

1 Answers1

1

First of all add php AddType to to httpd.conf file:

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

And then load php module in apache configuration based on your php version that installed on your machine and you wanted to use:

LoadModule php7_module        modules/libphp7.0.so
Yahya
  • 706
  • 8
  • 23