0

I am trying to get the standard info.php

<?php

phpinfo();

?>

to run on a Apache 2 server and a Ubuntu 16.04. machine. However, even after adding

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

to the configuration file /etc/apache2/apache2.conf and verifying that php7.0 has a .conf and a .load file in /etc/apache2/mods-enabled/, the info.php in /var/www/html is only downloaded, but does not show the intended content.

Does anyone have an idea what this is caused by?

Edit:Deleted the $ behind Filesmatch .php and also tried putting quotation marks around ".php", to no avail.

Paul Rousseau
  • 571
  • 2
  • 7
  • 21
  • You need to specify your php version. Try `SetHandler application/x-httpd-php5` – Amit Verma Jan 17 '18 at 17:23
  • also try restarting your apache after adding such a change. – YvesLeBorg Jan 17 '18 at 17:25
  • You shouldn't have to do anything like that to get Apache/PHP working on Ubuntu 16.04. What is your output from `php -v` in the terminal? Have you tried `sudo service apache2 restart` ?? What do you see if you go to `http://localhost` ?? – Brian Gottier Jan 17 '18 at 17:27
  • @starkeen: Unfortunately, I changed it to no avail. – Paul Rousseau Jan 17 '18 at 17:28
  • @BrianGottier: php -v gives :PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies – Paul Rousseau Jan 17 '18 at 17:29
  • @BrianGottier: I see the ubuntu apache2 "It works" index.html page, so the server is running. – Paul Rousseau Jan 17 '18 at 17:33
  • I may have had an installation or two where the default site was not set up in virtual hosts. If you go to /etc/apache2/sites-available , then you see the list of sites. You probably have one called 000-default, or something like that. Open it up with nano, and make sure it looks normal (dirs are where you think they are). Then, `sudo a2ensite 000-default`... then reload `sudo service apache2 reload`. – Brian Gottier Jan 17 '18 at 17:36
  • After your last comment, I'm wondering if you correctly installed PHP. I'll leave you an "answer" showing how I do it. – Brian Gottier Jan 17 '18 at 17:40

2 Answers2

0

I've got a few Ubuntu 16.04 servers. They mostly work with little effort. I'm going to post my install commands, just so you can compare with what you did:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 apache2-utils
sudo apt-get install mariadb-server mariadb-client
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0
sudo systemctl restart apache2

# modify dir.conf so index.php is the preferred file
sudo nano /etc/apache2/mods-enabled/dir.conf
Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
  • What happens if you rename Apache's default page: `sudo mv /var/www/html/index.html /var/www/html/index.php` and then go to `http://localhost` in your browser? – Brian Gottier Jan 17 '18 at 18:24
  • According to this: https://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them your browser might be caching the php response. Try a different file name and see what happens. – Brian Gottier Jan 17 '18 at 18:26
  • 403 Forbidden nginx/1.10.3 (Ubuntu) – Paul Rousseau Jan 17 '18 at 18:31
  • Well that's the problem. Seems like you've somehow got 2 web servers running at the same time. They're probably both listening on the same port or something. As far as I know, unless you set them up on different ports, you can't be using nginx and apache at the same time. – Brian Gottier Jan 17 '18 at 18:35
  • That's it. After stopping the nginx server and restarting the apache one, it works, but now the php file is displayed as text and not executed, but it solved the above question, so thank you. – Paul Rousseau Jan 17 '18 at 18:39
0

It looks like some apache modules aren't loading. Check in your httpd.conf if this line is uncommented:

LoadModule php7_module modules/libphp7.so

https://secure.php.net/manual/en/install.unix.apache2.php

dnloop
  • 161
  • 2
  • 5