localhost downloading the *.php files instead of viewing it - php

I have upgraded from PHP 5.3 to PHP 5.5 (Im running Ubuntu 12.04) By removing the PHP and re-install the 5.5 version and everything worked fine during the installation,
now when i open my localhost and try to open any website on my localhost it doesn't execute index.php but it download the index.php as a text file.
i restarted Apache2 and saw this posts
nginx localhost is downloading php files in browser, instead of serving them?
and localhost doesn't execute php files after update to Maverick/Yosemite OS but it doesn't help.
Help would be appreciated,
Thanks.

Try using different browser for opening php files. It was not working for me when I opened php files using Chrome. But the same worked in Firefox browser.

You could try adding this to your conf or htaccess:
AddType application/x-httpd-php .php
or do a proper installation.
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

i think you should take a look at your php module in your apache2. As far as i know php runs as a module in apache so search your httpd.conf for loaded modules and look at your /var/log/apache/error.log or where ever your apache error log

php is not correctly installed on your server otherwise it would have not downloaded the php file. On Ubuntu terminal try
php -v
under your
/etc/apche2/mods-enabled
see if you have php5.load in the current directory.

Related

How to run a PHP file from ubuntu?

How to run a php file from ubuntu platform in the localhost?
I have also installed LAMP in my system.
When I try to run the php file, in the browser, it says "The requested URL is not found-404 ERROR found".
I do not know how to proceed with this.
My php files are in the directory as shown here "/usr/var/html/a.php".
There are two options.
Access the php file through a local webserver(ie thru a local website). The web-server will deal with the requested php file. It will use either,
Inbuilt PHP module to interpret the php file, or
PHP through CGI (eg.CGI, FastCGI)
If your apache(check if apache is running using service apache2 status!!) is set to the default configuration, this could be as simple as
http://localhost/path/to/your.php
Remember by default, the base directory for apache is /var/www/html/, so you need not include this in the url.
Use the php binary directly from a terminal.
php /path/to/your/file.php
After installation of Lamp system in Ubuntu. Please follow the below two steps to run your php file.
Place your php file (.php) in /var/www/html/ (default path)
Please run url as localhost/withfilename.php
Example : I have placed welcome.php file in the /var/www/html/welcome.php
then url will be http://localhost/welcome.php

PHP won't load with php.ini file in place

I have set up a MAMP server on my local computer.
The server runs fine, no problems, but I need to install the mcrypt extension on PHP as I need to install Laravel.
I've been following this tutorial:
http://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-9-mavericks-development-server/
I have an issue with the last step. When I create a new php.ini file using the following Terminal command, PHP refuses to run at all.
sudo cp /etc/php.ini.default /etc/php.ini
Basically with no php.ini file in the etc/ folder, the PHP works fine (PHP info pages load, sites using PHP run fine), but when it's in place, no PHP works and loading a PHP info page returns a blank white browser window.
Am I missing something?
OK I managed to figure out the issue, here's the solution for anyone stumbling on this in the future.
short_open_tags was disabled in the php.ini file. I simply enabled this, saved the file to the /etc folder and rebooted the Apache server and it works great now. I needed to modify the php.ini file again to add the mycrypt extension but now works great.

PHP displays a code in browser rather then execute but only for virtual hosts

I have installed fresh LAMP on Ubuntu 13.10 After installation PHP works fine if i put the PHP code to default localhost web folder /var/www
I created the virtual host. I did it as usually before and never had problems
I added the file to /etc/apache2/mods-enabled and activated
but then when i enter this virtual host in browser i can see the code of my index.php file in the browser.
Also when i execute php code from command line i can see source of the code and it is not executed.
What can this be?
Try to use <?php and ?> not short tags, or if you want really use that (their use is discouraged due to compatibility issues), ensure that php.ini configuration have:
short_open_tag=On

Page not found: Running a php file on an Apache sever

I get page not found error when I try to run my php file running on the root folder of my apache. Other php files run fine(anyway this is a magento based site). Is it because i transferred the file through FTP?
Can a server be configured not to run some specific files? How can i get round this? has is got something to do with .htacess?
Be sure you uploaded your file into the /www or /httpdocs subdirectory.
If so, check the permissions of your file.
Does the fiel have the same extension as the other php files that work.
ie. myfile.php or myfile.php4
The default config for apache specifies that php files have the extension "php4" as php version 3.0 and before are not compatible with the current versions. Usually the plain "php" extension is re-enabled but maybe not in your case.

HTML recognizes my PHP code as comments

I want to create a Chrome app, but I have the same problem as this guy. When I add the .php extension and I run the app, it downloads the file.Should I do something more? I have installed PHP (if that means to download and extract the file in the same folder with my app, I'd be wrong). I'm a beginner... :(
EDIT
Some of you told me to install Apache or IIS. I said earlier that I want to create a Chrome app.
Do I need to install Apache? Where would I run it (I don't have a local host, Chrome extensions and apps use the "chrome-extension://" prefix, which means it is hosted on the browser). What about more information (you've all been helpful by now)?
EDIT 2
It turns out that Google Chrome doesn't allow developers toto run PHP inside Chrome apps.
Thanks for your help!
This means the server is either missing the PHP plugin (either CGI or otherwise) or the the server doesn't recognize that it must pass a file with the extension in to PHP for pre-processing.
If you're on a host out of your control (e.g. using GoDaddy) then make sure they allow PHP (some of the free hosts won't have PHP as they deam it an unnecessary security risk). If it's your own server, make sure you installed PHP and it's enabled.
If it DOES has PHP installed, but you're not getting it to parse, you'll need to bind the .php extension to the PHP handler using either an .htaccess file or the config.
For apache, your http.conf needs the following (assuming you already have PHP plugin):
AddType application/x-httpd-php .php
Or for something more broad, place an .htaccess file with the above code in your hosted directory.
EDIT
You mentioned you installed PHP. I'm going to assume you're using Apache, as IIS now has a Web Extensions installer that would (typically) take care of the "hard part" for you. So, having said that, open your http.conf (Usually located in C:\Program Files\Apache Software Foundation\Apache2.2\conf\ [using 2.2 as a demo version]). Within that file, at the bottom, add the following [replacing files paths to those that correlate to your own install]:
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
A better reference can be found by googling "install PHP [version] on [webserver]". Here's just one of the results I was able to locate.
Do you have a server installed on your machine? PHP is a server-side script & unlike Javascript you cannot run it without a server.
PHP files are server side code only. So you need to install a local server like APACHE to get the PHP script to execute.
PHP must be run on a web server, not your desktop. Install PHP on your webserver, then open the PHP file from a web browser via: http://localhost/yourfile.php
You need an Apache server on your computer. download xampp: http://www.apachefriends.org/en/xampp.html and put your files in the htdocs folder.
EDIT:
This will explain how to install a PHP environment: http://www.tanguay.info/web2008/tutorial.php?idCode=phpDevelopmentQuick

Categories