Server Php For Mac
XAMPP is a free distribution package that makes it easy to install Apache Web Server, PHP, PEAR, and MySQL. Before installing XAMPP, you should turn off any other web servers and instances of MySQL you have running on your Mac.
- Apple Os X Server
- Apple Server Software
- Server Php For Mac Shortcut
- Php Server Mac Address
- Php Web Server
- Best Php Server For Mac
XAMPP is a free distribution package that makes it easy to install Apache Web Server, PHP, PEAR, and MySQL. Before installing XAMPP, you should turn off any other web servers and instances of MySQL you have running on your Mac.
Installing XAMPP on a Mac
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.
I have been writing blogs for a long time now and playing around with Apache and PHP every once in a while to change my Web Host server settings or to make some changes in my UI layouts. So finally I have decided to learn PHP and I use Mac for my personal usage, so the first step was to install Apache, PHP and MySql on my Mac OS X. When starting php -S on a mac (in my case macOS Sierra) to host a local server, I had trouble with connecting from legacy Java. As it turned out, if you started the php server with 'php -S localhost:80' the server will be started with ipv6 support only! To access it via ipv4, you need to change the start up command like so: 'php -S 127.0.0.1:80'. This is the best web server software. I've abandoned xampp. Laragon is very easy to use (switching PHP versions etc), light weight and the most important part is, I love the auto create virtual hosts feature and cmder. Thanks for providing this superb tool!
- Download XAMPP for Mac OSX - Be sure to select the proper version of PHP. For Webucator classes, any version after 5 will be fine.
- Open the downloaded file (the DMG-Image).
- Drag and drop the XAMPP folder into your Applications folder.
Starting XAMPP on OSX
To start XAMPP simply open XAMPP Control (by going to /Applications/XAMPP/manager-osx.app in Finder) and start Apache and MySQL on the Manage Servers tab.
If MySQL Does Not Start
If your MySQL server isn't starting, you may need to set the permissions for it using Terminal with this command:
Testing your OSX XAMPP Installation
In your web browser, go to http://localhost. You should see the start page of XAMPP:
Class File Permissions
- Cmd+click on the ApplicationsXAMPPxamppfileshtdocs folder and select 'Get Info'.
- If the lock symbol at the bottom indicates that this information is locked, click the lock icon to unlock, and enter your user credentials.
- Once the settings are unlocked, choose 'everyone' under 'Sharing & Permissions' and change the option to 'Read & Write'.
Class Files
- Download the class files.
- After downloading the class files, navigate to ApplicationsXAMPPxamppfileshtdocs and create a new folder named Webucator and extract your class files in that folder.
Setting the MySQL Password on Macs
- The PHP files use 'pwdpwd' for the MySQL root password, while the default password is NO password.
- Change the password to pwdpwd by opening Terminal (Applications > Utilities > Terminal) and enter:
You will be asked to enter your Mac password; enter it and press enter. Then you will be asked if you want to set a password for your XAMPP pages, then for MySQL, and then for MySQL/phpMyAdmin user...to all of these just type 'n' for no and press enter.
Then it will say:
- Enter 'y' for 'yes, let me set a password for the root user' and press Enter
- Enter the password pwdpwd. You will be asked to enter it again for confirmation.
- Quit Terminal (Cmd+Q) and restart Apache and MySQL using the XAMPP Control Panel.
Testing phpMyAdmin
- Go to http://localhost
- Click on phpMyAdmin under Tools
- Enter 'root' for username
- Enter 'pwdpwd' for password
Apple Os X Server
You should be able to get in.
Installing Northwind Database using XAMPP
NOTE: you should download the class files below before following these instructions, as it contains the Northwinds Database file(s).
- To install the Northwind database used in class, click on the 'phpMyAdmin' link on the left navigation bar of the XAMPP home page. That should take you to http://localhost/phpmyadmin.
- If it asks you to login, the username is root and the password is blank (unless you have already changed it to something else, like pwdpwd).
- On that page, click on the Import link under the Localhost heading.
- Browse to the Northwind-MySQL.sql file in your class files.
- Click the Go button on the bottom right of the page.
- You should get a Success message and Northwind should be added to the Database dropdown menu on the upper left of the page.
Recommended Editor
- Visual Studio Code ( Download, Install, and Set up)
- While you may use a different editor or IDE, Visual Studio Code is an excellent IDE to learn to code on. It provides a nice balance of power and simplicity and it is available on Windows and Mac.
Designate your testing server in Dreamweaver
NOTE: The following only applies if you are using Dreamweaver. If you are not, please ignore this section.
- Go to Site > New Site.
- In the Site Setup dialog, fill in the Site Name (e.g., PHP) and browse to the Local Site Folder (e.g., ApplicationsXAMPPxamppfileshtdocs).
- Choose the Servers tab.
- At the bottom of the box on the right, click +.
- On the Basic tab, provide a Server Name, set Connect using to Local/Network, ensure the Server Folder matches the local site folder you specified in step 2, and set the Web URL to http://localhost/Webucator/ClassFiles/.
- Click the Advanced button.
- In the Server Model field, select PHP MySQL.
- Click Save. The server should appear in the table on the Servers tab.
- Make sure that both the Remote and Testing checkboxes are checked.
- Click Save.
Testing PHP Files
All your class files should be located in ApplicationsXAMPPxamppfileshtdocsWebucatorClassFiles
2 Methods for Testing Files in Browser
To test any of the class files in your browser, say ApplicationsXAMPPxamppfileshtdocsWebucatorClassFilesPHPBasicsDemosHelloWorld.php, you can use 1 of 2 methods:
Method 1:
- Go to http://localhost/Webucator/ClassFiles/PHPBasics/Demos/HelloWorld.php in your web browser.
- Follow the same pattern to view all other class files; basically the ApplicationsXAMPPxamppfileshtdocs gets changed to http://localhost/
Method 2:
- Go to http://localhost/Webucator/ClassFiles/ in your web browser.
- Bookmark that page in your browser for easy access to it from now on.
- From there, you can see all the lesson folders and drill down to any class file for testing/viewing
And that's it
Happy Mac XAMPPing!
Built-in web server
WarningThis 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.
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.
Version | Description |
---|---|
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 | |
5.4.11 | .ogg, .ogv, and .webm |
5.4.4 | .htm and .svg |
Version | Description |
---|---|
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:
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
Apple Server Software
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 */
?>
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:
Server Php For Mac Shortcut
<?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;
}
?>
Php Server Mac Address
Example #6 Accessing the CLI Web Server From Remote Machines
You can make the web server accessible on port 8000 to any interface with:
Php Web Server
WarningBest Php Server For Mac
The built-in Web Server should not be used on a public network.