PHP code opens in browser

3

I'm not able to install PHP on my machine. When I run a page in the browser, it returns the code written in .php.

I installed Apache 2.2.9 and PHP 5.2.1, and I made all the changes based on this tutorial

Even with all the changes, it continues with the same error. Apache works normally, when I call localhost, it returns me: Its Works, but PHP that it can not execute.

I use the Windows 7 Home Basic 86x operating system.

    
asked by anonymous 07.05.2015 / 06:25

3 answers

2

If it is showing the code written in the .php file it is possible that:

  • You have not placed the project inside a specific folder where it is accessible to localhost.
  • has placed this localhost accessible to you but is accessing your .php page using the file: \
  • Use a Xampp, Wamp or easyphp to install and configure everything automatically for you, in the case of these solutions the only thing you should do is put the project inside the root folder of localhost (htdocs for example) and call in browser with localhost.
  • 07.05.2015 / 12:13
    5

    As I read your question, I remembered a response from me on SOen , I believe this is the path:

    The problem is that maybe you have accessed the page through the FILE protocol instead of the HTTP protocol, as already said by Gustavo and Ricardo, I will explain the differences:

    Differences between HTTP and FILE

  • You should learn the differences between "http protocol" and "file protocol".

    HTTP protocol:

    HTTP functions as a request-response protocol in the client-server computing model. A web browser, for example, can be the client and an application running on a computer hosting a web site can be the server. The client sends an HTTP request message to the server. The server, which provides resources such as HTML files and other content, or perform other functions on behalf of the client, returns a response message to the client. The response contains completion status information about the request and may also contain requested content in your message body.

    File Protocol:

    The URI schema file is a URI schema specified in "RFC 1630" and "RFC 1738", normally used to retrieve files from within your own computer, if you open a PHP file directly the URL in the address bar will usually introduce this:

  • Second,yourneedtolearnabout"developer tools" with developer tools can detect "path", page headers and page responses to understand specific issues.

    Using developer tools in Chrome (in some browsers that use Webkit is similar): link

    Example:

    UsingFirefox: link

    Example:

    UsingSafari8: link

  • ToolsthatIrecommendtoinstallPHPonyourmachine:

    • link (windows, apache, php, mysql)
    • link (cross-platform, apache, php, mysql, pearl)
    07.05.2015 / 19:44
    -2

    If you are accessing via: file: /// C: / xampp / htdocs / The problem is this. Access only by: localhost / folder_of_your_project_in_XAMPP

    I hope I have helped

        
    03.10.2018 / 20:12