简体   繁体   中英

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 (eg 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM