Mysql Php And Apache For Mac



Install homebrew:

  1. Linux Apache Mysql Php
  2. Mysql Php And Apache For Mac Download
  3. Mysql Php And Apache For Mac Catalina

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 MacNetBeansProjects 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:

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):
/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:
You're probably doneIf you're running the Apache/Php/MySQL services through XAMPP, you probably can skip the rest of the document

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 is

Create 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:
In any case, always avoid any terminal '/' in the directory names.Restart Apache and check that '/default' works:Activate this URL:You should see the contents of the NetBeansProjects directory listed.Mysql Php And Apache For MacMysql Php And Apache For Mac

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

Linux Apache Mysql Php

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

Mysql Php And Apache For Mac Download

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

Mysql Php And Apache For Mac Catalina

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