Sunday, December 18, 2011

Getting Started with NetBeans IDE

Coming from ASP.NET to PHP, a good IDE is very important to me. After doing some research, I decided to start out with NetBeans as the IDE for my PHP development. NetBeans is a free IDE. You can download it from netbeans.org.  Just click the "Download Free" button on the home page and make sure you select the version for PHP development on the next page.  Once you have installed NetBeans on you system, you will have to configure PHP to use NetBeans as the debugger so that you can step through and debug your PHP web applications using NetBeans. 

Here are the steps to setup NetBeans as your debugger:

  1. Open the php.ini file in a text editor. This file is located in C:\xampp\php\ directory.
  2. Search for the line that contains "php_xdebug.dll"
  3. Remove the semicolon from the beginning of this line. Once you're done, it should look like this: zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
  4. Next, search for the line that contains "xdebug.remote_enable = 0"
  5. Remove the semicolon from the beginning of this line and change the 0 to 1. When you're done it should look like this: xdebug.remote_enable = 1
  6. Save your changes.
  7. Start and stop apache.
You have now successfully configured NetBeans as your php debugger.

How to configure phpMyAdmin to address Security Issues

This post is based on the instructions found in Murach's PHP and MySQL book, which I am using as a guide in my PHP Journey and I recommend that you do the same. 

The default location of the phpMyAdmin config file is: C:\xampp\phpmyadmin\config.inc.php

  1. Open the config.inc.php file in a text editor.
  2. Search for "$cfg['blowfish_secret'] = 'xampp'".  Replace 'xampp' with a random string of up to 46 characters.  This will be the encryption key.
  3. Search for "$cfg['Servers'][$i]['auth_type']".  Change the value from 'config'  to 'cookie'.
  4. Set the 'user' and 'password' options to empty strings. When you are done, it should look like this:

    $cfg['Servers'][$i]['auth_type']            = 'cookie';
    $cfg['Servers'][$i]['user']                 = '';
    $cfg['Servers'][$i]['password']             = '';
  5. Save your changes.

Now lets check to make sure the changes were made correctly:

  1. Open the XAMPP control panel and start Apache and MySQL.
  2. Click the "Admin" button next to MySQL to open phpMyAdmin.
  3. Log in by specifying "root" as the user.  Leave the password blank, because by default the root user doesn't have a password.
  4. Once you have logged in, you should set a password for the root user.  To do this, click "Change password" Under "Actions". And enter a password. You may want to save this password in a password protected file so that you can retrieve it later if you forget what you set it to.

Now you have successfully configured phpMyAdmin.

Hello World PHP

Now that you have installed XAMPP on your windows 7 pc and you have set Apache to run as a service to work around an issue with running Apache on windows 7, you're now ready to write the standard Hello World application in PHP!  To do this, you will need to create the PHP file in your htdocs directory. This directory is in the xampp directory.  If you installed XAMPP according to the instructions for windows 7, it should be C:\xampp\htdocs. You can think of this as the inetpub\wwwroot directory in ASP.NET. This is where all of your web site files will go when you're developing locally.  Now create a new folder called "helloworld" inside the htdocs directory. Once you have created this folder, create a new file using notepad++ or any editor of your choice.  Enter the following text into this file:

<?php
    echo 'hello world!';
?>

Once you have entered this text, save the file to your C:\xampp\htdocs\helloworld directory that you created as "index.php".   Then start apache, if it isn't already started.  Next, open up your browser and navigate to http://localhost/helloworld.  You should then see a web page with the "hello world!" text displayed.  Congratulations!  You have just created your first PHP page.

Saturday, December 17, 2011

Apache won't run after installing XAMPP on Windows 7

So you installed XAMPP on your windows 7 pc and Apache won't run. Well you're not alone.  To resolve the issue, simply click the "Svc" checkbox next to Apache in the XAMPP Control Panel Application (see below). After you check it, click "Yes" if Windows asks if you want to allow the program to make changes to your computer. Then restart and Apache should be started.  You will then be able to start and stop the service. 


The reason you have to do this is because Windows 7 has a service called http.sys which starts automatically and uses port 80. Running Apache as an automatic service causes apache to start before the http.sys service. This allows apache to get port 80 before http.sys starts.  I found the solution here.

Getting Started

I'm currently an ASP.NET developer in my day job, but I decided to spend some of my spare time learning PHP.  Some of my motivations for doing this are that the PHP development stack is free and the hosting options are much cheaper.  Since I'd love to someday run my own web development business this is appealing to me.  There are also many popular websites that run on PHP, such as Facebook. 

In order to get started with PHP, you will need a php web development stack. I chose to use the XAMPP stack after doing some research.  The reason I chose to use XAMPP is because I will be developing in a windows 7 environment, but I may want to deploy to a LAMP host.  XAMPP is an acronymn:

X: represents the server.  It is x because XAMPP is platform independent.
A: stands for Apache, which is the web server. If you are coming from an ASP.net background, you can think of Apache as the IIS of the PHP world.
M: stands for MySql, which is an open source database commonly used by PHP web applications
P: stands for PHP. 
P: stands for Perl.

To install XAMPP, you can download it from the apache friends website or you can follow the instructions from Murach's website

I did run into some issues getting Apache to run after installing XAMP.  This appears to be an issue specific to Windows 7. I will cover the resolution to that issue in my next post.

I highly recommend Murach's book PHP and MySQL as a guide to learning PHP: