Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 82584 Viewers
80 Video lessons · 133834 Viewers
52 Video lessons · 67114 Viewers
59 Video lessons · 52948 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.