I'm looking for something like http://phpfiddle.org/, but completely local. I don't want to commit to installing something as complex as Apache, then PHP on top of that, just to try out code when I'm offline. Is there anything that can run PHP 5.5 on the local machine without installing an entire server underneath it?
There's no need for a server if using PHP 5.5+ - it has a built-in server (http://www.php.net/manual/en/features.commandline.webserver.php)
Just use:
$ cd ~/public_html
$ php -S localhost:8000
As a minimalistic solution, on the command line you can also start php in interactive shell with php -a that will execute the commands you enter line by line. I often use it for testing small snippets of code.
You can download a portable webserver http://www.usbwebserver.net/en/ and use this script under it https://github.com/websiteduck/Run-PHP-Code
You can install either XAMPP or WAMP server locally if you find it complicated to configure PHP for Apache.
You should try phpsh as well. It is a php interactive shell from the facebook developer folks with history, tab completion and quick access to documentation.
The project is maintained on github.
Use psysh which is a wonderful tool for the purpose you described.
If your project is on Laravel, then it's "built in", as tinker, so you can invoke it as php artisan tinker.
I really dont think so. but it isnt so complex as you think.
if you are on windows - just download: http://www.wampserver.com/ - it will install the whole server for you (mysql&phpmyadmin,php5).
on linux - got to google: install lamp to [your-linux] -- and follow the simple instructions
For Windows Users:
Check out the ezPHP GitHub project. Per the project description...
EzPHP is an alternative to Xamp/Wamp. EzPHP is the easiest way to setup a PHP development environment for learning PHP programming on Windows.
The scope of this project is to provide a single .exe file that will get you a PHP developing server.
Link - https://github.com/marcomilon/ezphp
Setting it up was simple. Download the exphp.exe file and drop it in a folder. When you run the exe, it will launch the server and generate a public_html folder and index.php file. Follow the instructions in the command window and navigate to http://localhost:8080. Now you can start developing in the public_html folder and refresh your browser to see your changes.
This is what I do for simple pages:
Download php in zip and extract (PHP 8.0.2 ~25MB)
Then run
> php.exe path\to\your\index.php>path\to\the\output\index.html
Open the result index.html with your favorite browser
You have to find a workaround for your _GETs though.
If you use a development environment, like Aptana Studio, you might as well click on the Run As, and run it in your preferred browser. You need WAMP/XAMPP to be installed and running in order to do so.
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 know this is a newbie question, but i want to study php. i have phpeclipse and its running well, the problem is when i run a simple html file with the default server the page says cant display this page and thats it. i dont know if i need to install a new server or is there something wrong with the server configurations. ive tried installing tomcat on my computer but i cant see it under windows->preferences->server->runtime enviroments->add. iv also tried under the same page to fetch geronimo v2.2 and 3.0 and the dependencies were wernt satisfied. iv also tried the repository for zend debugger. what do i need to do in order to compile and see php and html pages with php eclipse?
You don't need to compile PHP.
Depending on your operating system and PHP version there are a few options.
As of PHP 5.4+ you can run your application using PHP's built in server, on the command line, if you cd into your website root directory (i.e. where the index file is) and then run the following
php -S localhost:8989
Then if you navigate to http://localhost:8989 in your browser you should see your application.
If you are unable to run the inbuilt web server, you need to look at Apache2. Most PHP websites run inside the Apache 2 web server. You will generally need a *AMP (WAMP/LAMP) environment.
L/W (Linux / Windows)
A pache (Web server)
M ySQL (Database)
P HP
Hope this is enough of a pointer ;)
I am figuring out how to use PHP OpenId
I have cloned the repo to the ~/www directory. There are some examples in the php-open-id/examples directory which I wanted to run.
Specifically, I wanted to render the page php-open-id/examples/consumer/index.php in order to better understand the API. I started a server in the php-open-id/examples directory using
python -m SimpleHTTPServer 8000
and I navigated to localhost://consumer/index.php
But it didn't work. It shows a dialog box to save the file. What is the correct way to render this PHP file?
I have found a solution :
Run the server using
php -S localhost:9000
Mac OS
Just Visit your project folder
open terminal on that folder
and Run php -S localhost:9000
then you can see
PHP 7.3.24-(to be removed in future macOS) Development Server started at Tue Mar 30 11:58:49 2021
Listening on http://localhost:9000
After that you are able to access your application on http://localhost:9000
if your port is not available try to change port
You need to have a php server for serving .php files. The simple python server is not a php server and therefore it is just simply listing the files in the directory for download.
If you are on OSX 10 or above, it comes with apache which has php module present and can be setup to serve php file.
Tutorials can be found here
http://php.net/manual/en/install.macosx.bundled.php and here https://discussions.apple.com/docs/DOC-3083
If you would like to setup a dedicated server instead of using apache, MAMP is a good solution. Google It and see tutorials on how to set it up.
Update November 2022:
Unfortunately, PHP has been removed from MacOS. This is a brief tutorial which explains how to get PHP working in Ventura.
I personally dislike the idea to compensate the lack of PHP with the activities outlined in the tutorial. My solution was to install Docker and to run a proper NGINX+PHP container. I consider it to be cleaner, more flexible and better to maintain rather than faffing about with half-baked on-board stuff. But that's a matter of taste, I guess.
Also, as suggested in one of the answers, using the Python approach is not hassle free in Ventura, since it requires xcode to be installed.
In MacOS 10.x I have also been working with the on-board Python and PHP. Having lost those tools as standard installations is annoying.
I was wondering how to link a SQL database on my PHP code.
I am using a database on my local server that I set up and I have already created a database, I tried writing a PHP script with ++notepad, but when I clicked on the script, it opened the browser and displayed a blank page. What am I doing wrong? I created my databases using phpMyAdmin.
You need to be running a web server locally which supports PHP (like Apache). It it the web server which does the PHP processing. At the same time you will have to run a MySQL (or any other) database engine too, so your PHP code can connect and query it. (I'm assuming you've already installed PHP.)
I would recommend you install XAMPP which includes Apache, PHP, MySQL and a bunch of other stuff. It one of "Apache friends". Once you install XAMPP you would have a folder htdocs in the xampp folder. Create a folder for you project myproject and place your PHP script script.php in there. Now if MySQL and Apache are running following should behave as you expect.
http://127.0.0.1/myproject/script.php
For the tutorial, to begin with you can use W3Schools. Brief and to the point. They have both a PHP tutorial and a SQL tutorial.
This is a very good book to start with:
PHP and MySQL
Web Development
Luke Welling and Laura Thomson
You have to play with php/sql code practically. Only reading cant help!
go for w3shools as mentioned above :)
start with simple code and then go to the complexity. all the best.. :)
There are multiple ways on how to do that.
One of the most modern ways to do that, is to use PDO to connect to the DB with PHP.
To run PHP on your PC(which i assume is your workstation), you need the supporting software for it, for php to run you need the PHP software installed, and likewise if you want to run the server software you need apache, however you can go for a single install package which will install almost everything for you to run your php script, download and install the wamp.
to install wamp which stands for (windows, apache, mysql, PHP) if you are running windows, and lamp for linux or mamp for mac, all of which are free softwares, you can download wamp from the following link. http://www.wampserver.com/en/download.php that is the first step which you need to do.
step 2: once wamp is installed the default directory of installation is C:/wamp (i reccomend do not change the location of the installation), you need to start the wamp server by just opening or double clicking the software which you just installed.
step3: navigate to the default directory where you should be storing your PHP files and that is C:/wamp/www note that you should be keeping all your PHP files here apart from this location if you store it anywhere else it wont simply run at all, and that it should and must have the .php extension.
step4: create or save the php files in this location(c:/wamp/www) i for example will assume you have created a file test.php in the www folder. now to access this file open your web browser and type http://localhost/test.php there you go, you will have the access to your PHP file (Note: PHP files cannot be run by simply double clicking the file, you have to follow this procedure in order to run the PHP files)
step5: open the test.php in any of your text editor like notepad, or i recommend use an IDE (Netbeans is free and worth a try), and write your code in the following format.
<?php
your PHP code should go here.
?>
when i started writing the code i started by following a nice tutorial which i found in zend.com, it has one of the best examples, and moreover the tutorial is meant for the beginners. hope this helps you..
http://devzone.zend.com/tag/PHP101
I want to do a sample program in PHP on Windows XP.
Do I need any special software to get this to work?
I am afraid that I simply open notepad type the PHP program and save it with php extension. Then I open it with the browser as a HTML file. But it does not work.
Please help
Thanks in advance
However you decide to install a webserver and php (or just php and use it in the console like someone mentioned):
Check out the PHP Manual, especially the Getting Started section.
Apache (Very, very easy)
Check out the WampServer getting started presentation.
Download and install WampServer.
And you are ready to go.
Microsoft (Not tested this myself)
Check out PHP on Windows.
Download and install the Microsoft Web Platform Installer.
Let me know how that work out... (never tried it myself, since WampServer is so easy)
You need to have a web server with PHP installed on your PC to make this work.
I highly recommend installing wampserver on your computer. It is a Windows installer that will put PHP, MySQL and Apache in your computer and let you manage all the services and such very easily. If you have problems getting it to work, you can also try out XAMPP, although I've never used it myself.
Some answers containing the hint for using wamp.
You should better use the Zend Server Community Edition.
This is also free and can be downloaded here:
http://www.zend.com/de/community/zend-server-ce
This contains Apache, Mysql, PHP and some Zend related Tools.
Benefit: its much better preconfigured than wamp.
Another easy one to set up (though it takes extra config to support PHP5) is easyPHP
you can simply install PHP, and then run the program and redirect the output
php foo.php > output.html
and then use any browser to open up that html file.
Since you have IIS on the windows cd I would suggest you go to control panel, install/uninstall programs and click on windows components and install IIS. Then install ASP.NET 3.5 from www.asp.net and finally install Phalanger from http://www.php-compiler.net/
That will give you the benefit of both worlds, you can program in ASP.NET using PHP as the language, you can use only PHP if you prefer that or you can mix using ASP.NET/C# on some pages and PHP on other pages within the same application.
I use XAMPP, works out of the box with his installer and is more than enough for a simple developer windows environment.
The simplest way - use www.microsoft.com/web platform installer. get the whole stack to run PHP all from one place.
i would like to share that before starting PHP we have to set environment for that and then we can start working with PHP.
http://code.freefeast.info/php-tutorials/setting-up-the-environment-for-php-php-tutorial/