Can MAMP automatically start when I start my mac?

You can ask general questions about MAMP here.

Moderator: severin

Can MAMP automatically start when I start my mac?

Postby kabo » Sun May 01, 2005 9:25 pm

Is there a way to make MAMP start the apache-server and MySQL when I start my mac?
Add a .sh-script to StartupItems perhaps?


/Calle Kabo
kabo
 
Posts: 5
Joined: Fri Apr 22, 2005 8:59 am

Postby kabo » Mon May 02, 2005 7:09 pm

***EDIT*** This solution does not work, read the next post to solve it!

Yay, I solved it! :)

added a folder called MAMP in /Library/StartupItems/
I then added a file called MAMP containg this
Code: Select all
#!/bin/sh

. /etc/rc.common

StartService()
{
/Applications/MAMP/bin/mysql4/bin/mysqld_safe --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lower_case_table_names=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log &
/Applications/MAMP/bin/apache2/bin/apachectl start
}

StopService()
{
/Applications/MAMP/bin/mysql4/bin/mysqladmin -u root -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown
/Applications/MAMP/bin/apache2/bin/apachectl stop
}

RunService "$1"


and a file called StartupParameters.plist containing
Code: Select all
{
  Description   = "MAMP";
  Provides      = ("MAMP");
  Uses          = ("Super Server");
  OrderPreference = "None";
  Messages =
  {
    start = "Starting MAMP";
    stop  = "Stopping MAMP";
  };
}


the file MAMP has to be issued the following commands:
sudo chown root MAMP
sudo chmod 755 MAMP

***OLD EDIT***
Hmm... it seems this solution isn't fully working though...
MySQL seems to start and I can access the databases, but not the tables?!?!
Weird...

The thing is, when I use start.sh in the terminal this happens...
But when I use MAMP to start apache and MySQL it works fine.
Why is this? What is the difference?

Anyway, I found out about launchd in Mac OS X:
http://developer.apple.com/documentatio ... index.html
so maybe that solution is better...
Last edited by kabo on Thu May 05, 2005 12:12 pm, edited 1 time in total.
kabo
 
Posts: 5
Joined: Fri Apr 22, 2005 8:59 am

Postby kabo » Thu May 05, 2005 12:11 pm

OK, now I've finally solved it! (now where have I heard that before...?)

The best way is to use launchd to start the apache2-server and the MySQL-database. This is done by placing two .plists in /Library/LaunchDaemons/
One called apache2.plist and one called MySQL.plist.
In apache2.plist write:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>info.mamp.apache2</string>
   <key>OnDemand</key>
   <false/>
   <key>ProgramArguments</key>
   <array>
      <string>/Applications/MAMP/bin/apache2/bin/apachectl</string>
      <string>start</string>
   </array>
   <key>UserName</key>
   <string>root</string>
</dict>
</plist>


And in MySQL.plist type:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>info.mamp.MySQL</string>
   <key>OnDemand</key>
   <false/>
   <key>ProgramArguments</key>
   <array>
      <string>/Applications/MAMP/bin/mysql4/bin/mysqld_safe</string>
      <string>--port=3306</string>
      <string>--socket=/Applications/MAMP/tmp/mysql/mysql.sock</string>
      <string>--lower_case_table_names=0</string>
      <string>--pid-file=/Applications/MAMP/tmp/mysql/mysql.pid</string>
      <string>--log-error=/Applications/MAMP/logs/mysql_error_log</string>
   </array>
   <key>UserName</key>
   <string>YOUR_USERNAME_HERE</string>
</dict>
</plist>

Note that you have to write your username here in order to launch MySQL correctly.

*phew* now I don't have to think about that anymore... :)
kabo
 
Posts: 5
Joined: Fri Apr 22, 2005 8:59 am

Postby chabig » Tue Oct 11, 2005 3:38 am

Your plists didn't work for me. I only wanted MAMP to run when I was logged in to one specific user account. Here are the launchd plists that worked for me. They are installed in /Users/myusername/Library/LaunchAgents/ to ensure they only run when I log in...

apache2.plist
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>info.mamp.apache2</string>
   <key>OnDemand</key>
   <false/>
   <key>Program</key>
   <string>/Applications/MAMP/bin/apache2/bin/apachectl</string>
   <key>ProgramArguments</key>
   <array>
      <string>/Applications/MAMP/bin/apache2/bin/apachectl</string>
      <string>start</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>ServiceDescription</key>
   <string>This plist launches MAMP's apache server at startup.</string>
   <key>UserName</key>
   <string>MYUSERNAME</string>
</dict>
</plist>


Note that apache is started at login (RunAtLoad) rather than on demand. Also note that MYUSERNAME is your OS X username. Root is not correct because you want to run MAMP in user space.

MySQL.plist
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>info.mamp.MySQL</string>
   <key>OnDemand</key>
   <false/>
   <key>Program</key>
   <string>/Applications/MAMP/bin/mysql4/bin/mysqld_safe</string>
   <key>ProgramArguments</key>
   <array>
   <string>/Applications/MAMP/bin/mysql4/bin/mysqld_safe</string>
   <string>--port=8889</string>
   <string>--socket=/Applications/MAMP/tmp/mysql/mysql.sock</string>
   <string>--lower_case_table_names=0</string>
   <string>--pid-file=/Applications/MAMP/tmp/mysql/mysql.pid</string>
   <string>--log-error=/Applications/MAMP/logs/mysql_error_log</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>ServiceDescription</key>
   <string>This plist launches MAMP's MySQL server at startup.</string>
   <key>UserName</key>
   <string>MYUSERNAME</string>
</dict>
</plist>


Note the same RunAtLoad issue as with apache (I want this to run at login). I set the port to 8889, which is MAMP's default port, rather than 3306. And also realize that as above, MYUSERNAME is the OS X username, not the name of the MySQL account.

Put these two plists in your ~/Library/LaunchAgents/ folder to have MAMP automatically run at login. Create the LaunchAgents folder if you must.

Chris
chabig
 
Posts: 11
Joined: Tue Oct 11, 2005 3:22 am

Postby leovst » Mon Jul 31, 2006 10:09 am

For me the apache2.plist worked,
but i'm having trouble with the MySQL.plist file.
I tried both and none of them worked,
I changed the UserName and the port,
are there other things I have to change?
leovst
 
Posts: 1
Joined: Sun Jul 30, 2006 4:59 pm

Postby chabig » Wed Aug 16, 2006 2:14 pm

The only thing you should have to change is the username. Just make sure to use your Mac OS X username, not your MySQL username.

Chris
chabig
 
Posts: 11
Joined: Tue Oct 11, 2005 3:22 am

Postby cbo » Sun Sep 17, 2006 6:25 pm

leovst wrote:For me the apache2.plist worked, but i'm having trouble with the MySQL.plist file ...


It seems that with newer versions of MAMP you also need to change the location of the mysql call from MAMP/bin/mysql4/bin/ to MAMP/Library/bin/

Was...
Code: Select all
<string>/Applications/MAMP/bin/mysql4/bin/mysqld_safe</string>
   <key>ProgramArguments</key>
   <array>
   <string>/Applications/MAMP/bin/mysql4/bin/mysqld_safe</string>

Should be...
Code: Select all

    <string>/Applications/MAMP/Library/bin/mysqld_safe</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Applications/MAMP/Library/bin/mysqld_safe</string>


I'm not sure when it changed, but /Applications/MAMP/bin/mysql4/bin/ doesn't exist in the PPC version I grabbed today. Use this instead of the above MySQL.plist (replacing your MYUSERNAME of course.) Worked for me. MAMP whips A!

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http:// www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>info.mamp.MySQL</string>
    <key>OnDemand</key>
    <false/>
    <key>Program</key>
    <string>/Applications/MAMP/Library/bin/mysqld_safe</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Applications/MAMP/Library/bin/mysqld_safe</string>
    <string>--port=8889</string>
    <string>--socket=/Applications/MAMP/tmp/mysql/mysql.sock</string>
    <string>--lower_case_table_names=0</string>
    <string>--pid-file=/Applications/MAMP/tmp/mysql/mysql.pid</string>
    <string>--log-error=/Applications/MAMP/logs/mysql_error_log</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceDescription</key>
    <string>This plist launches MAMP's MySQL server at startup.</string>
    <key>UserName</key>
    <string>MYUSERNAME</string>
</dict>
</plist>
cbo
 
Posts: 2
Joined: Sun Sep 17, 2006 6:13 pm

Re: Can MAMP automatically start when I start my mac?

Postby steiner » Thu Apr 23, 2009 9:09 pm

Hi,
I've tried the last method "updated" with the new paths.
MySQL starts perfectly but apache don't :(
Here is my apache2.plist :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>info.mamp.apache2</string>
   <key>OnDemand</key>
   <false/>
   <key>Program</key>
   <string>/Applications/MAMP/Library/bin/apachectl</string>
   <key>ProgramArguments</key>
   <array>
      <string>/Applications/MAMP/Library/bin/apachectl</string>
      <string>start</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>ServiceDescription</key>
   <string>This plist launches MAMP's apache server at startup.</string>
   <key>UserName</key>
   <string>MYUSERNAME</string>
</dict>
</plist>

I've put it in : /Users/MYUSERNAME/Library/LaunchAgents

I've tried 2 paths for apachectl :
- /Applications/MAMP/Library/bin/apachectl
- /Applications/MAMP/bin/apache2/bin/apachectl
Hence there is a symbolic link, it's in fact the same file.

Can't figure what's wrong :s

Thx in advance for your advice.
steiner
 
Posts: 1
Joined: Thu Apr 23, 2009 9:02 pm


Return to General questions

Who is online

Users browsing this forum: Google [Bot] and 4 guests