Web Server For Mac



A protip by mvmaasakkers about mac os x and webserver. To start a simple webserver on Mac OS X simply start terminal, go to the directory you want to start the webserver from (which will be the document root) and use the following command. Install and Configure MAMP (Mac, Apache, MySQL, PHP) This is an open-source program that gives.

  1. Best Web Server For Mac
  2. Free Web Server For Mac
  3. Mac Os Server Setup
  4. Php Web Server For Mac

Built-in web server

Warning

This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

As of PHP 5.4.0, the CLISAPI provides a built-in web server.

The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.

URI requests are served from the current working directory where PHP was started, unless the -t option is used to specify an explicit document root. If a URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither file exists, the lookup for index.php and index.html will be continued in the parent directory and so on until one is found or the document root has been reached. If an index.php or index.html is found, it is returned and $_SERVER['PATH_INFO'] is set to the trailing part of the URI. Otherwise a 404 response code is returned.

If a PHP file is given on the command line when the web server is started it is treated as a 'router' script. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.

Best Web Server For Mac

Apache web server for mac

Standard MIME types are returned for files with extensions: .3gp, .apk, .avi, .bmp, .css, .csv, .doc, .docx, .flac, .gif, .gz, .gzip, .htm, .html, .ics, .jpe, .jpeg, .jpg, .js, .kml, .kmz, .m4a, .mov, .mp3, .mp4, .mpeg, .mpg, .odp, .ods, .odt, .oga, .ogg, .ogv, .pdf, .pdf, .png, .pps, .pptx, .qt, .svg, .swf, .tar, .text, .tif, .txt, .wav, .webm, .wmv, .xls, .xlsx, .xml, .xsl, .xsd, and .zip.

Changelog: Supported MIME Types (file extensions)
VersionDescription
5.5.12 .xml, .xsl, and .xsd
5.5.7 .3gp, .apk, .avi, .bmp, .csv, .doc, .docx, .flac, .gz, .gzip, .ics, .kml, .kmz, .m4a, .mp3, .mp4, .mpg, .mpeg, .mov, .odp, .ods, .odt, .oga, .pdf, .pptx, .pps, .qt, .swf, .tar, .text, .tif, .wav, .wmv, .xls, .xlsx, and .zip
5.5.5 .pdf
5.4.11 .ogg, .ogv, and .webm
5.4.4 .htm and .svg
Server
Changelog
VersionDescription
7.4.0 You can configure the built-in webserver to fork multiple workers in order to test code that requires multiple concurrent requests to the built-in webserver. Set the PHP_CLI_SERVER_WORKERS environment variable to the number of desired workers before starting the server. This is not supported on Windows.
Warning

This experimental feature is not intended for production usage. Generally, the built-in Web Server is not intended for production usage.

Example #1 Starting the web server

The terminal will show:

After URI requests for http://localhost:8000/ and http://localhost:8000/myscript.html the terminal will show something similar to:

Note that prior to PHP 7.4.0, symlinked statical resources have not been accessible on Windows, unless the router script would handle these.

Example #2 Starting with a specific document root directory

The terminal will show:

Software

Example #3 Using a Router Script

In this example, requests for images will display them, but requests for HTML files will display 'Welcome to PHP':

<?php
// router.php
if (preg_match('/.(?:png|jpg|jpeg|gif)$/', $_SERVER['REQUEST_URI'])) {
return
false; // serve the requested resource as-is.
} else {
echo
'<p>Welcome to PHP</p>';
}
?>

Example #4 Checking for CLI Web Server Use

To reuse a framework router script during development with the CLI web server and later also with a production web server:

<?php
// router.php
if (php_sapi_name() 'cli-server') {
/* route static assets and return false */
}
/* go on with normal index.php operations */
?>
Server

Example #5 Handling Unsupported File Types

If you need to serve a static resource whose MIME type is not handled by the CLI web server, use:

<?php
// router.php
$path = pathinfo($_SERVER['SCRIPT_FILENAME']);
if (
$path['extension'] 'el') {
header('Content-Type: text/x-script.elisp');
readfile($_SERVER['SCRIPT_FILENAME']);
}
else {
return
FALSE;
}
?>

Example #6 Accessing the CLI Web Server From Remote Machines

You can make the web server accessible on port 8000 to any interface with:

WarningPhp web server for mac

The built-in Web Server should not be used on a public network.

May 4, 2013 11:51 PM

Great guide, thanks John.


Just a note, in case anyone has the same issue. At first I couldn't get this to work. I tried logging out and back in (still no joy), then restarting the mac (still no joy).


Free Web Server For Mac

Try doing both of those first. However, if, like me, you still can't get the local host site to load, try the following: You should find a file at /Library/WebServer/Documents/index.html.en . This contains the text 'It works!' referred to in the post. What I did was duplicate that file in the same folder and changed the duplicate's name to 'index.html', leaving the original in situ.


Both local and user sites then loaded. After which, I was able to delete the duplicated file and everything now works without issue. Just to be clear, leave the original file index.html.en where it is, untouched and unharmed throughout this step.


Mac Os Server Setup

Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps.

Php Web Server For Mac

May 4, 2013 11:51 PM