Why am I seeing the PHP code in the browser?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sirab33
    New Member
    • Aug 2009
    • 10

    Why am I seeing the PHP code in the browser?

    Hi All,

    Actionscript/Javascript programmer new to PHP.
    Just installed MAMP on my MacBook - no problems, all works well.
    Also successfully configured Dreamweaver to work with Apache/MySql (using official Adobe instructions)- again, no problems.

    I'm now trying to run some very basic PHP pages - intro/tutorials type stuff - but they don't work: content generated with regular HTML shows up correctly but anything in <?php> tags does not show up at all.

    Also, pages that are exclusively in PHP show up as literal code on the browser. Its as if I was looking at them in a regular text-editor.

    Obviously there's some issues having to do with PHP being incorrectly interpreted - any ideas on how to fix this?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Your server isn't parsing them as PHP. Sure you've got the server running? Files using correct extension (.php)? How about your error logs (apache) - anything in them?

    Mark.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      some more

      - did you stop the native Apache on Mac
      - using short tags when disabled (though you mentioned <?php ?>)
      - PHP module not loaded
      - php extention not registered in Apache

      Comment

      • sirab33
        New Member
        • Aug 2009
        • 10

        #4
        Gentlemen,

        In response to your questions, here's what I know:
        -the MAMP app has the green lights ON for both Apache and MySQL Servers which I take it means they're both running correctly
        -I am indeed using the correct .php extension in my file-names
        -re Apache error-logs - how do you access these?
        -re "did you stop native Apache on Mac?" - I don't know that I already had it running. I believe it comes with OS 10.5 but I'm on 10.4.11 so I don't think I ever had it pre-installed - but is this correct? How can I find out?
        -Not using short-tags - at least I don't think that I am. I know I didn't enable them anywhere...I basically copy-pasted some very basic PHP code from online tutorials so I'm pretty sure the code is right.
        -No idea if the PHP module is loaded or not - how do I check for this?
        -Same thing for PHP extensions registered in Apache - how do I check for this?

        thanks :-)

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Try at the command line apache2 -M, or httpd -M, not sure which it is on Mac.

          Comment

          • sirab33
            New Member
            • Aug 2009
            • 10

            #6
            Originally posted by Markus
            Try at the command line apache2 -M, or httpd -M, not sure which it is on Mac.
            ok, I'm sorry but I don't what "the command line" is - how/where do you access it?

            Note that I'm a straight coder, I don't have any experience with system-admin/server/OS type stuff - but I'm generally pretty bright and can follow directions very well if they're clear :-)
            So, where do I go to get this command line?

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by sirab33
              ok, I'm sorry but I don't what "the command line" is - how/where do you access it?

              Note that I'm a straight coder, I don't have any experience with system-admin/server/OS type stuff - but I'm generally pretty bright and can follow directions very well if they're clear :-)
              So, where do I go to get this command line?
              My bad - it's possibly called the 'terminal' in Mac. Not all that sure how you open it on a Mac, but google will be able to help you there.

              Mark.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by sirab33
                ok, I'm sorry but I don't what "the command line" is - how/where do you access it?
                the Command Line (alias CLI) is your access through the base system (Darwin), the most powerful tool on any Posix machine.

                to be found via Applications > Utilities > Terminal.app


                there’s an Apache even in OS 10.4 (though it is Apache 1.3, I believe), access via Applications > (System) Preferences > Sharing >> Web Sharing

                if you have the native Apache running, MAMP might not be accessed (because another programme is already listening on port 80)


                well, if you upgrade to 10.5 you get Apache 2 and PHP 5 built-in (there’s no built-in PHP in 10.4 but there are PHP packages to install)

                Apache conf / log should be something around
                /etc/var/log/apache/error_log
                /etc/apache/httpd.conf
                - there’s somewhere a section about loaded modules (use search option, the conf file is quite long)

                Comment

                • sirab33
                  New Member
                  • Aug 2009
                  • 10

                  #9
                  Originally posted by Dormilich
                  the Command Line (alias CLI) is your access through the base system (Darwin).

                  to be found via Applications > Utilities > Terminal.app


                  there’s an Apache even in OS 10.4 (though it is Apache 1.3, I believe), access via Applications > (System) Preferences > Sharing >> Web Sharing

                  if you have the native Apache running, MAMP might not be accessed (because another programme is already listening on port 80)
                  OK, so if it is the case that I had an earlier version of Apache on my OS 10.4, what should I do now? Can I disable it without disabling the new one? Or do I unistall the new one and the old one and start a new MAMP installation from scratch?
                  And if so, how? Is there an un-install for MAMP?

                  In terms of accessing Apache, I opened Application-->(System) Preferences-->Sharing - but there's nothing called "Web Sharing". There's something called "Personal Web Sharing" - which is currently not selected/checked on - is that the same thing? (Its under the "Services" tab. There are also "Firewall" and "Internet" tabs.)

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Originally posted by sirab33
                    OK, so if it is the case that I had an earlier version of Apache on my OS 10.4, what should I do now?
                    stick with MAMP (especially with 10.4)*

                    Originally posted by sirab33
                    Can I disable it without disabling the new one? Or do I unistall the new one and the old one and start a new MAMP installation from scratch? And if so, how? Is there an un-install for MAMP?
                    MAMP deinstallation* * is described on their web site (delete the MAMP folder)

                    Originally posted by sirab33
                    In terms of accessing Apache, I opened Application-->(System) Preferences-->Sharing - but there's nothing called "Web Sharing". There's something called "Personal Web Sharing" - which is currently not selected/checked on - is that the same thing? (Its under the "Services" tab. There are also "Firewall" and "Internet" tabs.)
                    I was guessing from 10.5. so you’re at the right place. and if it’s not checked, it’s disabled (so you also don’t need to worry about logs…)

                    then you’ll have to check MAMP’s documentation to find where you have to look for the config / logs (I only use MacPorts)

                    * you might also look at MacPorts
                    ** deinstallation on Mac is simple—just delete it

                    Comment

                    • sirab33
                      New Member
                      • Aug 2009
                      • 10

                      #11
                      I found this when I opened the php_error.log file - it says the following:
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
                      [10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
                      [10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98

                      so that help make sense of whatever's wrong?

                      Comment

                      • dlite922
                        Recognized Expert Top Contributor
                        • Dec 2007
                        • 1586

                        #12
                        it's just a notice, but you should always initialize your variables before using them.

                        Your error says:
                        1. A variable was used without being initialized.
                        2. It's called 'localtheme".
                        3. It's in /defined.inc.php
                        4. It's on line number 95.


                        Dan

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          doesn’t look like it’s related to being PHP not parsed. try finding the apache configuration file (httpd.conf)

                          Comment

                          • sirab33
                            New Member
                            • Aug 2009
                            • 10

                            #14
                            Originally posted by dlite922
                            it's just a notice, but you should always initialize your variables before using them.

                            Your error says:
                            1. A variable was used without being initialized.
                            2. It's called 'localtheme".
                            3. It's in /defined.inc.php
                            4. It's on line number 95.


                            Dan
                            ok - but I don't know any of this code - I didn't write it - it came with this sample file - there's this whole how-to/tutorial on Adobe's site for configuring Dreamweaver to work with PHP - "Setting up a PHP development environment for Dreamweaver" - its really good actually - here:


                            I followed it step-by-step and everything worked perfectly. Including a connection to MySQL - it all looked great.

                            I just can't get any PHP code to work and its beginning to drive me a little bonkers cause I followed every step exactly and every thing is supposedly fine: MAMP works, PHP is installed, I've got a Testing Server configured correctly, I've MySQL installed correctly, everything's done right - but PHP ain't working.

                            I'll ask again, and if someone can be a little clearer it would really help cause I can't make heads or tails out of some of these 1-line/half-phrase responses :-(
                            Ya'll need to remember I've got lots of programming experience but am totally new to this particular area of IT world and don't have the context or bgd. to understand some of the suggestions you've been making - and I hope I don't sound unappreciative, I just don't know what you guys are talking about :-)

                            1) Should I throw away the MAMP installation and start over?
                            2) If I start over, do I need to get rid of the the earlier version of Apache that came with OS 10.4? (I'm still on 10.4 - I'm not on 10.5)
                            3) If so, how do I do it?
                            4) Or, can I keep the earlier version of Apache but somehow disable it?
                            5) Is that even what's causing the problem?

                            Thinking about it logically, what are the possible things that can cause PHP to not work?
                            PHP is installed, it is loading - what gives?

                            Could it be some setting in the browser preferences?

                            What I don't get is why files that have both HTML and PHP in them ONLY display the HTML content and not the PHP content...

                            Any and all help would be greatly appreciated as I'm totally stuck on something that seems pretty simple...

                            Thank you much
                            -S

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              Originally posted by sirab33
                              1) Should I throw away the MAMP installation and start over?
                              2) If I start over, do I need to get rid of the the earlier version of Apache that came with OS 10.4? (I'm still on 10.4 - I'm not on 10.5)
                              3) If so, how do I do it?
                              4) Or, can I keep the earlier version of Apache but somehow disable it?
                              5) Is that even what's causing the problem?
                              1) if you don’t find a solution… maybe
                              2) no, it’s already disabled/not running
                              3) I don’t recommend messing with the OS
                              4) see 2)
                              5) I don’t think so

                              Originally posted by sirab33
                              Thinking about it logically, what are the possible things that can cause PHP to not work?
                              PHP is installed, it is loading - what gives?
                              well, a look at the Apache conf file should give you some answers

                              Originally posted by sirab33
                              Could it be some setting in the browser preferences?
                              no, PHP is a server thing, although display may vary.

                              Originally posted by sirab33
                              What I don't get is why files that have both HTML and PHP in them ONLY display the HTML content and not the PHP content...
                              even in the source code?

                              Comment

                              Working...