New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Detecting and handling port conflicts on Mac OS X

From: Installing Apache, MySQL, and PHP

Video: Detecting and handling port conflicts on Mac OS X

When you install more than one copy of a particular server application, such as Apache or MySQL, and then try to run both at the same time, you will run into a port conflict. Apache, for example, listens on port 80 and only one application at a time can listen on that port. To demonstrate this, I have installed both the individual components, Apache and MySQL, and XAMPP represented by the XAMPP Controls panel, and MAMP represented by the MAMP application.

Detecting and handling port conflicts on Mac OS X

When you install more than one copy of a particular server application, such as Apache or MySQL, and then try to run both at the same time, you will run into a port conflict. Apache, for example, listens on port 80 and only one application at a time can listen on that port. To demonstrate this, I have installed both the individual components, Apache and MySQL, and XAMPP represented by the XAMPP Controls panel, and MAMP represented by the MAMP application.

Now, I'll go into the System Preferences and show you that both MySQL and Apache are running. I'll go into MySQL and show that the MySQL Server instance is running and then I'll go to Sharing and show you that Web Sharing is selected. Now, I'll show you what happens in XAMPP and MAMP when you try to run the same applications. XAMPP gives you a lot of help. I'll click the Start button for Apache and I get a really clear message. Web Sharing is on! And it tells me exactly how to fix the problem.

I can do the same thing for MySQL and once again I get a great error message. If you're working with MAMP though, this symptom is less clear. I'll click Start Servers in the MAMP application and simply nothing happens. Both the Apache Server red light and the MySQL Server red light stay lit. They don't switch to green. That's an indicator that the applications weren't able to start. Now the simplest thing to do is to go back to System Preferences and turn off the applications.

So I'll go to Sharing and deselect Web Sharing and then go back to the main System Preferences pane and go into MySQL and click Stop MySQL Server. If I'm prompted at any point for my Administrator password I'll type it in. Once the applications are stopped, I should be able to start Apache and MySQL for my selected server bundle. So I'll go to XAMPP and click Start on Apache. Once again I'm prompted for the Password, and I'll click Start for MySQL, and this time both start successfully.

Now I can't have XAMPP's versions of these servers and MAMP's running at the same time. So if I click Start Servers here I'll run into the same problem. Now I'm going to turn off the XAMPP versions and restart the individual components. I'll restart MySQL Server and restart Apache and I'll show you a way of finding out which versions of these servers are actually running, using some commands in Terminal. I'll go to Terminal by going to Spotlight, typing terminal, and choosing the application Terminal.

Within the application I am going to use a command called lsof, which stands for List Open Files. I'll run this command as the superuser. So I'll start with superuser do, or sudo, then a space, then lsof and then I'll add a couple of parameters, -i and -P. Then I'm going to filter the result of this command and look for applications that are running on a particular port. MySQL runs on Port 3306.

To do the filtering I'll type in the pipe character then grep, which searches text, and then the string I'm looking for, 3306. If I'm prompted for my Administrator password I'll type it in. This process might take a few seconds the first time you run it so be patient. So this shows me that MySQL is in fact running. It tells me that the name of the process is mysqld and it assigns a Process ID, which is random, of 29585.

Now, to stop the process I could go back to my System Preferences pane. I'll go to MySQL and I could click Stop MySQL Server. But another way of doing this is to kill the process from the command line, using the UNIX command Kill. You do this by the Process ID. So I'll double-click the Process ID and copy it to the clipboard. And then I'll type sudo, for superuser do, then kill and then I'll paste in the Process ID.

I'll go back to the System Preferences pane and show that the MySQL Server instance has stopped. You can do the same thing for the Apache server. So I'll type in sudo lsof -i -P, then the pipe character, grep, and then I'll search for port 80. Now make sure that you don't have any web browsers currently running. If you have browsers running you'll to get back a whole bunch of more information than you expect.

So I'll just go down to my Dock and make sure I don't have Firefox or Google Chrome or Safari running, then I'll come back to Terminal and press Return. Once again, it might take a few seconds for the process and the search to complete. Here is the response. Notice I'm getting back more information than I am expecting. What I'm really looking for is this string, :80, and I see that there are two processes running with httpd, the actual name of the Apache HTPP Server process.

If I wanted to kill these processes from the command line I could once again select and copy the Process IDs and kill them, but this time I'll stop the process from the System Preferences pane. I'll go back to the Sharing pane. I'll deselect Web Sharing. I'll come back to Terminal and press the up arrow key to restore the last command. I'll press Return and once again it'll take a few seconds to run the process. And when the response comes back, the httpd processes are not there anymore.

So that's a look in various ways of how to diagnose and then solve port conflict situations. Again, you can only have one copy of Apache and one copy of MySQL running at a time, and if you're not sure where the ports are being used you can use both the applications that come with these products and some commands in the Terminal application to diagnose and solve your issues.

Show transcript

This video is part of

Image for Installing Apache, MySQL, and PHP
Installing Apache, MySQL, and PHP

39 video lessons · 43027 viewers

David Gassner
Author

 
Expand all | Collapse all
  1. 17m 35s
    1. Welcome
      1m 9s
    2. Understanding Apache, MySQL, and PHP
      7m 12s
    3. Using the exercise files
      1m 7s
    4. What's new in this update
      3m 35s
    5. Choosing a software stack
      4m 32s
  2. 30m 18s
    1. Installing Apache HTTP Server 2.4 on Windows
      6m 51s
    2. Installing PHP 5.5 on Windows
      4m 12s
    3. Starting Apache from the command line
      5m 24s
    4. Installing MySQL on Windows
      7m 24s
    5. Installing phpMyAdmin on Windows
      6m 27s
  3. 44m 5s
    1. Activating Apache on Leopard and Snow Leopard
      3m 35s
    2. Activating Apache on Lion
      5m 9s
    3. Activating Apache on Mountain Lion and Mavericks
      4m 57s
    4. Configuring personal site folders on Mountain Lion and Mavericks
      6m 59s
    5. Activating PHP on Mac OS X
      6m 12s
    6. Installing MySQL on Mac OS X
      3m 59s
    7. Setting the root user password
      2m 28s
    8. Installing phpMyAdmin on Mac OS X
      6m 16s
    9. Uninstalling MySQL on Mac OS X
      4m 30s
  4. 14m 35s
    1. Installing WampServer
      6m 25s
    2. Managing WampServer
      2m 2s
    3. Defining directory aliases through WampServer
      2m 55s
    4. Changing software versions with WampServer add-ons
      3m 13s
  5. 10m 58s
    1. Installing MAMP
      4m 6s
    2. Configuring Apache and MySQL server ports
      1m 57s
    3. Managing MAMP
      4m 55s
  6. 29m 3s
    1. Installing XAMPP for Windows
      10m 0s
    2. Managing XAMPP for Windows
      4m 4s
    3. Managing MySQL security through XAMPP for Windows
      2m 40s
    4. Installing XAMPP for Mac OS X
      6m 14s
    5. Managing XAMPP for Mac OS X
      2m 27s
    6. Managing MySQL security through XAMPP
      3m 38s
  7. 13m 20s
    1. Installing BitNami for Windows
      6m 31s
    2. Installing BitNami for Mac OS X
      6m 49s
  8. 18m 49s
    1. Handling port conflicts with Skype on Windows
      2m 37s
    2. Handling other port conflicts on Windows
      5m 19s
    3. Detecting and handling port conflicts on Mac OS X
      6m 26s
    4. Configuring Apache to work with IPv6 on Windows 8
      4m 27s
  9. 31s
    1. Goodbye
      31s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.