php have a easy way to run a light server:
first cd into php file directory, then
php -S 127.0.0.1:8000
then you can run php
Answer from peter zhang on Stack Overflowphp have a easy way to run a light server:
first cd into php file directory, then
php -S 127.0.0.1:8000
then you can run php
You have to run a web server (e.g. Apache) and browse to your localhost, mostly likely on port 80.
What you really ought to do is install an all-in-one package like XAMPP, it bundles Apache, MySQL PHP, and Perl (if you were so inclined) as well as a few other tools that work with Apache and MySQL - plus it's cross platform (that's what the 'X' in 'XAMPP' stands for).
Once you install XAMPP (and there is an installer, so it shouldn't be hard) open up the control panel for XAMPP and then click the "Start" button next to Apache - note that on applications that require a database, you'll also need to start MySQL (and you'll be able to interface with it through phpMyAdmin). Once you've started Apache, you can browse to http://localhost.
Again, regardless of whether or not you choose XAMPP (which I would recommend), you should just have to start Apache.
How to install php and run it?
Can't access php files on localhost
Testing PHP on my local machine
php - How do I run a file on localhost? - Stack Overflow
How to run PHP files in phpMyAdmin?
How do I run my PHP file?
Can we run PHP in XAMPP?
Videos
If apache is rendering as text your php file, then apache is not configured to use php.
You need to find your httpd.conf file. Unfortuneately, different installs put this in different locations. Start looking in /etc/httpd directory structure. Other places might be /usr/local/etc/httpd. For the below, I'm going to assume /etc/httpd.
When you find httpd.conf, look for ServerRoot. This may be /etc/httpd. There should be a "modules" directory or symbolic link to a directory.
In this directory should be the php module if it was installed, say libphp5.so. First confirm you have a php module in the "modules" directory.
Next, we need to tell apache to use php.
Apache loads a default config file, httpd.conf, and additional config files typically in "extra" or "conf.d" directories. See if you have any of those, and within those should be a php.conf file.
If there is no php.conf file, that could be your issue. Here's a simple one:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
AddType text/html .php
DirectoryIndex index.php
What this does is tell apache to load the libphp5.so module, associate the .php extension to it, expect the output of the php script to be html, and if an index.php file exists use it when a user goes to a directory instead of specific url.
Well it looks like the problem was in my software sources, somehow the files got corrupted. I change to another mirror and it's working now.
How do I install php and run it? I've seen people running it on the command prompt on Youtube but I would like a way where I can run it on Notepad++ or Sublime Text (preferably Notepad++).
Hey,
I've never really worked with php before and right now im already failing to run a file.
I've downloaded XAMPP and when I start Apache and MySQL I can use the dashboard, phpMyAdmin, etc. But when I want to run a file, my browser can't seem to find it. My understanding is that if i have a file at the location C:\example\index.php , i should be able to run it on localhost/example . If i do that however I only get a 404 not found error that reads: "The requested URL was not found on this server.
Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 Server at localhost Port 80". Im pretty much at wits end here. I have tried accessing localhost/C:/example but that just gives me a 403 forbidden. I have also tried to change the xampp config file by changing some things from require local to allow all (or whatever its called i have forgotten). If anybody knows why i cant access my files please let me know
Ok, thanks for the more specific info, ppl may remove their downvotes now...
What you are proposing is a very common thing to do! You want to run your web application locally without uploading it to your host yet. That's totally fine and that's what your Apache is there for. Your Apache is a web server meaning its main purpose is to serve HTML, PHP, ASP, etc. files. Some like PHP; it first sends to the interpreter and then sends the rendered file to the browser. All in all: it's just serving pages to your browser (the client).
Your web server has a root directory which is wwwroot (IIS) or htdocs (apache, xampp) or something else like public_html, www or html, etc. It depends on your OS and web server.
Now if you type http://localhost into your browser, your browser will be directed to this webroot and the server will serve any index.html, index.php, etc. it can find there (in a customizable order).
If you have a project called "mytutorial" you can enter http://localhost/mytutorial and the server will show you the index-file of your tutorial, etc. If you look at the absolute path of this tutorial folder then it's just a subfolder of your webroot, which is itself located somewhere on your harddrive, but that doesn't matter for your localhost.
So the relative path is
http://localhost/mytutorial
while the absolute path may be
c:/webservices/apache/www
or
c:/xampp/htdocs
If you're working with Dreamweaver you can simplify the testing process by setting up your local server as a testing server in your project settings. Try it! It's easy. Once it's done, you can just press the browser icon with any of your files and it will open on localhost.
You can do it by running with following command.
php -S localhost:8888