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!
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
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:
If it works, it should look like this:
This is printed from a php script
*I am generally not in favour of putting
phpinfo() in a test page.