Portable MAMP (Apache2 + PHP5 +MySQL5)

The aim of that quick and dirty tu­to­rial is a fully func­tio­nal web ser­ver run­ning from any usb-drive on mac OS X (10.4) and maybe on other unix / li­nux dis­tri­bu­ti­ons. For sure the fol­lo­wing de­scripts seem to be very com­li­ca­ted and con­fu­sing but it's a step by step guid to build your own MAMP (Ma­cA­pa­che­Mys­ql­Php) which will be a lot more fle­xi­ble be­cause it's in­de­pen­det of any lo­cal set­tings. I call it por­ta­ble MAMP or just pMAMP.
As MAMP it' not made to run a pu­blic web ser­ver be­cause of a whole lot of out­stan­ding se­cu­rity ho­les.
Also its a kind of un­fle­xi­ble be­cause of the sta­tic path na­mes ('COMPSPINE') but it's just a ques­tion of the right script (perl seems to be a good for me).

Sta­tus: Apa­che and PHP working per­fect. MySQL not really.

0. Re­qui­re­ments

- A USB Stick
- Mac OS 10.4 (10.3 not tes­ted)
- In­stal­la­tion of Apple De­ve­l­oper Tool­kit, avail­able at: http://developer.apple.com/tools/download/

Fol­der struc­ture on the USB-drive / USB stick
COMPSPINE
-data
-mac
----apache-2.0.58

----mysql-5.0.45
----php-5.2.5
----logs

1. Pre­pa­ra­ti­ons

Get an USB-Stick, plug it into your Mac and open Disk Uti­lity. It can be star­ted in Fin­der in the fol­ders Ap­p­li­ca­ti­ons and then Uti­li­ties or sim­ply by a Ter­mi­nal com­mand like that:

open -a /Applications/Utilities/Disk\ Utility.app

We want to par­ti­tion a MS DOS drive which can be read by eit­her win32 and Unix platt­forms. Wi­t­hin the Disk Uti­lity you should see a orange co­lo­red drive na­med like your USB-stick in­side Fin­der. Select it and chose the 'Par­ti­tion' tab on the right hand side. Select MS DOS form the drop down menu and change the par­ti­tion size if you want to. Finaly press 'par­ti­tion' and con­firm it by cli­cking OK. Take care that you backup all your im­port­ant data form your stick in ad­vance be­cause par­ti­tio­ning de­lets ever­y­thing. As long as any ap­p­li­ca­tion ac­ces­ses the USB drive Disk Uti­lity can't un­mount the drive which is ne­cess­arry be­fore star­ting the par­ti­tio­ning process.

2. In­stall Apa­che on USB drive

Down­load Apache-2.0.58 on your Desk­top from
http://archive.apache.org/dist/httpd/httpd-2.0.58.tar.gz

Open your Ter­mi­nal and type:

cd /Volumes/COMPSPINE/mac/apache-2.0.58
sudo ./configure --prefix=/Volumes/COMPSPINE/mac/apache-2.0.58 --enable-mods-shared=most
make
make in­stall
open -e conf/httpd.conf

Your fa­vo­rite edi­tor should ap­pear with the httpd con­fi­gu­ra­tion file. Se­arch for the line "Lis­ten 80" and change it to "Lis­ten 8080" (use an other port if that on is used by an other ap­p­li­ca­tion like tom­cat e.g.). Re­place line:
Do­cu­ment­Root "/Volumes/COMPSPINE/mac/apache-2.0.58/htdocs"
with
Do­cu­ment­Root "/Volumes/COMPSPINE/data".
As well re­place

with
Save and close the file.Open now bin/apachectl:

open -e /Volumes/COMPSPINE/mac/apache-2.0.58/bin/apachectl

Re­place the line:
HTTPD='/Volumes/COMPSPINE/mac/apache-2.0.58/bin/httpd'
by
HTTPD='/Volumes/COMPSPINE/mac/apache-2.0.58/httpd'Back in Ter­mi­nal type:

sudo /Volumes/COMPSPINE/mac/apache-2.0.58/bin/apachectl start
open -a Sa­fari 127.0.0.1:8080

If the URL '127.0.0.1:8080' ap­pears wi­t­hin the adress line in your Sa­fari your Apache2 is running.

3. In­stall PHP

Try to down­load PHP on your Desk­top from (URL may change af­ter a while): http://de3.php.net/get/php-5.2.5.tar.bz2/from/a/mirror

Ex­tract the file on your Desk­top and:

cp ~/Desktop/php-5.2.5 /Volumes/COMPSPINE/mac

Stop the Apa­che to avoid conflicts

cd /Volumes/COMPSPINE/mac/apache-2.0.58/bin
sudo apachectl stop

Do some hard co­ding as a work around (I could fi­gure out which op­tion flag of the fol­lo­wing ./configure co­mand would be a bet­ter solution):

open -e /Volumes/COMPSPINE/mac/apache-2.0.58/bin/apxs

Re­place
my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
with
my $httpd = "/Volumes/COMPSPINE/mac/apache-2.0.58" . "/" . get_varsNow we are go­ing to con­fi­gure a Make­file to com­pile PHP:

/Volumes/COMPSPINE/mac/php-5.2.5/configure --prefix=/Volumes/COMPSPINE/mac/php-5.2.5 --with-apxs2=/Volumes/COMPSPINE/mac/apache-2.0.58/bin/apxs --with-config-file-path=/Volumes/COMPSPINE/mac/php-5.2.5

Com­pile your PHP

make
make install

(I got a warning af­ter 'make')Now we need a php.ini file

cp php.ini-dist php.in

Con­fi­gure Apache2

open -e /Volumes/COMPSPINE/mac/apache-2.0.58/conf/httpd.conf

Look for so­me­thin si­mi­lar like "Load­Mo­dule php5_module modules/" an add the line
Load­Mo­dule php5_module modules/libphp5.soSearch for anything like "Add­Type application/" and add the line
Add­Type application/x-httpd-php .php .phtml
(you can add other file en­dings as well)Now we have to sheet a little bit. Go to http://www.mamp.info/en/index.php and down­load a fresh copy of MAMP (don't take the pro ver­sion). Af­ter moun­ting the .dmg file we go­ing to bor­row just one file:

cp /Volumens/MAMP/MAMP/Library/modules/libphp5.so /Volumes/COMPSPINE/mac/apache-2.0.58/modules/

Af­ter do­ing that you can un­mount and de­lete MAMP

Start Apa­che again:

sudo /Volumes/COMPSPINE/mac/apache-2.0.58/bin/apachectl start

Finaly lets see if PHP is working. The­re­for we need to have a test file.

vi /Volumes/COMPSPINE/data/index.php

An edi­tor cal­led 'vi' ap­pears wi­t­hin the ter­mi­nal win­dos. Even if you don't see anything type:

""

Now press es­cape once and type (again in the com­mand mode of 'vi') ZZ
Vi should clo­ses and you will see all your ter­mi­nal stuff again.

In­stall MySQL

sudo chown -R mysql .
sudo ch­grp -R mysql .
scripts/mysql_install_db --user=mysql
open -e ../bin/mysqlaccess

Re­place the line:
$MYSQL = '/usr/local/mysql/bin/mysql'; # path to mysql
with
$MYSQL = '/Volumes/COMPSPINE/mac/mysql-5.0.45/bin/mysql'; # path to mysql

Safe and close the file.

sudo bash
cd sudo ch­grp -R mysql /Volumes/COMPSPINE/mac/mysql-5.0.45/data
sudo chown -R mysql /Volumes/COMPSPINE/mac/mysql-5.0.45/data
sudo -u mysql -b /Volumes/COMPSPINE/mac/mysql-5.0.45/bin/safe_mysqld
./bin/mysqladmin -u root pass­word root

In­stead of 'pass­word root' you should be crea­tive to chose your own password

sudo ./bin/mysqld --user root --pid-file=/Volumes/COMPSPINE/mac/mysql-5.0.45/data/mysql.pid --basedir=/Volumes/COMPSPINE/mac/mysql-5.0.45 --lower_case_table_names=2

For me this is not teh per­fect way to start the mysql ser­ver but it should work. It would be bet­ter to use a dif­fe­rent --so­cket path then /tmp. That means that we are ac­ces­sing the lo­cal hard disc. The op­tion --socket=/Volumes/COMPSPINE/mac/mysql-5.0.45/tmp/mysql.sock re­sults in the fol­lo­wing error:

071209 17:51:12 In­noDB: Star­ted; log se­quence num­ber 0 43655
071209 17:51:12 [ERROR] Can't start ser­ver : Bind on unix so­cket: In­va­lid ar­gu­ment
071209 17:51:12 [ERROR] Do you al­re­ady have ano­ther mys­qld ser­ver run­ning on so­cket: /Volumes/COMPSPINE/mac/mysql-5.0.45/tmp/mysql.sock ?
071209 17:51:12 [ERROR] Aborting

I have mul­ti­ple mysql ser­vers on my sys­tem but none of them ac­ces­ses that tmp fol­der. Its all­most cau­sed by wrong pri­ve­le­ges but my tmp fol­der is ow­ned by eit­her mysql user and group. Also the bin/mysqld is ow­ned by mysql and his group.

It's of­ten good to know how kill that par­ti­cu­lar pro­cess. Use:

sudo bash && killall mysqld

Any sug­ges­ti­ons to fix that?

Posted by nise | Filed in Tech | 2 Comments »Share this on del.icio.us Digg this! Share this on Facebook Share this on Technorati Tweet This!

Tags: , , , ,


2 Responses to “Portable MAMP (Apache2 + PHP5 +MySQL5)”

  1. Tagallept Says:

    di­vers thanks for the ad­vice spe­ci­fied on a lo­ca­lity. With ques­ti­ons I shall ora­tion to the ad­mi­nis­tra­tor on a soap.

  2. maxson Says:

    hi their are bet­ter ways

    i will soon try to write a tutorial

    you should in­stall mysql from source
    and you should allso in­clude a dow­noad­link to the mysql

    bye

    com­ment

Leave a Comment