Wednesday, 24 April 2013

PHP script downloading instead of executing in browser

To run a PHP script in Ubuntu or likewise other Linux-based distributions, your file should be located in the /var/www/ folder. To run the script in the terminal, you can type php filename.php when in /var/www folder. To run the script in browser, type the url as localhost/filename.php.

If opening the file in the browser, downloads the file, instead of executing it, you need to install some packages. To do this, type the following in a terminal:

sudo apt-get install apache-mod2-php5

Now open the file again in the browser by using the url shown above, and your script should be up and running.