Start a PHP server on Mac OS X - php

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.

Related

which server to install for phpEclipse and how to do it?

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 ;)

Git HTML 5 demo on OSX

I am very new to Web development and wanted to run one of the Github project (https://github.com/remy/html5demos) on my Mac.
I have downloaded the project on my Mac and puzzled how to run it. Need help from all talented people across Stackoverflow.
The demo using php. Unfortunately, the apache installed on OSX (assuming you're on Snow Leopard) has not have php enabled by default and you need some admin-editing to enable it.
So, first move the unpacked folder remy_something into /Library/WebServer/Documents and rename it to easy name, for example "remy". (The final path /Library/WebServer/Documents/remy)
enable Web sharing in System preferences
point your browser to http://localhost/remy/index.php
if you get an rendered page - you're done, and can start playing...
if you get an error - something is terrible ;(
if you get a page where is the 1st line <?php - you're on good way - you need enable php.
For enabling php in OSX's apache, you should read for example: http://www.perfectline.ee/blog/how-to-setup-apache-and-php-on-mac-os-x-snow-leopard or any other guide you can find.
after enabling php and restarting apache (disable/enable Web sharing), you can check again the page...

"Compiling php" as in making it portable

I'm not intrested in compiling for performance but in being able to "compile" a php script in order to carry it on a usb stick or portable hard drive.
I think that there may be two way:
Portable Apache
Portable command line php
I undersand that some package such as xampp and so on exists, as well as using the php bin files but I was wondering if something more user friendly exists, I mean something that I can just double click, open a browser and use.
PHP is only interpreted. XAMPP merely sets up a mock environment with an apache server, a database, and the PHP engine. Unfortunately, XAMPP is about as fast and portable you're going to get in terms of being able to fire up a PHP app.
If you figure out a way to do it the way you're looking to - message me - I'll pay for it...
searching the web gives me this
PCC
and this
PHC
Two native PHP compiler i found.
PHP 5.4+ has a built-in webserver... I was able to simple copy my php executable into a random folder and...
# ~/someDir/php -S localhost:7676 -t ~/docRoot ENTER
PHP 5.4.0RC3 Development Server started at Tue Jan 3 15:57:33 2012
Listening on localhost:7676
Document root is /Users/localadmin/docRoot
Press Ctrl-C to quit.`
Browse to http://localhost:7676 and you're good to go.
If you want even more portability, you can delve into the world of recompiling PHP with a build command such as ./configure --enable-static --disable-shared --disable-all

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

What's the easiest way to test PHP in Windows XP Professional?

I want to test some PHP on my local machine running Windows XP Professional. I'm familiar with coding PHP for upload, but not with running a web server.
What is the easiest way to set up a test environment? Step-by-step instructions would be great if you can give them.
(I see WAMP recommended in this thread - thoughts?)
Update - a year later
A little self-promotion: after using XAMPP for a long time, I began to want things it didn't include. (Support for PDO was a big one - every time I tried to enable pdo and mysqli simultaneously, something crashed.) I eventually worked through the process of installing Apache, PHP, MySQL, and PHPMyAdmin individually, and documented the process with screen shots on my blog.
Some of the configuration that I was able to do this way could have been done in XAMPP, but it was only because I had to set things up myself that I discovered new things (like being able to serve files out of c:\whatever instead of c:\program files\apache\htdocs).
On the whole, I'm happier with having installed these items separately. But XAMPP was a good (and easy) package to start with, and served me well while I used it.
(source: apachefriends.org)
Xampp is the simplest. You can setup everything in a Step by Step and if you require further configuration (Virtual Server, extension) you have the normal php.ini and other file in the directory that you can edit yourself.
Here is the Step By Step installation for Windows.
XAMPP from ApacheFriends is pretty simple to set up and use.
note the site appears to be down as at 15:02 UTC on 3rd Dec 2008
note again and it is back!
Instead of WAMP, I recommend XAMPP, for Cross Platform (X), Apache, MySQL, PHP, and Perl, all in one package. It is very simple to setup and use, and like WAMP puts an icon in the system tray to manage it all.
You can get it here: www.apachefriends.org/en/xampp-windows.html. This site also includes comprehensive instructions to get up and running quickly.
There is even a portable version available at http://portableapps.com/apps/development/xampp.

Categories