I'm an absolute beginner when it comes to PHP. I have a standard html/css/js project that I'm editing with VS code and running a development server with the Live Server extension, which is running on localhost:5500.
I'd like to integrate a single .php file into my project which will handle a form submission.
Will I need xampp running on my local machine in order for the .php file to work?
At the moment the form action is sending a post request to my .php file but I get a 405 error from the browser.
Yes, A PHP processor is needed for the PHP code to work. If you have XAMPP installed (which means you have php), you can run
php -S localhost:5501 (make sure C:/xampp/php is in your PATH environment variable)
in the root directory of your project, this will start a PHP server and you don't have to move everything to the htdocs folder.
You need a server capable of processing PHP.
That doesn't need to be Apache HTTPD. If you do pick Apache HTTPD then you don't need to install it as part of XAMPP.
The Live Server extension is not capable of processing PHP so you need a different server. (I think I saw a PHP capable equivalent in the extensions library in VS Code, but I recall it being quite fiddly to configure.)
Yes, you need a server (apache or nginx) + php.
Xampp include all this in one application: x (SO) A (apache) M(mysql) P(perl) P(php)
Related
Could anyone please tell me how to run a php file locally on my system.
Currently I am using a server to run files.
I know both php & Apache to be installed.
I need to see out put of this program, for example:
<?php
$a=5;
$b=10;
$c=$a+$b;
print $c;
?>
Can you please tell how I can run these files of if I need anything more.
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
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.
In short:
Install WAMP
Put this file to C:\wamp\www\ProjectName\filename.php
Go to browser: http://localhost/ProjectName/filename.php
I just put the content in the question in a file called test.php and ran php test.php.
(In the folder where the test.php is.)
$ php foo.php
15
If you have apache running, put your file in server folder for html files and then call it from web-browser (Like http://localhost/myfile.php ).
3 easy steps to run your PHP program is:
The easiest way is to install MAMP!
Do a 2-minute setup of MAMP.
Open the localhost server in your browser at the created port to see your program up and runing!
I just installed apache and php on a windows 7 installation.
in the apache htdocs directory I put a file called "testing.php"
in it I wrote
<?php
echo "Maple|Pine|Oak|Ash";
?>
when I visit the page though it just spits out everything (rather than actually echoing the words) .
this is my first time running a web server or anything so I was wondering what I am doing wrong?
You need to install PHP also. Apache does not come with PHP in it, it has to be installed and properly enabled. Consider WAPM (to learn .htaccess too, for Linux hosting) or IIS Express + Web Platform Installer (+ PHP + PHP Win Cache + URL Rewrite - these are found in WebPI and are easy to install).
Does apache or nginx must be installed before I can run my PHP files in browser?
Django itself has a run-server for testing python codes.Is there any similar way to test PHP files?
Your options is:
Install web server, as you said.
Use web server, as JohnP suggested.
Install php-cli, run your script from console, save output to html file and open it in a browser.
Actually, you can't normally "run" php files in browser. Browser can only send requests to server and display script's output.
There is a built in web server from php 5.4.
Before PHP 5.4 you must install a web server to execute php files in browser
Yes. You need something like nginx or Apache. Either install one of those (on say your local machine). OR, see JohnP's comment - a new feature released recently.
In testing our site it would be so much easier to use PHP include offline. Essentially rather than put a page together for the purposes of testing, we would rather just include the various html files from their respective areas.
Our macs do not render PHP pages when offline and just show the source code. Is there a way to make them?
You need a local webserver in order to run php in your browser.
check out mamp or zend server
Once installed you can type localhost and whatever is the default directory will show in your browser. What I usually do is instad of just accessing everything through localhost I create an alias in the /private.etc/hosts/ file and the http.conf file in mamp
You would need a local web server to render any PHP code. MAMP might help you : www.mamp.info
To include HTML code into php with include() or require() you'll have to change the extension of the files from .html to .php even if no PHP code is inside them.
Also you could use a localhost server. There are mainly 2 of them for Mac:
Mamp
Xampp
I use the latter and I think it's the best. I had some trouble with Mamp years ago while Xampp worked just fine.
You have to make a php server. Free MAC php/ mysql server http://www.mamp.info/en/index.html
I'm starting a new project using Linux and PHP, but for the early dev state i'm now, I'm trying to use XAMPP for now.
I'm Running Ubuntu 10.04 x64 on a laptop, And got everything I need. The site I should build is based upon CodeIgniter and some implementation of smarty, but I think this is not that important because the same site runs pretty well on windows (with XAMPP )
The Problem I have is, if I put some php file on the root (like foo.php) with phpinfo() on it, the server parsed it as it should be, but when I try to get the url for one CodeIgniter app (as http://localhost/site/site.php ), Firefox tries to download the file & Chrome alerts some server error.
Again, the site as it works perfectly on windows (I share code using mercurial, if that's important)
I have around 3 codeigniter apps sharing the same System folder, and those get pickup by the loader (as site.php, admin.php...), but anyone I pick I still getting the same msg.
Also, the server list all the files perfectly, and tried to rename the file and then asked for the same (to see if the problem is cache or something) but I get a 404.
I'm also a newbie on apache and linux in general, I don't know what to do...
Check your apache.conf and httpd.conf. There are configuration entries called AddHandler which assign a module to each file extension which should handle this. If no module is provided the apache will send the file as plain text to the client.