1

I am not sure if this is Unix related, but I can't really see what it would be, if it wasn't Unix related. I'm running a Ubuntu Server, and I'm trying to execute a .php script on my website when someone presses a button. Although, when it gets to triggering the script, it just shows the script code, and does not actually run it. Do I need to install something in order to make this work? I can confirm that this works on an actual webspace. I appreciate any help I can get!

  • You'll need to tell your webserver to execute php code, often by adding a handler for it. You may need to install something, you haven't given us a lot of detail about it so far like which web server you're trying to use (apache, nginx, lighttd, ...). Also, this question is probably better for Super User than here, since configuring a web server isn't really Linux specific. – Eric Renouf Sep 25 '16 at 15:21
  • Sorry. I'm using Apache2. – ApplePie Sep 25 '16 at 15:22
  • How will I tell it to execute the code? I am using "action="script.php" " right now. – ApplePie Sep 25 '16 at 15:23
  • Try going to the PHP install guide and start with step 7 (you can use apt-get to install php if it isn't already there instead of trying to build from source). Or the help page from Ubuntu – Eric Renouf Sep 25 '16 at 15:25
  • Please skip the excuses and get straight to the point. – Rein Sep 30 '16 at 9:40
6

In order for Apache2 to handle php requests, you need to install php. Since you are using Ubuntu, you can install by issuing these commands:

sudo apt-get install php5

...and:

sudo apt-get install libapache2-mod-php5

You then need to enable the apache module with:

sudo a2enmod php5

You can of course install later versions of php if you desire, and if they are avialable for your Ubuntu version.

When you are done with the above, restart apache with:

sudo service apache2 restart

When you have done all of the above, try if your web server handles php correctly by putting something really basic* in the root directory of your web server like:

<?php
    echo "<h3>Hello!</h3>";
    echo "<p>This is printed from a php script</p>";
?>

Assuming the script above is in a file called hello.php, point your browser to it:
<your-ip-address>/hello.php If it works, it should look like this:

Hello!

This is printed from a php script


*I am generally not in favour of putting phpinfo() in a test page.

|improve this answer|||||
  • Thanks for responding. When trying to execute the apt-get install commands, I get these errors: "E: Package 'NAME' has no installation candidate". I'm running a Ubuntu Server, but I don't think that matters. Are you able to help me out on why this is happening? I just ran apt-get update and upgrade. – ApplePie Sep 25 '16 at 19:02
  • It would be helpful if you could post the version of Ubuntu (lsb_release -a) you are using. Depending on that php5 may, or may not, be available. You may have a later version of php in the repositories for your Ubuntu version. – maulinglawns Sep 26 '16 at 6:12
  • Ubuntu 16.04.1 LTS (Codename xenial) – ApplePie Sep 26 '16 at 11:46
  • I can't find the "libapache2-mod-php5" package though. Not php7 either. You able to help me at this point? – ApplePie Sep 26 '16 at 12:09
  • php7 should be available in Ubuntu 16.04. What happens when you try to install with sudo apt-get install php7.0? – maulinglawns Sep 26 '16 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.