Download PHP tidy extension for Mac OS X

Update: You can download the file I’ve hosted and it may work for you, but I’ve come to realize that it’s better to compile the package hosted here http://php-osx.liip.ch/

You will need to download and install Command Line Tools for OS X, and then setup proper symlinks after compiling PHP. Be assured that you will have almost all the php extensions, you will possibly need.
—-

Yeah, I bought a Macbook Air 🙂

I cannot deny that it’s an awesome device and all that, but I’m still getting used to a new OS. The major work’s rediscovering the right tools and, of course, learning OS X’s keyboard shortcuts. Thankfully, it seems like a nice OS and all the work seems worth it.

 

Friggin' spinning wheel
by http://www.flickr.com/photos/mind-hacker/2726423319/lightbox/

That said, I now have a technology startup and cannot afford to just keep on ‘learning’. And that’s why small problems become big issues. All I needed was PHP-tidy to get on with life. Little did I know that it’d take up half of my day. So I’m putting it up here for people to download.

As most people, I got MAMP to avoid unnecessary complications and get on with “the code that matters to me”. MAMP is pre-packaged Apache-MySQL-PHP stack for Mac. My beef with the project is that they seem to be focusing on things that don’t really matter a lot to the target audience, like shiny-gui interface to configure document root, specify ports etc.. However, they seem to ignore few major bugs which seem to date around 2009.

  1. They do not package tidy extension, even though there have been requests in the forum.
  2. Their “pear.conf” configuration file’s broken, due to which neither pear nor pecl binary works, so tidy installation using pecl didn’t work either. The fix is a simple edit to the php_dir param though.
  3. Sadly, pecl still fails due to some issue with phpize.
  4. One solution is to compile PHP with tidy. However, there apparently is (or was) some bug with tidy, so I decided to avoid it and look around a little more.
  5. Then, I found this post that recommends using pre-compiled php-tidy binary that comes bundled along with Zend Studio IDE. I decided to check it out, and thankfully, it worked.

Sigh! Such a crazy way to solve a simple problem.

Anyways, since tidy is an open source project, I figured it may not be illegal to put the binary up for download. (Zend Studio is NOT free.)

You may download php tidy for OS X (tested on Lion)  from my public Dropbox folder.

[How To] Implementing Shindig.

I should have written an article/tutorial on how to implement/use Shindig to convert your SNS into and OpenSocial compliant SNS. Time, however, has prevented me from doing it so far. May be sometime later.

For now, you can have a look at my presentation on the same topic. I had presented it at Barcamp Bangalore 7, and PHPCamp Pune. It was recommended by Dan Peterson, Google, on the Shindig developer’s mailing list. 🙂

For those who don’t have an idea what I am talking about; I have been (officially) working on OpenSocial for quite sometime. OpenSocial is a specification developed by giants like Google, MySpace, Ning, etc. to provide a common platform (API) for social app developers. Shindig, an Apache incubator project, is what can help your site become OpenSocial compliant.

By the way, I am referring to the Six degrees of Separation in the initial slides. 🙂

Proposal for a new Array Syntax in PHP

PHP LogoA new array syntax has been proposed (for quite some time) for defining arrays in PHP. Currently, we use array() construct to create an array. Some examples could be:

$myArray = array(1, 2, 3, 4, 5);
$yourArray = array(1 => “one”, 2 => “two”, “three”);
$herArray = array(1, 2, 3, array(4 => “four”, “five”));

The proposal is to use square brackets ( [ ] ) to define an array. If passed, we would be able rewrite the above examples as:


$myArray = [1, 2, 3, 4, 5];
$yourArray = [1 => “one”, 2 => “two”, “three”);
$herArray = [1, 2, 3, [4 => “four”, “five”]];

There’s a good deal of discussion going on in the internal mailing list with almost equal number of people voting “for” and “against” it. Rasmus, isn’t not very supportive, yet has voted for the new proposal.

To be pretty honest, I am still not very sure if it’s going to be worth the trade-offs.
Anyhoo! Let’s wait and watch. 🙂

Apache Headache: “no listening sockets available”

Update 1: I was unable to configure MySQL. Reason: It was installed in C:\(blah-blah) and , probably, do not have write rights in the directory. Installing it to D:\(bigBlah) solved the issue. Duh!

Update 2: I see a fairly good traffic coming here searching for the same problem. So, in case you are in a hurry, this is mostly a summary to inform you that in all probability, YOU HAVE SOME SERVICE RUNNING ON PORT 80. Check out using TCPView (if you are on windows). Hope that helps. 🙂

I am currently working on an official XSS (Cross Site Scripting) presentation. I needed some screenshots of alert boxes and defaced site. So I installed Apache, configured it to work with PHP. (If you need help in installing and configuring MySQL, Apache and PHP, look here).

But this was day before yesterday. Yesterday, I needed to make a quick manipulation to the script, but… Apache won’t start. The error I was getting (using eventvwr) was:

>>> (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 .

It’s pretty apparent that some other jerk was sitting and listening at port 80. Yesterday, however, was too hectic to discover the rat. Today, I ran TCPView (thanks to Shruthi for suggesting) to discover that inetinfo.exe was the ra**al. TCPView is one of the nicest tools created by the guys at SysInternals, which was later acquired by Microsoft. Rats!

Anyways, the fun part was stopping the service. I couldn’t kill it. Neither using TCPView, nor Task Manager. It would again span back to life 🙂

So, finally I opened services.msc to stop the IIS server and change the automatic start mode to manual mode. Heck! I should have disabled… or even better, deleted the scoundrel. 😀

So, if you have the same problem, you are in all probability in office right now and hence may not be aware what services are running. Use TCPView to discover all those unnecessary network services. It’s a great tool. Further, you might also want to switch some stupid services from automatic start mode to manual (or disable :P). Use Services.msc.

Apache-MySQLPHP Installation & Configuration Tutorial for Beginners :)

Note: This article still seems to attract a fair bit of traffic. Just wanted to let you guys know that this is a pretty old article. PHP development environment has come a long way since then. You may want to download and use any of the following packaged environments instead: WAMP or XAMPP on Windows, or MAMP on OS X

In case you have any other queries, feel free to drop a note in the comments. I’ll try to answer.


This article is a very “narrow” tutorial aimed for complete beginners and dummies, who want to start off coding with AMP (Apache-MySQL-PHP) but do not want to read manual for installing and configuring them.
This write up is very specifically targeted and applies for Windows platform.

Note: To get the real and complete understanding, spend some time with the manuals. They are the best source of information.

Installing and Configuring PHP5 with Apache

    1. Select the most appropriate mirror for you from the following: http://www.apache.org/dyn/closer.cgi/httpd/binaries/win32/ (for Apache), and http://www.php.net/downloads.php for PHP.
    2. Download apache_1.3.x-win32-x86-no_src.exe and PHP 5.1.2 zip package (names PHP-5.x-win32).
        • DO NOT use Apache 2.x with PHP.

       

      • If you use PHP 4.x, make proper changes in the some of the steps given below.

Note:

  1. Install Apache by simply clicking on the exe file. The default path is C:\Program Files\Apache Group\Apache.
  2. Unzip the PHP file to C:\PHP.
  3. Add C:\PHP to system path.
  4. Backup and rename php.ini.dist to php.ini.
  5. Copy php5ts.dll and php.ini to %systemroot%.
  6. Copy php5apache.dll to C:\Program Files\Apache Group\Apache.
  7. Open cmd (command prompt) and run net stop apache (to obviously stop the server).
  8. Backup httpd.conf, located in C:\Program Files\Apache Group\Apache\conf, and then open it in an editor to add the following lines:
    • LoadModule php5_module php5apache.dll
    • AddType application/x-httpd-php .php
    • AddModule mod_php5.c [If you face any problems, remove this line and check again]
  9. Net start Apache.
  10. To check if all everything is in place, write the following code in a notepad and save it as “phpinfo.php” (with inverted quotes).

<?php
phpinfo();
?>

  1. Place the file in your DocumentRoot directory. The default path is C:/Program Files/Apache Group/Apache/htdocs.
  2. Start your Mozilla Firefox browser (it’s not mandatory, just a recommendation :P), and type http://localhost/phpinfo.php.
  3. If everything’s fine, we’ll see something like this:

 

phpinfo.jpg

Installing MySQL:

  1. We can find it in three shapes and sizes :D, The Complete Package, The Essentials Package and The Noinstall Archive. We’d go for the complete package named mysql-[version]-win32.
  2. The installation part is click next type.
  3. At the end of the installation, click to configure and choose the options as per your choice or as given below:
    • Detailed Configuration>Next
    • Developer Machine>Next
    • Multifunctional Database>Next
    • >Next
    • Manual Settings (choose 5)>Next
    • Enable TCP/IP (leave default port as 3306)>Next
    • Add to both, windows services and ssytem path>Next
    • Choose root password>Next
    • Execute.


Configuring MySQL & PHP:

  1. Open php.ini, located in %systemroot%, in and editor and uncomment the following line by removing the semicolon at the beginning of the line:
  2. extension=php_mysql.dll
  3. Copy php_mysql.dll and libmysql.dll from C:\PHP\ext to C:\PHP.
  4. To verify the configuration and administer MySQL, one may use phpmyadmin, found at http://www.phpmyadmin.net/home_page/index.php. However, do make sure not to publish it along with the site :P.
  5. That’s it. Happy Coding (. For anymore queries, either leave your comments or refer to the manuals.