title: MAMP "Apache couldn't be started because port is in use." AND "Can’t connect to local MySQL server through /tmp/mysql.sock
body: <p>After restarting MAMP, I noticed the MySQL Server checkbox didn't turn green as it usually does.  I clicked 'Start Servers' again and got a message stating, "Apache couldn't be started because port 8888 is in use by some other software."  Weird since I haven't made any changes to the system or application, or installed any updates.  I opened Chrome and entered the url of a site I'm developing locally and it showed up with no problem.  But, when I tried to log into the site with a dummy user account I received a "SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket ' /Applications/MAMP/tmp/mysql/mysql.sock' (2)" message.</p>
  
  <p>Regarding the first problem (Apache Port in use by another program), I opened up Terminal and <code>&gt;&gt; sudo lsof -i -P | grep -i "listen"</code> to see which ports would show up. When MAMP was closed, the console output was </p>
  
  <p><code>launchd       1           root   23u  IPv6 0x156733646a84db9h      0t0    TCP *:5900 (LISTEN)
  launchd       1           root   24u  IPv4 0x156733646a84eba8     0t0    TCP *:5900 (LISTEN)
  launchd       1           root   28u  IPv6 0x156733646a84d75u      0t0    TCP localhost:631 (LISTEN)
  launchd       1           root   29u  IPv4 0x156733646a84e3bu      0t0    TCP localhost:631 (LISTEN)
  launchd       1           root   31u  IPv6 0x156733646a84d31u      0t0    TCP *:22 (LISTEN)
  launchd       1           root   32u  IPv4 0x156733646a857ba5      0t0    TCP *:22 (LISTEN)
  kdc          96           root    6u  IPv6 0x156733646a84cedt      0t0    TCP *:88 (LISTEN)
  kdc          96           root    8u  IPv4 0x156733646c2a9ba5      0t0    TCP *:88 (LISTEN)
  imagent     270           userhomedirectory    7u  IPv4 0x156733646a1a13bb      0t0    TCP *:52216 (LISTEN)
  EEventMan   279           userhomedirectory    4u  IPv4 0x156733646a8573bb      0t0    TCP *:2968 (LISTEN)
  </code>
  The output when MAMP is running is (everything listed above) + :</p>
  
  <p><code>httpd     28772 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28786 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28790 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28791 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28792 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28793 userhomedirectory    5u  IPv6 0x156733646a84b55f      0t0    TCP *:8888 (LISTEN)
  httpd     28794 userhomedirectory    5u  IPv6 0x169041156a84b55f      0t0    TCP *:8888 (LISTEN)
  </code></p>
  
  <p>So, Port 8888 is only in use when MAMP is launched, which also tells me that the web server is, in fact, connected.  So I don't understand why I'm getting an Apache port error. </p>
  
  <p>Anyway, next I opened Activity Monitor and killed every httpd and mysqld process that was running and restarted MAMP but, the problem persisted.  The mysqld process never reappeared after I killed it the first time. </p>
  
  <p>Then, I searched SO.  I came across <a href="https://stackoverflow.com/questions/26124504/mamp-pro-apache-couldnt-be-started-because-the-port-was-already-in-use">a post</a> regarding MAMP PRO and decided to try the suggested solutions but, to no avail.  Same goes for <a href="https://stackoverflow.com/questions/23245096/mamp-3-apache-wont-start-on-port-8888">this post</a>'s suggestion to delete and re-install the entire application.  </p>
  
  <p>By now I can't tell if the mysql error is causing the apache error or if the apache error is causing the mysql error.  So, I searched and tried several solutions regarding the mysql error including suggestions from <a href="https://stackoverflow.com/questions/16133467/mamp-phpmyadmin-2002-cant-connect-to-local-mysql-server-through-socket-a">this post</a>, and <a href="http://www.tech-recipes.com/rx/762/solve-cant-connect-to-local-mysql-server-through-socket-tmpmysqlsock/" rel="noreferrer">this post</a>, but none of them worked for me. I mean, I literally tried every single suggestion on those pages, from the posted answers to the comments. </p>
  
  <p>I've also tried restarting my computer, changing the apache, nginx and mysql port configuration settings, switching from apache to nginx, loading MAMP's MySql from Terminal, creating a my.cnf file with the socket configuration.  None of which have worked. </p>
  
  <p>Does anyone have any experience with this? Is it an Apache port error or a MySQL socket error?  Or something totally different?  And considering that there were no updates installed or changes to anything in the system or application, what could have caused this?</p>
  
  <p>Thanks in advance. </p>
  
  <p><strong>* **Edit December 10, 2014</strong> ***<br>
  So I played around with this all night.  I re-installed the application a couple of times.  Installed some updates and even copied my laptop's MAMP setup, which works, to my desktop.  But, I still got the same errors.  Then I changed MAMP's document root back to the default <code>Mac HD -&gt; Applications -&gt; MAMP -&gt; htdocs</code> and it worked!  I had previously set it to <code>/Users/userhomedirectory/Sites</code>.</p>
  
  <p>I posted this as an edit instead of an answer because the problem still exists. Changing the document root back to <code>Users/myhomedirectory/Sites</code> gives me the same error messages as before so my solution is more of a workaround.  Hopefully this sets off a lightbulb for someone because I still can't figure out what could be the cause and/or solution. </p>