Install homebrew:
4 thoughts on “Mac OS X: Setting Up Apache, MySQL, PHP and ModRewrite” TommyWillB says: June 3, 2008 at 5:51 pm.
Also from what I've just read, most Macs have PHP and MySQL already installed; all I have to do is just activate the Apache program. Can someone point me to a good link, thread, or something that clearly illustrates how to do that-any helps/clarifications will be greatly appreciated. In this article, we are discussing the “Setup Apache, PHP & MySql on Windows 10”. We are creating this tutorial for knowledge. You can use Xampp or Wamp server, both of the servers provide rich features and flexibilities. Before you can enable PHP on a Mac, you first have to enable Apache. Both PHP and Apache are free open source software programs and both come installed on all Macs. PHP is server-side software, and Apache is the most widely used web server software. Enabling Apache and PHP on a Mac isn't difficult to do. Mac OS X serves as an excellent development environment, even if you are not actually developing Mac OS or iOS applications. It is the darling of many a LAMP (Linux, Apache, MySQL and PHP) developer, who enjoys a slick desktop operating system with good UNIX-like underpinnings but who don’t necessarily want to put up with all the various limitations and complications that running a Linux.
/usr/bin/ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
Open Terminal and run the following Code: sudo apachectl start
Open your browser and access http://localhost. If it says It Works, then you are set otherwise see if your apachectl has started or not.
Let's make a backup of the default Apache configuration. This will help you to cross check later what you changed or in case you want to restore the configuration to default.
Now edit the httpd.conf with vi or any other text editor: vi httpd.conf
Now uncomment the following line (Remove #): LoadModule php5_module libexec/apache2/libphp5.so
Now Restart apache: sudo apachectl restart
To install MySQL: brew install mysql
Install brew services now: brew tap homebrew/services
Now start MySQL: brew services start mysql
Now configure MySQL : mysql_secure_installation
- Validate Password Plugin
- Remove anonymous users
- Disallow root login remotely
- Remove test database and access to it
- Reload privilege tables now - Choose yes
After finishing this up, test MySQL: mysql -uroot -p
.
It will ask you write the password you set for mysql before. Enter password and then something like this appear:
Now we need to ensure PHP and MySQL:
All your sites would have URLs like http://locahost/some-site pointing to /Library/WebServer/Documents/some-site.
Note on Permissions
You may recieve 403 forbidden when you visit your local site. The Apache user(_www
) needs to have access to read, and sometimes write, your web directory.
You can either change permissions like this: chmod 755 directory/
or you can change the ownership of the directory to the apache user and group: chown -R _www:_www directory
This is optional. You can use MySQL through command line but this is a good way to administer MySQL. Download phpmyadmin from site.
Done! Done! Done!
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:Edit the Php init file: php.ini
Edit the following file (via nano, or sudo nano). Search for timezone.Reset from the initial value (Europe/Berlin):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):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: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: