Skip to content

Instantly share code, notes, and snippets.

@knzm
Created August 25, 2012 18:19
Show Gist options
  • Select an option

  • Save knzm/3468783 to your computer and use it in GitHub Desktop.

Select an option

Save knzm/3468783 to your computer and use it in GitHub Desktop.
Run PHP scripts without Apache on Mac

1. Install php-cgi

  • Download PHP542.dmg and open it.
  • Copy PHP5 folder into /Applications.

2. Install WPHP

$ python virtualenv.py --no-site-packages .
$ . bin/activate
$ easy_install wphp

3. Run script

$ python main.py
import os
from wphp import PHPApp
from wsgiref.simple_server import make_server
here = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.join(here, "www")
php_script = "/Applications/PHP5/bin/php-cgi"
php_options = {
'include_path': os.path.expanduser("~/pear/share/pear"),
'magic_quote_gpc': 'Off',
'date.timezone': 'Asia/Tokyo',
'error_reporting': '"E_ALL&~E_NOTICE|E_STRICT"',
}
my_php_app = PHPApp(
base_dir,
php_script=php_script,
php_options=php_options)
httpd = make_server('', 8000, my_php_app)
httpd.serve_forever()
@knzm
Copy link
Author

knzm commented Aug 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment