How do I show / run a PHP file in a browser? As if it was a webpage

48,196

Solution 1

You need to download a server, and install it. If you want to go to the trouble, you can get XAMPP, and once it's installed, move the PHP file to the root of your installation (usually c:\xampp\htdocs\ on windows) and then use the url localhost/script.php in your browser.

Solution 2

You do not need a web server to execute PHP script unless you need to run it using a browser. Install PHP in your operating system and include PHP path in your environment path or variable (depending on what OS) you are using. If you are just using the script for the mailing stuff from your own computer, you don't need a web server like apache, you just need PHP and its cli program installed and you be run php scripts directly. Google the web how on how run PHP command line. Or visit this official documentation link: http://php.net/manual/en/features.commandline.php

Share:
48,196
SeekLoad
Author by

SeekLoad

Be benevolent above nice, not polite. Be morally correct, not immorally legal and politically correct. Do not do to others, as you do not want others to do to you. Ask me anything. I can not promise I will know the answer, but I can promise you I will respond accordingly. This is my web page that I bin working on when I became a member at stackoverflow to find solutions. http://www.seekload.50webs.com My web page is in finished, however small bugs may exist because I am not always active to update it. You can contact me at: FaceBook: https://www.facebook.com/SeekLoad YouTube: https://www.youtube.com/user/MrSeekLoad Linkedin: https://www.linkedin.com/in/liviu-rafael-nichiforiuc-56b3a265?trk=hp-identity-name

Updated on August 02, 2020

Comments

  • SeekLoad
    SeekLoad almost 4 years

    How do I run a PHP file in my browser? I know what the file is for and I know how it looks because I tested it online. But now I downloaded it locally to my computer and I do not know how to run it on my browser. Is there a way maybe to link it to a HTML like you do with JavaScript or CSS to make it work on a web browser also after it is online how will I manage it to work?

    If I can not link then maybe I can use iframe to see it in a HTML iframe. Is that possible? Yet the question is not based about iframe, but I do not exclude the iframe possibility too. That is why I ask of it too.

    Or even better, if there is a way to both link and use iframe for the PHP?

    The entire PHP file I got is a email function that works and looks a loot like a HTML and JavaScript file, but it is written in PHP. If I simply change the name to the file from PHP to HTML I can open it in the browser and it looks like a HTML file with few defects since it is a PHP file after all.

    The file I downloaded was from here: https://www.hscripts.com/scripts/php/registrationMailer.php

    And it is this PHP file I am specifically intrested in: https://www.hscripts.com/scripts/php/HMAD/hmailer.php

    NOTE: I am not asking of "PHP code is not being executed, instead code shows on the page" as the other page is asking. I am asking of "How do I show / run a PHP file in a browser? As if it was a webpage."

  • SeekLoad
    SeekLoad about 7 years
    Thank you this was the answer I was searching, sadly all the others did not understand the question and reported it as being a duplicate just because I added a second question about the iframe and that part is a duplicate, but actually it was two questions in one.
  • SeekLoad
    SeekLoad about 7 years
    I really do not understand why you got minus points for giving me the clear answer? and being one of a few who really understood the question... But okay maybe I was unclear for most of the people what the question was.
  • TurtleTread
    TurtleTread about 7 years
    Thank you. I'm quite amazed at the egos of some of these top ranked snobs (not sure if you saw the comments that were later deleted by a moderator). But just like the real world, we share the space. I believe this is a platform for constructive purposes and NOT a place for snobs to trample over others just because they have accumulated more rep points on the forum which is hardly a measure of expertise let alone good judgement or common sense understanding since a more commonly asked question gets most points whether you posted the question or the answer.
  • TurtleTread
    TurtleTread about 7 years
    As for inclusion of the PHP script in iframe, this means you will indeed need a web server to handle http requests and run your scripts. Easy solutions are web development environment packages like WAMP if are using windows. If you are using Mac or Linux system, I encourage you to install PHP, Apache and MySQL separately on your own because you will learn more if you are seriously considering doing web development.
  • SeekLoad
    SeekLoad about 7 years
    My friend maybe some of them feel me as a bit treating to them, because I "accumulated many rep points" in a very short time. I had this account a long time were I accumulated no point at all since I was not active. But all of a sudden because I started doing a personal job I needed help and questions started to flung into my mind like bullets after a hunted animal. And those question I posted here online. And this made me get a big amount of rep point in a very short amount of time. Although I am not at the top and far away from it, what I do have is pretty good for a beginner. @TurtleTread
  • SeekLoad
    SeekLoad about 7 years
    In some cases (few but still some) were I did post a question I found the answer by my self and I ended up posting the answer to my own question. How ever this was the first time I posted a question about PHP so it is not so strange if I was not that good at asking it. Usually I post questions about JavaScript. @TurtleTread
  • SeekLoad
    SeekLoad about 7 years
    As for web servers I use to have Linux, but my new laptop is fcked up. It refuses any ddsitro what so ever. I tried everything, so do not tell me of Ubuntu, I tried that too. In my life I had dussins of Linux as I use to have a doal boot system on all my laptops. But this is the first laptop I ever had to not install Linux, because it refuses to install it. So the QUESTION is: How do I make PHP to work offline when I have naither Linux or Mac. By the way I "HATE" Macintosh systems, but love Linux. @TurtleTread
  • TurtleTread
    TurtleTread about 7 years
    Yes, like I mentioned earlier, use WAMP for the web dev environments on Windows. www.wampserver.com You will need to look up how to configure wamp to setup virtualhosts on apache and etc. But for starters, you can start programming PHP in its default document root directory.