Improve MAMP local performance and reduce RAM usage

You might have too many httpd processes running on your system during development.

Screenshot of httpd processes haven taken over the machine.

2015 03 03 03 12 40 PM

 

Objective: Reduce the amount of spare httpd servers that apache will maintain in memory.

Purpose: Since this is for local development purposes it’s not likely that the number of users will exceed 256 clients.

Overview:

These are the internal default configuration for Apache sets its configuration. This section will not exist in your httpd.conf file unless you already created it prior.

<IfModule prefork.c>

StartServers 4
MinSpareServers 3
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 10000

</IfModule>

 

Insert/replace the following in httpd.conf – File->Edit Template->Apache->httpd.conf

<IfModule prefork.c>

StartServers       2

MinSpareServers    1

MaxSpareServers   2

ServerLimit      256

MaxClients       256

MaxRequestsPerChild  10000

</IfModule>

 

This will reduce the amount of spare httpd processes in memory and reduce the amounts of threads used by the processor. This will improve your overall system performance, reduce energy and battery usage as well.

Compile PHP 5.5.14 on upgrade from MAMP Pro 5.5.10 php -i /configure

 

This will require the use of Brew.

sudo brew install gettext

//create symbolic link to lib location, needed for php compilation
//this will also fix any linking errors that might occur related to libintl.h 
ln -s /usr/local/Cellar/gettext/0.18.3.2/lib/libintl.* /usr/local/lib/

sudo brew install t1lib

 
The php that comes with MAMP Pro is compiled with the following ./configure command. To verify that this is the case you can issue php -i command in the location of your php executable, usually in /Applications/MAMP/bin/php/phpxxxxxx/bin/.
 

./configure  –with-mysql=/Applications/MAMP/Library –with-gd –with-jpeg-dir=/Applications/MAMP/Library –with-png-dir=/Applications/MAMP/Library –with-zlib –with-zlib-dir=/Applications/MAMP/Library –with-freetype-dir=/Applications/MAMP/Library  –enable-ftp –enable-gd-native-ttf –with-bz2=/usr –with-ldap –with-mysqli=/Applications/MAMP/Library/bin/mysql_config –with-t1lib=/Applications/MAMP/Library –enable-mbstring=all –with-curl=/Applications/MAMP/Library –enable-sockets –enable-bcmath –with-imap=shared,/Applications/MAMP/Library/lib/imap-2007f –enable-soap –with-kerberos –enable-calendar –with-pgsql=shared,/Applications/MAMP/Library/pg –enable-exif –with-libxml-dir=/Applications/MAMP/Library –with-gettext=shared,/Applications/MAMP/Library –with-xsl=/Applications/MAMP/Library –with-pdo-mysql=shared,/Applications/MAMP/Library –with-pdo-pgsql=shared,/Applications/MAMP/Library/pg –with-mcrypt=shared,/Applications/MAMP/Library –with-openssl –enable-zip –with-iconv=/Applications/MAMP/Library –enable-opcache –enable-cgi –enable-intl –with-icu-dir=/Applications/MAMP/Library –with-tidy=shared

 

Creds: https://stackoverflow.com/questions/11370684/what-is-libintl-h-and-where-can-i-get-it

Get MacOSX to use MAMP PHP path



Open a Terminal and Locate your osx php version with:

which php

On Maverick the result should be:

/usr/bin/php

2. Backup (move) your original php binary:

sudo mv /usr/bin/php /usr/bin/php.bak

 

sudo ln -s /Applications/MAMP/bin/php/php5.4.25/bin/php /usr/bin/php



It works like a charm, alias in bashrc doesn't work out. So must do it this way. Thanks @Heik

Install SSH2 on OSX MAMP PRO

 

Creds http://cyberpunx.com/2011/11/install-ssh2-support-for-mamp-and-php-5-3-x/

Updated instructions 2014

brew update

brew doctor

brew install libssh2
cd /Applications/MAMP/bin/php/php5.4.25/
sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade
sudo pecl install channel://pecl.php.net/ssh2-0.12

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :
 

Build process completed successfully

Installing ‘/usr/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so’

install ok: channel://pecl.php.net/ssh2-0.12

configuration option “php_ini” is not set to php.ini location

You should add “extension=ssh2.so” to php.ini

 

cp /usr/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so

chmod 755 /Applications/MAMP/bin/php/php5.4.25/lib/php/extensions/no-debug-non-zts-20100525/ssh2.so


Edit template, add extension=ssh2.so

restart apache, check for ssh2 with phpinfo mama start page

which php should give you the version of php on osx, if the one you’re using with mamp is not far apart then this method will work, otherwise you will have to compile with php version that matches the one you’re using in mamp

 

How to install ssh2.so for PHP 5.3.x on OSX Lion and MAMP

 

For a recent project I needed to use the ssh2 extension with PHP. I had tried to use phpseclib, but found that it doesn’t support for DSA keys (a requirement for my project). Using the instructions below, you can easily install ssh2 support for PHP using homebrew.

Using homebrew to install libssh2:

brew install libssh2

I was working with a fresh OSX Lion install, so I needed to install pear. Luckily it comes with Lion, so we just need to install and update.

sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
sudo pear upgrade

After pear is setup, we can use pecl to install the ssh2 extension:

sudo pecl install channel://pecl.php.net/ssh2-0.11.3

When prompted for the libssh2 prefix, just press enter for autodection:

libssh2 prefix? [autodetect] :

This next step is optional and should not be done if you already have a /private/etc/php.ini file. However, this step may help others who are working with a fresh install like I was:

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Now we need to add the ssh2.so to the php.ini …so open /private/etc/php.ini with your favorite editor and add the following line:

extension=ssh2.so

After saving, run the following command and it should output ‘ssh2′:

php -m | grep ssh2

Now lets copy ssh2.so to the MAMP extension folder:

cp /usr/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so /Applications/MAMP//bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/

Edit the php.ini template for MAMP’s PHP install and add:

extension=ssh2.so

MAMP PHP Template

Restart MAMP… ssh2 extension should now be installed for the system’s PHP and MAMP’s PHP.

Output of phpinfo(); will show this:

 

Where are mysql db files kept – MAMP PRO and more

Where are MySQL’s Files Kept?

MySQL stores and accesses files in various places on your hard drive. This page documents the locations of commonly used files, for some often used MySQL installations.

If you want to backup your data or copy data from one server to another, please don’t copy the data files directly. It is recommended to use Sequel Pro’s Export and Import features (use a MySQL dump) to accomplish this.

If you can’t find the files in the locations given here, it could be because you changed the configuration — these are only the default locations. Some of the files only exist while the MySQL server is running (eg. the socket file).

If your installation has no option file (my.cnf), you can create it in the base directory of your installation (see ‘Using Option Files’ section of the MySQL manual for more information).

If you can connect to your MySQL server, you can find many of these paths by selecting Show Server Variables… from the Database Menu in Sequel Pro.

MySQL installed with the official .pkg installer

Socket File
/tmp/mysql.sock
Data Files
/usr/local/mysql/data/
Error Log
/usr/local/mysql/data/HOSTNAME.err (insert your hostname)
Base Directory
/usr/local/mysql/ (this is a symbolic link)

MySQL pre-installed on Mac OS X Server

Socket File
/var/mysql/mysql.sock

MySQL 5 installed with MacPorts

Socket File
/opt/local/var/run/mysql5/mysqld.sock
Data Files
/opt/local/var/db/mysql5/
Error Log
/opt/local/var/db/mysql5/HOSTNAME.err (insert your hostname)

MySQL installed with MAMP

Socket File
/Applications/MAMP/tmp/mysql/mysql.sock
Data Files
/Applications/MAMP/db/mysql/
Base Directory
/Applications/MAMP/Library/
Error Log
/Applications/MAMP/logs/mysql_error_log

MySQL installed with MAMP PRO

MAMP PRO shares many paths with MAMP, with the following difference:

Data Files
/Library/Application Support/appsolute/MAMP PRO/db/mysql

MySQL installed with XAMPP

Socket File
/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
Data Files
/Applications/XAMPP/xamppfiles/var/mysql
Configuration File
/Applications/XAMPP/xamppfiles/etc/my.cnf

 

MySQL installed with Zend Server CE

Socket File  
/usr/local/zend/mysql/tmp/mysql.sock
http://www.sequelpro.com/docs/Where_are_MySQLs_Files