Why is my MAMP server returning my PHP test program source instead of executing it?

Anonymous March 25, 2014
Pinterest Stumbleupon Whatsapp

Hello Everybody.

I found this article here and I have started following the procedure: http://www.makeuseof.com/tag/build-basic-web-crawler-pull-information-website/

I did all OK when it comes to installing the server via MAMP and as a confirmation that it is working ok, I have installed WordPress locally and it is working fine.

The problem is here:

“Make a new file in your web directory, and call it example1.php – the actual name isn’t important, but the .php ending is. Copy and paste this code into it:

<?php
include_once('simple_html_dom.php');
phpinfo();
?>

Access the file through your internet browser. If everything has gone right, you should see a big page of random debug and server information printed out like below ”

When I do this all I get is the simple code in the file displayed on my browser.

How can I get rid of this? I need the code launched, not displayed!

So a quick recap: server is up and running, WordPress works perfectly locally but I can’t seem to have this php code work.

Any suggestions?

Thanks.

Vittorio

Ads by Google

  1. Vitovito22
    March 26, 2014 at 9:08 am

    Hello both.

    I have tried all the suggested solutions both I still had the same issue.

    So I decided to reinstall MAMP from zero, following a youtube tutorial that I found, and now it works.

    So, the good news is that it now works. The bad news is that I haven't managed to understand the issue as the MAMP installation is purely a couple of clicks.

    After the installation I have set the port preferences to 80 an 3306 (apache and MySQL) and the test works.

    Thank you very much for the time dedicated,
    I am loving this makeuseof.com site

    ;)

    Vittorio

    • Jeff F
      March 26, 2014 at 8:31 pm

      Vittorio,

      I'm so glad to hear that you've solved this! Please mark this question as resolved and have yourself a fine day!

      - Jeff

  2. Jan F
    March 25, 2014 at 10:03 pm

    Redundant question but which editor did you use?

    If you are using TextEdit for example you have to be careful about not using Rich Text but to put it into Plain Text (Format > Make Plain Text).

    From the top of my head I could think of the following scenario:
    You have been editing in Rich Text mode.
    You said File > Save and then selected "Web Page .html" as file format and named it index.php.

    The problem then is that the code you have written isn't actually saved as "source code" but instead gets wrapped into HTML paragraph element.

    Open up your the file in your browser using "http://localhost/example1.php" or whatever the correct name and address is and then take a look at the source code (right-click > Show Page Source in Safari).

    If you see some standard HTML tags something like what I described above happened.
    If you do (only) see the php code which it is supposed to be then it's something with PHP not working.

    As a final test name the file example1.php5 (or php4, whatever PHP version is running in your MAMP installation). If that works you need to reconfigure it so the ".php" extension is also mapped to the php interpreter.

  3. Vitovito22
    March 25, 2014 at 8:41 pm

    Hi Jeff.

    thanks for the prompt reply!
    The server isn't executing the code, you are right!

    Honestly, it is the first time that I try to do this procedure and I thought that the fact that wordpress is working fine was already a positive test.
    Is there a different way to test if the php module is online?

    ty

    • Jeff F
      March 26, 2014 at 12:01 am

      Vitovito22,

      You can check if your PHP module is executing php code properly by running the PHP function phpinfo(). This will give you information about your local php installation. I've taken the liberty of creating it for you and uploading it. Place it in your web directory and then open it in your web browser. You should see a page listing all of your php variables and configuration.

      Download phpinfo.php

  4. Jeff F
    March 25, 2014 at 7:49 pm

    Vittorio,

    It sounds to me like your PHP server isn't executing the code. Are you sure that your PHP module is online?

Ads by Google