- Apache Php Mysql For Mac Versions
- Install Apache Php Mysql Mac
- Apache Mysql Php Windows 10
- Apache Mysql Php For Mac
First thing that we need to do is to download the MySQL.dmg file from their website and install it on Mac. Look for three file install. Mysql5.6.xxx.pkg (MySQL application) MySQLstartupitem.pkg (start MySQL when Mac boots) MySQLPrefPane (system preference control over Mac) To make PHP talk to MySQL, edit /etc/php.ini and set the following values. Here are the steps to install Apache, MySQL and PHP on a Mac OS X. Download the installation image from MySQL website here. Then double-click to mount and open the disk image. Install MySQL Server by double clicking the package “mysql-5.1.pkg” and follow the menu, accepting the default values, unless you want to change something.
Specify your computer login – PLEASE DO THIS!!
The standard NetBeansProjects directory is in your home directory and so it is important to identify then name of your home directorywhich is dictated by your computer login.If you don't know what your login is, or that you even have such a thing,look for your login as a directory name in the folder Key your computer login and click the Set Change button:Once you've done this, the value keyed in will be used throughout the documentto personalize it for your computer.XAMPP Apache/Php with XAMPP MariaDB
This is the easiest combination to use. We'll assume you'vealready done the XAMPP Installation.Start up the XAMPP Control Panel as administrator and thenstart up both the MySQL and Apache services.The MAC Native Apache may already be running on your system. What might happenis the XAMPP Apache service stops by itself when you try to start it. The remedyis to disable MAC OS Apache (at least temporarily) by:To be more sure that you're using the right one:Verify that the following URL is working:On MAC this will either give the default 'It Works' message, or else redirect to the so-called 'dashboard' site.Establish the '/default' URL
I want to map a dedicated URL to the directory which holdsyour Php projects. For definiteness, I will assume thatthis is yourNetBeansProjects folder. Also, fordefiniteness, I am going to use this as the dedicated URL:I will also assume the standard NetBeansProjects installation directory:Edit the following file (via nano). You may have to edit as administrator:Scroll to the end and make this addition:/Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf (appended)
Afterwards, restart Apache from the XAMPP Control Panel.Activate the target URL to verify that it gives a listing of your NetBeansProjects directory:You should get the empty directory listing with header:Apache Php Mysql For Mac Versions
Edit the Php init file: php.ini
Edit the following file (via nano, or sudo nano). Search for timezone![Apache Php Mysql For Mac Apache Php Mysql For Mac](/uploads/1/0/0/9/100923582/898872159.jpg)
/Applications/XAMPP/etc/php.ini
Afterwards, restart Apache.Php Command-line program
All the XAMPP command line programs are in the directory:The Php command-line program isIf you want to make this usable simply as 'php',then add the folder /Applications/XAMPP/bin into the PATH.You have probably already done so for the mysql executable.Confirm by checking: If necessary, edit ~/.profile adding an expression like this (no blanks around the '='): Open a new terminal and check again.In any case we'll refer to the executable simply as 'php'. Confirm its usage by running this in a command shell tosee the version of Php:Php/MySQL Test Programs
Php Information Test Program
Go into the NetBeansProjects directory and create this file (via nano):phpinfo.php
With the file in place, refresh the default URLYou should see the file appear in the listing where you can activate it.Php PDO/MySQL test program
If necessary, prepare the standard MySQL setup with the test database accessedby the guest user with empty password. Test it first:Create and run the following program in the web server:mysql-pdo-test.php
Refresh the default URL to pick up the added file and activatethis to see final SUCCESS message.You should also be able to run it from the shell, seeing theHTML output. Open a shell and navigate to the NetBeansProjectsfolder and run:XAMPP Apache/Php with Native MySQL
This assumes you have installed XAMPP as inXAMPP on MACand have installed MySQL as in MySQL on MAC.Start the XAMPP control panel, but only start up Apache.Simply do all the steps in the previous 2 sections. Everything should work.Native Apache/Php with Native MySQL
This assumes you have installed MySQL as in MySQL on MAC.Here we are not going to use XAMPP at all.Apache and Php are already installed on the MAC. There is usually some gimmickyou have to go through to have Apache run as a service, but will at leastserve temporarily to start it up as follows:Verify that Apache is running bytesting this URL:The apachectl service
On the MAC you will need to use the executable (as root)You should be able to use this just as sudo apachectlwith these commands:Project Directory
On the MAC, the standard NetBeans directory is this:Certain directories on the MAC are unsuitable for web programming. For example, the /Users/LOGIN/Documents directory permits only owner access, which means the Apache cannot 'pass through' to read web scripts.Configuration
The Apache-related files you will need to edit are all found inThe main configuration file isCreate the '/default' URL
Check the Apache version:You'll see either 2.2.x or 2.4.x. Edit the main Apache configuration file:scroll down to the end of the file. Choose one or the other- If your Apache version is 2.4, add this code:
- If your Apache version is 2.2, add this code:
Install Apache Php Mysql Mac
in the directory names.Restart Apache and check that '/default' works:Activate this URL:You should see the contents of the NetBeansProjects directory listed.The Php configuration file: php.ini
The file /etc/php.ini is Php's main configuration file. On theMAC this serves as the configuration file for both the Apache and thecommand-line versions.If it does not exist, Php uses certain default settings.For our purposes we need to override these default settings.You can see if it exists by running this command from a shell:If it doesn't exist, MAC will provide a suitable starter file withall the default settings:You have to copy this into the official init file:You need to modify the Php init file (via sudo-nano unless you prefer something else):Search for timezone:/etc/php.ini
Also, error display needs to be enabled in adevelopment environment. Search for display_errors.If it is off, turn it on:/etc/php.ini
Afterwards, restart Apache as before.Verify that Apache/Php is working
The Native Php version is MAC OS X (up to 10.12) is version 5,which is perfectly fine.Double-check that the Php module is being loaded.Search for 'php', looking for the line:If it is commented out with a leading '#' character, remove that character and restart Apache:Go into the NetBeansProjects directory and create this file:You cannot create 'just a file' via NetBeans. The simplest way to create it maybe using nano (as normal user) in a terminal shell:With this in place, refresh the default URL:You should see the contents of the phpinfo.php in the listing.Activate it to see the Apache/Php information listed.Test MySQL access
The test program to run is mysql-pdo-test.php described in the Test Programs section above.MySQL network vs file socket access
Themysql-pdo-test.php test program illustrates two allegedly equivalentways to connect to the database via either of the URLs:In UNIX-like systems (MAC and Linux), the connection via '127.0.0.1' willattempt to connect to MySQL via the network socket on port 3306, which is guaranteedto succeed no matter which version of SQL is running. In contrast, the connection via 'localhost' will attempt to connect to MySQLby a file socket which varies based on the version of Php being used.In particular, if we want to use the 'localhost' version, we must prepare Phpto connect to the dedicated MySQL socket. You would have to edit /etc/php.iniand set this value:/etc/php.ini
Update 22 Oct 2019: Instructions updated for OSX 10.15 Catalina
After suffering some pretty bad issues with MAMP, I decided to set everything up with homebrew instead. The result was surprisingly a much faster and (in my opinion) easier to configure setup.
As a tl;dr, we’ll be setting up Homebrew MySQL and PHP and using OSX’s built in Apache.
In this tutorial I’m using the subl command which will open a file for editing in Sublime Text. If you don’t use Sublime Text, replace subl with nano or vi or any other app you use to edit text/config files.
Homebrew Setup
Homebrew is a package manager for OSX. It makes installation of a wide variety of useful apps super easy.
Installation instructions are on thehomebrew homepage but you can also just run the following:
MySQL
I lied! We’re installing MariaDB instead! At the time of writing MySQL version 8.0.11 has just changed its default authentication method to caching_sha2_password which isn’t supported in PHP. It’s a huge hassle so we’ll just use the drop-in replacement MariaDB instead.
Install and configure MariaDB.
Add the following to the end of the file to add support for large imports:
Make MySQL start when you log in:
The default installation comes with a passwordless root user. So secure it with:
SSL
Like all developers I like working on a custom subdomain – in this case localhost.com. We need to create a self-signed wildcard SSL certificate and get Chrome accepting it.
Create a folder /Users/your_username/Sites/certs and inside it run the following:
This should have created two files – server.crt and server.key which will be used in the apache config below to get HTTPS up and running.
But first, because this certificate is self-signed, it’ll result in a This site’s security certificate is not trusted! error in Chrome. That can be fixed through adding the cert to OSX’s keychain app.
- open /Applications/Utilities/Keychain Access.app (In OSX 10.15 this was only visible in Finder and not Terminal for some reason)
- Under Keychains at the top left click System
- Click File – Import Items and select your server.crt file
- Now in the list find your newly added cert, double click it, expand the Trust section and set everything to Always Trust
- These changes will only take effect after a browser restart.
Apache and PHP
OSX 10.15 Catalina comes (at the time of writing) with Apache 2.4.41.
To configure apache (with SSL):
gt;
SetHandler application/x-httpd-php
</FilesMatch>
SetHandler application/x-httpd-php
</FilesMatch>
# As with content, we want to load all site definitions from a Sites folder in our
# home directory. At the bottom replace the following:
# Include /private/etc/apache2/other/*.conf
IncludeOptional /Users/your_username/Sites/*.conf
# home directory. At the bottom replace the following:
# Include /private/etc/apache2/other/*.conf
IncludeOptional /Users/your_username/Sites/*.conf
# The error and custom logs too
CustomLog “/Users/your_username/Sites/logs/apache2/access_log” common
ErrorLog “/Users/your_username/Sites/logs/apache2/error_log”
CustomLog “/Users/your_username/Sites/logs/apache2/access_log” common
ErrorLog “/Users/your_username/Sites/logs/apache2/error_log”
# Uncomment to load the SSL config
Include /private/etc/apache2/extra/httpd-ssl.conf
Now configure the default SSL options:
Include /private/etc/apache2/extra/httpd-ssl.conf
Now configure the default SSL options:
Since this is a development machine, you’ll probably also want to enable the ever popular xdebug which luckily for us comes pre-compiled with OSX. What OSX doesn’t come with, however, is a default php.ini though it does have a sample file. We can use that:
Then simply add extension=xdebug.so below all the extension= lines in your new /etc/php.ini file.
Apache Mysql Php Windows 10
VirtualHosts
Apache Mysql Php For Mac
I like to split virtualhosts up into one for each site and store them all in /Users/your_username/Sites/ folder.
Create a file /Users/your_username/Sites/mysite.localhost.com.conf and add the following:
Finally, restart apache and you should be good to go!
Resources
- Much of the content of this article came from David Marcus’s really great post Set up localhost on macOS High Sierra (Apache, MySQL, and PHP 7) with SSL/HTTPS.
- To get SSL certs working correctly in the browser I followed the instructions on Jed Schmidt’s gist How to set up stress-free SSL on an OS X development machine.
- Because I’m positive I’ve missed or incorrectly written at least some of this article I’ve uploaded copies of all relevant files. httpd.confhttpd-ssl.confmysite.localhost.com.conf