How to Set Up PHP, HTML & MySQL Development on Mac OS X

How to Set Up PHP, HTML & MySQL Development on Mac OS X

The following are instructions for setting up a development environment on a Mac that can be used for HTML, PHP and MySQL.

1. Install NetBeans
NetBeans is the IDE used for programming.
Install NetBeans for HTML5 & PHP from this link:

https://netbeans.org/downloads/

2. Install MySQL & MySQL Workbench
MYSQL is used for databases.
Follow the tutorial at this link:

http://www.macminivault.com/mysql-mavericks/

Install Workbench from this link:

http://www.mysql.com/downloads/

3. Activate the built-in Apache Server on the Mac
Apache will provide a local server we can use to test websites.
Follow the tutorial at this link:

http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/

Test that Apache is properly installed by navigating to “localhost” in Safari
The root of the Apache Web Server folder is: /Library/WebServer/Documents
Change the permissions on the above mentioned Documents folder by right clicking on it, then click Get Info, then in the opened dialog box: click on the icon of a lock and input password, then under the Sharing & Permissions tab at the bottom, provide Read & Write Privileges to everyone who appears in the box.

4. Enable PHP in the built-in Apache
PHP is needed to test PHP functionality in the web pages
Follow the tutorial at this link:

http://php.net/manual/en/install.macosx.bundled.php

Restart Apache server in terminal using:
sudo apachectl restart
Test that the PHP server is functional by:
1. Navigate to /Library/WebServer/Documents
2. Copy the attached “index.php” file to this folder
3. In your web browser, navigate to: localhost/index.php
4. If you see a phpInfo page, then PHP is functional

5. Installing Xdebug
XDebug is needed to debug issues with code
XDebug is already installed in the computer, you simply need to enable it. To do that:
In Finder, in the top menu bar, click on the menu header: “Go”. From the drop down list, select: “Go to Folder”
In the dialog box that appears, enter: “/private/etc/“ (without quotes)
In that folder, open php.ini with Text Edit
Copy and paste the following lines of code to the end of the file

[xdebug]
zend_extension=”/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so”
xdebug.degault_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
;xdebug.remote_log=”/var/log/xdebug.log”
xdebug.remote_autostart=1

Now, test if Xdebug is working:
Restart Apache server using terminal:
sudo apachectl restart
In Safari, navigate to “localhost/index.php”, (as done in Step 4)
Scroll through the page and search for “xdebug”
If you find it, that is a good sign. Next, we are going to verify that Xdebug was installed properly.
Using Command+A, select everything on the page (all the text and images); (see “Select All Screenshot” for a visual)
Copy everything by using Command+C
Navigate to: http://xdebug.org/wizard.php
Click inside the large white box in the page, and paste using Command+V; (see “Paste Screenshot” for a visual)
Click the “Analyse my phpinfo() output” button
If XDebug installed provides a version number, it works!

6. Running a test page on NetBeans
Now, test if Xdebug is working with NetBeans:
Open NetBeans
Go to: NetBeans>Preferences in the top menu bar
Check that the Web Browser:
Under the PHP Tab, then the General tab:
Php 5 Interpreter should be: /usr/bin/php
Click okay. Preferences are complete. Now create a new project:
Go to File>New Project
Create a PHP Application Project
Click Next
Project Name: test
Sources Folder: /Library/Webserver/Documents/test
Click Next
Run As: Local Web Site (running on local web server)
Click Next and Finish
Paste the following code into the index.php page:

 

In the code, next to the line “echo phpinfo(); there is a number 3. Click on that number to set a break point for debugging. This will replace the number 3 with a red square.
Save the project
Right click on the project in the “Project” Section on the left and click “Debug”
If you see content under the Variables, Call Stack and Breakpoints tab, then it worked.
Your development environment is now complete.

7. Good to know
httpd.conf: /private/etc/apache2/httpd.conf
php.ini: /private/etc
xdebug.os: /usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
Root dir of Apache: /Library/WebServer/Documents
Apache Server Terminal Commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl restart

5 Comments

  1. This paragraph will help the internet users for building up new web site or even a blog from start to end.|

  2. Last one to utiilze this is a rotten egg!

  3. Thanks for sharing your thoughts. I truly appreciate your efforts and I am waiting for your further write ups thank you once again.|

  4. Hi there very nice blog!! Man .. Excellent .. Wonderful .. I’ll bookmark your blog and take the feeds additionally? I’m satisfied to seek out numerous helpful information here in the submit, we need develop more strategies in this regard, thanks for sharing. . . . . .|

  5. Hi everyone, it’s my first visit at this web page, and piece of writing is actually fruitful in favor of me, keep up posting such content.|