I'm very interested to get started with PHP, but a little lost with how to preview the PHP pages I've been creating. I started fishing around the internet and found some cool PHP tutorials and have been incorporating PHP into a new website I am designing. Problem is I can't preview the PHP pages in my local browser. 😕

    You need some server to view the php pages and also php installed on the computer. One good server is Apache (free server). You can download it from http://www.apache.org and php from www.php.net.

    Hope that sets you in the right direction.

      If you are using Windows and have IIS, then you are probably best served by going to http://www.php.net and downloading the latest install for windows.

      It is an installer, so there is no massive configuration you have to do before it will run. The default install should be fine for you.

        I DID IT! Well, sortof. And I still have a little problem.

        I did download apache and PHP and installed them both easily using a installer called XAMPP. After that, I created some PHP files, but still having some problems viewing the PHP pages in the browser.

        Basically, I create a PHP page called index.php and when I try to open it my browser (Firefox) sends back a pop-up message asking what application I want to open the PHP file with. For god's sake! Puleeze somebody help! This is getting to be too annoying. I just want to get started testing pages locally. Thanks. :o

          First make sure that your server is running (XAMPP in your case) and any PHP file that you write and want to view with your browser need to be on your server (XAMPP) this would be the htdocs folder which is located in a default install of XAMPP at C:\apachefriends\xampp\htdocs. Put your files there. then to see your PHP file you need to type into your address bar http://localhost/theNameOfYourPHP.php and you will see it. XAMPP uses the htdocs folder to serve web pages.

          You can also download PHP Designer 2005 or 2006 (just came out) I think it is from MPSOFTWARE, but a Google search for PHP Designer will give you the site. Using that program you can view your PHP right in the editor, but before you can you need to tell the editor where your php.ini file is or possibly the php.exe I can't remember but it doesn't matter they are both located at C:\apachefriends\xampp\php on a default install of XAMPP.

          The thing that I like about XAMPP is you can switch from PHP4 to PHP5. Hope that helps you out. I have been using XAMPP for about two years and also use WAMP for PHP5 and XAMPP for PHP4. Of course you can only use one server at a time because they fight over the MySQL server even though each has its own MySQL.

            Houdini wrote:

            First make sure that your server is running (XAMPP in your case) and any PHP file that you write and want to view with your browser need to be on your server (XAMPP) this would be the htdocs folder which is located in a default install of XAMPP at C:\apachefriends\xampp\htdocs. Put your files there. then to see your PHP file you need to type into your address bar http://localhost/theNameOfYourPHP.php and you will see it. XAMPP uses the htdocs folder to serve web pages.

            Geez! I must have the worst luck. I've just been tinkering around with this for the last hour and a half, downloaded the PHP designer, and still cannot browse PHP pages in my browser! PHP Designer seems cool, but I really am content with using Dreamwever and Notepad for right now.

            Man, this sucks. All I want to do is open my browser, hit File > Open... and then open my PHP creations. I don't know what else to do. I'm about to give up on this. I mean, I've already downloaded and installed XAMPP and read through a bunch of stuff.b 😕

            Somebody throw me a life line! Is is abolutely necessary to save all my PHP file in the "C:\Program Files\xampp\htdocs" folder? F! I already have a nice system of where I save all my website stuff. 🙁

              Yes because the server that recoginzes PHP is the apache server and that is where you have to place your web files. PHP only runs on a server (a web server like Apache or even IIS, but you do not have PHP on the IIS server).

              You can only view PHP in your browser when is is looking at a site that has a server that supports PHP. Since XAMPP installs PHP as well as MySQL and Perl you have to have that server running and the file has to be running. To test your new XAMPP copy the below code and put it in the htdocs folder on your local server (Apache). Save the file as phpinfo.php in the htdocs folder then with the server running type into the address bar http://localhost/phpinfo.php and it will show what all is installed on your server.

              <?php
              echo phpinfo();
              ?>

              What you could do is make your localhost a favorite or bookmark in your browser and go to at least its root, or you could make an HTML or PHP home page with index.html or index.php and make http://localhost/index(html/php) a favorite or bookmaek.

              For PHP Designer to show a PHP it must have access to your php.exe file which is in the apachefriends/xampp/php folder and you have to tell it where the file is for it to work so it is possible for PHP Designer to display PHP if it know where the above mentioned file is when you are debugging a script.

              You can not simply write a PHP script and put it anywhere and expect a browser to read it, PHP must be interpreted by the server then what ever output it give will be HTML that PHP generates.

                Houdini wrote:

                To test your new XAMPP copy the below code and put it in the htdocs folder on your local server (Apache). Save the file as phpinfo.php in the htdocs folder then with the server running type into the address bar http://localhost/phpinfo.php and it will show what all is installed on your server.

                <?php
                echo phpinfo();
                ?>

                Good stuff! Now, I have all my PHP files in the right place on the hard drive. They are all in folders within the htdocs folder. For ex: "C:\Program Files\xampp\htdocs\phpinfo.php". When I typed in the local address into the browser the way you described above (http://localhost/phpinfo.php), I could preview the page just fine. Thanks! 🙂

                However, when I try to open the browser and do FILE > OPEN, then go to "C:\Program Files\xampp\htdocs\phpinfo.php", it doesn't open!

                1. In Internet Explorer, when I do FILE > OPEN pointing to "C:\Program Files\xampp\htdocs\phpinfo.php", the page actually opens up in the Dreamweaver 8 Editor for PHP instead of the browser!

                2. In Firefox, when I do FILE > OPEN in firefox, it asks for the application of which to open phpinfo.php with. I've tried php-win.exe and php.exe and still it won't load.

                🙁

                  Evidently Dreamweaver has the php.exe and php.ini files and or supports it, I do not have or use that software (I like free stuff). I don't know how your XAMPP is set up but I have mine to only run if I invoke it, but my WAMP server starts up on boot since I use it more. I too use Firefox when writing code and normally browsing the web. I would say that if Internet Explorer opens it using your Dreamweaver then when you try typing the filename in and it asks for a program just tell it the .exe file for Dreamweaver.

                  If you want to change your php.ini I am not sure which directory it is in but I think XAMPP puts a copy of the php.ini in its folder and that is the one that needs changed, but I think there is also one in the php folder which would be c:\apachefriends\xampp\php\php.ini
                  the other location in the apache server is
                  c:\apachefriends\xampp\apache\php.ini

                    Junkie wrote:

                    In Internet Explorer, when I do FILE > OPEN pointing to "C:\Program Files\xampp\htdocs\phpinfo.php", the page actually opens up in the Dreamweaver 8 Editor for PHP instead of the browser!

                    This is because IE is so tightly coupled with WIN it knows what applications are associated with file types. Dreamweaver will not parse the PHP, it will only open the file for editing.

                    Junkie wrote:

                    In Firefox, when I do FILE > OPEN in firefox, it asks for the application of which to open phpinfo.php with. I've tried php-win.exe and php.exe and still it won't load.

                    As FF is not so coupled it does not know, hence it has to ask.

                    Doing this type of operation is the equivilent of double clicking on the file in WIN explorer!!

                    I know others have tried to explain this but I will give it another go.

                    A browser, any browser, does not know how to parse PHP. All a broswer can parse (run) is HTML, CSS and javascript. Thus when you use a browser to open a PHP file it doesn't know what to do with it, and thus asks you what application you want to use to try and parse it.

                    Put simply, the ONLY application that can parse PHP is php.exe!!!

                    You MUST call the php file via your webserver (apache), so that the php file is parsed by php.exe and all your broswer is receiving is HTML.

                    You CANNOT double click on the file.
                    You CANNOT use file/open to view the file.

                    The ONLY way you can run the PHP is by calling it via HTTP

                    ie. http://localhost/index.php

                      4 months later

                      I am having the same problem, mostly related to getting the browser (IE) to render the .php file. I am running Apache and am requesting the page through http://localhost/. Is the solution to modify the php.ini file? If so what needs to be chnaged it's kind of a long file.

                      I'm running XP with SP2.

                      Thanks!

                        i use a simple stand alone server... MSAS, free to download and suits my need without lots of messing around, run one program and it runs in the background

                          kimminwoo do you have PHP on your local machine? It sounds like you do and if so write the phpinfo script as below:

                          <?php
                          phpinfo();
                          ?>

                          save that file in your htdocs folder and call it info.php then type http://localhost/info.php into your browser if PHP is properly installed you should see several tables of information about your PHP installation. If you do not see this information you have an improper or incomplete install and need to correct it.

                            Junkie, Please realize that running Apache and PHP on your local machine is possible and I applaud you for not being scared to just jump right in and do it that way. Be aware that you are trying to master multiple skills at the same time: (a) learn PHP, (b) install and run a web server, and (c) configure the web server to run PHP. While these are all great skills, you should know that lots (most) people stick with learning PHP first and then they do the other things later. There are lots of inexpensive companies who offer PHP web hosting where you can let them run the web server and you just FTP the PHP files up to their machine and run them there. I mean, the way you're doing it is great - but if it gets to be too much at once, don't forget that there is an easier way to experiment with PHP - you don't have to run the web server on your local machine.

                            In fact, you're going to want a database pretty soon and that's going to mean installing and configuring something like MySQL too. And when a client pays you to put up their site, it's very possible that the code you write on your local machine isn't going to work in a different environment because they have PHP configured diffrently so sometimes it's better to learn PHP where you will actually be hosting the web site. You're not doing it wrong, I'm just saying that you should be aware that there's another way.

                              The cause of my problem is quite silly but thought it might be worth posting. I had a bug in my httpd.conf file in my AddType entry (the dot was in the wrong place). The result the .php file was not getting processed, which resulted in IE not understanding the file and asking me what program to open the file with.

                              One I corrected the problem the .php file render just fine.

                                Heh. We all do that once in a Blue Moon. Configuration, configuration, configuration. Say it repeatedly whilst spinning around on your head on a smooth surface, possibly after imbimbing large quantities of your favorite beverage. Makes you feel queasy, doesn't it?

                                If I had ten bucks for every time I'd fat-fingered a config file, I could retire now.

                                Y'all have fun with PHP ... 😃 and welcome to the new kids!!

                                  Write a Reply...