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.