MAMP Pro
Introduction
MAMP Pro is a very handy tool for having a Webserver with PHP and MySql on your Mac.
To obtain MAMP for Installation and Update you need to:
- Download MAMP PRO from www.mamp.info.
Installation
Installing is simple and only given here for reference.
- Follow the guidelines given on that Website documentation.mamp.info.
Update
To update is different cook. It all depends how you have configured your websites in MAMP and MAMP-Pro. The best way to create websites is outside the MAMP (PRO) environment. That prevents a lot of trouble (shit).
Manage ownership
MAMP has the user _www as default user to run the MAMP-server. When you try to run a Terminal application that uses files from the Server owned directory you need to do a sudo:
$ sudo ./<My-Appl-Cli> --about Password:
Give your OSX password and that will do the trick. Another way is to do is to use su, but that's even more annoying.
The best way is to change the group of the directory in the admin user (I think every Apple owner is also the admin of his device).
$ ls -Al /Applications/MAMP/www/Log -rw-rw-r--@ 1 _www _www 457 Oct 1 13:32 .htaccess -rw-rw-r-- 1 _www _www 103138 Jun 26 2016 Log4Anno.log -rwxrwxr-x 1 _www _www 11558605 Nov 15 19:04 Log4DbTrace.log -rw-rw-r-- 1 _www _www 4249529 Nov 21 16:25 Log4Energy.log ... -rw-rw-r-- 1 _www admin 28624 Nov 22 09:03 Log4Whois.log # Change the ownership of the group $ cd /Applications/MAMP/www/Log $ sudo chown :admin Log4DbTrace.log Password: $ ls -Al Log4DbTrace.log -rwxrwxr-x 1 _www admin 11M Nov 15 19:04 Log4DbTrace.log
If you try to send a mail with MAMP Pro you will notice that this is not working out-of-the-box. MAMP Pro uses postfix as you can find on the last tab of the MAMP Pro app.
- Just fill in 'gmail.com' at the Domain of outgoing mail and restart the server.
- Now open the mail log file which is located in the /var/log directory and you will see:
May 28 16:09:39 Harms-MBP-3.fritz.box postfix/master[78220]: fatal: bind fe80::1 port 25: Can't assign requested address May 28 16:09:49 Harms-MBP-3.fritz.box postfix/master[78221]: fatal: bind fe80::1 port 25: Can't assign requested address
The reason of these errors is located in the wrong binding to the ipv6 instead of the ipv4.
To change this:
- Edit the file main.cf located in the /etc/postfix/main.cf in terminal.
- Type
$ sudo nano /etc/postfix/main.cf
- Add the line
inet_protocols = ipv4
- Save the file in nano.
- Stop postfix:
sudo launchctl stop org.postfix.master
- Start postfix:
sudo launchctl start org.postfix.master
- Now look in the mail.log
tail -f -n 65 /var/log/mail.log
- Resulting in
May 28 16:28:29 Harms-MBP-3.fritz.box postfix/master[78439]: fatal: bind fe80::1 port 25: Can't assign requested address May 28 16:28:40 Harms-MBP-3.fritz.box postfix/master[78440]: daemon started -- version 2.11.0, configuration /etc/postfix May 28 16:29:26 Harms-MBP-3.fritz.box postfix/master[78440]: terminating on signal 15 May 28 16:29:26 Harms-MBP-3.fritz.box postfix/master[78443]: daemon started -- version 2.11.0, configuration /etc/postfix
- Fixed, the deamon has been started (see line2).
Mysql
When you receive the following warning on mysql on OSX:
PHP Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Data/.../Database.php on line 258 [26-Oct-2018 08:58:13 Europe/Berlin] PHP Stack trace: [26-Oct-2018 08:58:13 Europe/Berlin] PHP 1. {main}() /Applications/MAMP/www/.../DbTrace-be.php:0 [26-Oct-2018 08:58:13 Europe/Berlin] ... [26-Oct-2018 08:58:13 Europe/Berlin] PHP 8. mysqli_connect(*uninitialized*, *uninitialized*, *uninitialized*) /Data/.../Database.php:258
Solution
For some reason mysql on OS X gets the locations of the required socket file a bit wrong, but thankfully the solution is as simple as setting up a symbolic link.
You may have a socket (appearing as a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock, but one or more apps is looking in the other location for it.
Find out with this command:
$ ls -l /tmp/mysql.sock /var/mysql/mysql.sock
Stack-Overflow, War
Rather than move the socket, edit config files, and have to remember to keep edited files local and away from servers where the paths are correct, simply create a symbolic link so your Mac finds the required socket, even when it's looking in the wrong place!
[1]
'Comment: Exactly what I had with earlier MAMP installations, but since you are doing this once, you don't remember it.
If you have /tmp/mysql.sock but no /var/mysql/mysql.sock then..
$ cd /var $ sudo mkdir mysql $ sudo chmod 755 mysql $ cd mysql $ sudo ln -s /tmp/mysql.sock mysql.sock
If you have /var/mysql/mysql.sock but no /tmp/mysql.sock then...
$ cd /tmp $ ln -s /var/mysql/mysql.sock mysql.sock
You will need permissions to create the directory and link, so just prefix the commands above with sudo if necessary [1].
Comment: If you have already symbolic links use the resulting file iso creating a symbolic link to a symbolic link.
php xDebug
The following problem can occur while using xDebug [2]
Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
Look at the configuration of php in MAMP Pro [3]
[xdebug] MAMP_Xdebug_MAMPzend_extension="/Applications/MAMP/bin/php/php8.2.0/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so" xdebug.mode=debug xdebug.start_with_request=yes xdebug.client_port=9003 xdebug.client_host=localhost xdebug.output_dir="/Applications/MAMP/tmp"
If you set the log level to zero, this annoying message is not shown:
; Added by Harm Frielink HaFr ; Unfortunately, the only way to disable this error is to disable ; generally ALL errors & warnings in xdebug.ini: xdebug.log_level = 0
Level | Name | Example |
---|---|---|
0 | Criticals | Errors in the configuration |
1 | Errors | Connection errors |
3 | Warnings | Connection warnings |
5 | Communication | Protocol messages |
7 | Information | Information while connecting |
10 | Debug | Breakpoint resolving information |
StartTLS
The mail.log is located in the /var/log.
- After fixing the above issue the next problem is that the name of the host is taken as default name for the mail-send-account.
- In the example below look for:
- status=bounced
- Must issue a STARTTLS command first.
/Applications/MAMP/www/formula:HaFrMpro$ cat /var/log/mail.log Sep 6 10:00:19 Harms-MBP-2 postfix/pickup[15361]: 35FBB3FB6E3F: uid=501 from=<HaFrMpro> Sep 6 10:00:19 Harms-MBP-2 postfix/cleanup[15362]: 35FBB3FB6E3F: message-id=<20160906080019.35FBB3FB6E3F@mailer.gmail.com> Sep 6 10:00:19 Harms-MBP-2 postfix/qmgr[14705]: 35FBB3FB6E3F: from=<HaFrMpro@gmail.com>, size=902, nrcpt=1 (queue active) Sep 6 10:00:19 Harms-MBP-2 postfix/smtp[15364]: 35FBB3FB6E3F: to=<harm@harmfrielink.nl>, relay=smtp.gmail.com[74.125.136.109]:25, delay=0.55, delays=0.09/0.06/0.35/0.04, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.136.109] said: 530 5.7.0 Must issue a STARTTLS command first. id1sm31874130wjb.21 - gsmtp (in reply to MAIL FROM command)) Sep 6 10:00:19 Harms-MBP-2 postfix/cleanup[15362]: BA5023FB6E42: message-id=<20160906080019.BA5023FB6E42@mailer.gmail.com> Sep 6 10:00:19 Harms-MBP-2 postfix/bounce[15365]: 35FBB3FB6E3F: sender non-delivery notification: BA5023FB6E42 Sep 6 10:00:19 Harms-MBP-2 postfix/qmgr[14705]: BA5023FB6E42: from=<>, size=2858, nrcpt=1 (queue active) Sep 6 10:00:19 Harms-MBP-2 postfix/qmgr[14705]: 35FBB3FB6E3F: removed Sep 6 10:00:20 Harms-MBP-2 postfix/smtp[15364]: BA5023FB6E42: to=<HaFrMpro@gmail.com>, relay=smtp.gmail.com[74.125.136.108]:25, delay=0.31, delays=0/0/0.25/0.05, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.136.108] said: 530 5.7.0 Must issue a STARTTLS command first. b128sm25177085wmb.21 - gsmtp (in reply to MAIL FROM command)) Sep 6 10:00:20 Harms-MBP-2 postfix/qmgr[14705]: BA5023FB6E42: removed
CYREN - Greylisted
Sep 6 11:01:51 Harms-MBP-2 postfix/smtp[17040]: 94CD13FB74AD: host mxcluster2.one.com[91.198.169.9] said: 450 4.7.1 <harm@harmfrielink.nl>: Recipient address rejected: 95.90.202.130 temporary greylisted by CYREN IP reputation (in reply to RCPT TO command)
Example successful send
Dec 12 09:11:26 Tonne postfix/pickup[31994]: EF76490ECED: uid=502 from=<from.address@gmail.com> Dec 12 09:11:26 Tonne postfix/cleanup[31995]: EF76490ECED: message-id=<20141212081126.EF76490ECED@mailer.gmail.com> Dec 12 09:11:27 Tonne postfix/qmgr[31997]: EF76490ECED: from=<from.address@gmail.com>, size=391, nrcpt=1 (queue active) Dec 12 09:11:28 Tonne postfix/smtp[31998]: EF76490ECED: to=<to.address@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.136.27]:25, delay=2.2, delays=1.1/0.02/0.38/0.69, dsn=2.0.0, status=sent (250 2.0.0 OK 1418371832 k5si1095875wjf.30 - gsmtp) Dec 12 09:11:28 Tonne postfix/qmgr[31997]: EF76490ECED: removed
The problem with the above is that the from field is not field correctly. The PHP-mail command has the following signature and parameters:
- boolean mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Parameters:
- $to Receiver, or receivers of the mail.
The formatting of this string must comply with » RFC 2822. Some examples are:- user@example.com
- user@example.com, anotheruser@example.com
- User <user@example.com>
- User <user@example.com>, Another User <anotheruser@example.com>
- $subject Subject of the email to be sent. (Subject must satisfy » RFC 2047).
- $message Message to be sent.
Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters. - $additional_headers (optional) String to be inserted at the end of the email header.
- This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
- When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
- Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
- This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
Note:
If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.
additional_parameters (optional)
The $additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address (-fxxx@yyy.zz).
The mail from has to be set twice to be absolute sure it will work correctly:
- In the $additional_header. Please note the specific formatting of this field.
- In the $additional_parameters. Please note the format: -ffrom@xxx.nl without a space between -f and the email address (i.e. -fharm@harmfrielink.nl).
Which TCP Ports are open
Check for open TCP ports using Network Utility on Mac TCP/IP communications between your computer and other computers on the internet pass through numbered logical ports on each computer.
Knowing which ports are open on your computer can help you assess the security of your system or troubleshoot connection problems.
On your Mac, open the Network Utility app, located in the /System/Library/CoreServices/Applications folder.
Click Port Scan, enter your IP address, then click the Scan button.
For SMTP you need to have open post 25 and 465. But the latest port has been replaced by port 587
To find your IP address, choose Apple menu → System Preferences, click Network, then select a network service, such as Ethernet or Wi-Fi.
Open TCP Port
That is a bit tricky to do. The firewall may prohibit this action. Normally you do not need to open a port on your Mac!
- Open Terminal,
- Run the following command: nc -l localhost portnumber (replace portnumber with the actual number of the port you need to open).
- It looks like it doesn’t do a thing because netcat is waiting for a connection on that por
# Opens the closed smpt port number 587. $ nc -l localhost 587
BUT for SMTP do not use this port! Use port 587 instead!
Example MAMP Configuration
Since the gmail configuration gives bounced error due to authorization conflicts. I have used my own service provider One.com.
Set domain of outgoing emails
Use the basic name of the service provider (i.e. one.com) or for gmail (i.e. gmail.com).
Use a Smart host for Routing
Use the full name of the smtp service (i.e. send.one.com). In case of gmail (i.e. smtp.gmail.com).
Authentication
For one (i.e. Unencrypted).
User Name
The user name for the service provide (i.e. harm@harmfrielink.nl).
Password
The password. (i.e. ???).
See also
- ServerSMTP, SMTP Errors
- Elegant Themes, WordPress Mamp Pro
- Python, Python language
Reference
- ↑ 1.0 1.1 Stack-Overflow, Warning mysql connect 2002.
- ↑ xdebug.org, Home of the xDebugger.
- ↑ xdebug.org docs, Client Step Debug.