Install a Local PHP Manual with MAMP

I sometimes find myself offline and needing to do web development. As I work mostly with php getting access to the PHP manual can be critical. Without being online the only way to do this is to store a local copy.

Now, I had a few problems getting this to work. Little documentation and a fuzzy head were the main causes. Anyway, I got there in the end so here’s what I did. Pre-requisites are that you have a copy of MAMP (non-pro version) installed and have downloaded and unzipped the manual file.

Copy the manual file somewhere sensible in your localhost root folder. I put mine into /Sites/root/phpmanual/ giving the localhost url of http://localhost/root/phpmanual/php-chunked-xhtml/.

Next, work out which php.ini file you’re using. To do this create and open a phpinfo.php file. A phpinfo.php file just needs the following:

<?php
    phpinfo();
?>

Search for php.ini and you’ll see a line in the row with a heading of Loaded Configuration File. You’ll have a url of something like: /Applications/MAMP/conf/php5.3/php.ini. Open this file in TextWrangler and make the edits below. Make sure you make a copy of the php.ini file before doing this or have some way to restore the original version.

  1. Change display_errors to On.
  2. Change html_errors to On.
  3. Add base url to docref_root and uncomment (delete the semi-colon). In my case the base url is /root/phpmanual/php-chunked-xhtml/.
  4. Uncomment error_prepend_string.
  5. Uncomment error_append_string.
Here’s what they look like in the php.ini file. I’ve added line numbers I get. This is using MAMP Version 2.0.5 and PHP 5.3.2.
277 display_errors = On
311 html_errors = On
319 docref_root = "/ROOT/phpmanual/php-chunked-xhtml/"
320 docref_ext = .html
323 error_prepend_string = "<font color=ff0000>"
326 error_append_string = "</font>"

The final thing to do is save the file and then restart your servers. To test it create a basic php file like the one below.

<?php
include ('file.php');
?>

Launch it and you should see this

Warning: include(file.php) [function.include.html]: failed to open stream: No such file or directory in /Users/zoooj/Sites/root/mailout.php on line 2  
Warning: include() [function.include.html]: Failed opening 'file.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Users/zoooj/Sites/root/mailout.php on line 2

Click on the links (in blue) and you’ll be taken to your local copy of the PHP Manual. These links point to my local copy so probably won’t work for you, unless you’ve set it up and used the same location as I have. Simply by regularly updating the manual you can now work offline whenever you want on your php development.

Create MySQL Backup

There are a number of ways to backup a MySQL database. For my local environment I like a quick way to take a backup before trying something new. Rather than go through the cumbersome process of logging into Terminal, navigating to the MAMP /bin directory and then entering a very long command, which I would easily forget, it’s simpler to create a shell script and then invoke it as an Application by using AppleScript.

First, create your shell script by opening a text editor, eg TextWrangler (and not an RTF editor), and type:

#!/bin/bash

On the next line type in the commands you would normally do in Terminal. In my case, I wanted to navigate to the MAMP /bin where mysqldump lives. Then, I wanted to use this to dump a sql file of a specific database within my sites directory.

cd /Applications/MAMP/Library/bin/
./mysqldump -a -uroot -pPASSWORD mydb1 > ../../../../Users/[username]/Sites/Backups/db1.sql;

Finally, close it with

exit

You then save this in a logical place (ie somewhere you can find it!), in my case /Users/[username]/Sites/Backups/scripts/. Next go to Application > Utilities and launch AppeScript Editor. Type the following into the edit pane.

do shell script "/Users/[username]/Sites/Backups/scripts/backup_nsdaukcom_263323_db1.sh"

Save this to either Applications or a sub-directory within Applications. When you change the File Format to Applications before saving.

Once done, all you need to do to take a backup is double-click the new application you’ve created and your previous backup is overwritten with a new one.

Remove System Mail

The other day I was in Terminal when I noticed for the first time it said You’ve got mail. at the top. Knowing I didn’t have any new mail I typed mail to see a whole load of system mail from previous web development work.  I’m no command line expert so I checked on macrumors.com and quickly found out what to do. Here’s the original post.

Go to the directory (=folder) where the system level email files for all users are stored, and list them:

cd /private/var/mail/; ls -l

Display the email(s) for the user which you fill into <username>. Either use your username (without the angle brackets) or use the character * (asterisk) if you want all emails from users listed:

cat <username> | less

Finally erase your mail file, in case you do not need it anymore.

sudo rm /private/var/mail/<username>

Obviously, seeing as you’re deleting mail from your mac make sure you’re certain before doing so. Also, the sudo rm command has no safety net. Once something’s gone it’s gone so if you’re unsure, don’t do it.

Resetting Root Password in MAMP

I struggled for a while to do this as I expected MAMP to automatically update the root password after I’d changed it in the mysql.user table. To be clear, it does not. And so, here’s a brief guide to sorting out you MAMP woes.

First, connect to mysql using Terminal. MAMP is automatically set to use root as the user account to connect to mysql. Funnily enough, root is also the password!

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
You’ll be logged into mysql and will see the following.
Last login: Wed Dec 28 14:48:04 on ttys001
ZoooJs-MacBook-Pro:~ zoooj$ /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 38
Server version: 5.1.44 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
 The next thing to do is reset your password. Type the following replacing your-new-password with your new password. You should see the Query OK message.
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your-new-password');
Query OK, 0 rows affected (0.00 sec)
Once that’s done you need to edit a number of files in the /Applications/MAMP/ directory. I still can’t quite believe that you have to do this in so many places. You’d think they would have a single file that has the master password set. Hey ho, maybe not.
So, find and edit these files using a plain text editor, not TextEdit, Word, OpenOffice, etc. Use TextWrangler or another decent Mac IDE. TextWrangler is free. You’ll need to find the line that has -proot and change it to read -pyour-new-password. Note that there is no space between -p (stands for password) and the password itself.

/Applications/MAMP/bin/phpMyAdmin/config.inc.php
/Applications/MAMP/bin/checkMysql.sh
/Applications/MAMP/bin/quickCheckMysqlUpgrade.sh
/Applications/MAMP/bin/repairMysql.sh
/Applications/MAMP/bin/stopMysql.sh
/Applications/MAMP/bin/upgradeMysql.sh
/Applications/MAMP/bin/MAMP/index.php

Restart MAMP and all should be well.

Need a Website? Read this.

Meeting client expectations is the key to running a successful web development business. How those expectations are set is therefore something the web developer has to consider very carefully. Set them too high and you risk annoying the client. Set them too low and you won’t get the business.

A number of freelancers on freelancers.net have compared quoting for a project akin to buying a car. One in particular wrote:

1) do you want a Ferrari
2) does it need to be 4×4
3) do you want diesel or petrol
4) do you want a maintenance plan
5) do you want extras
6) do you want free MOT
7) do you want continuous improvements (this would equate to a lease hire
where you replace the car for the newer model at the end of each year) 8) do you want free upgrades (top of the range breaks and accessories each time the car is serviced) – £5000 upfront,

Are you a Trader or are you Private Seller or are you an Independent Dealer
or are you an Authorised Dealer.

£125 – £750 per day AND full Professional days. Quote by day and if it
takes you 10 more days than quoted, you can’t ask for extra money. so don’t promise more than you can deliver and agree a continous review to make sure you’re on track.

You need to charge for project initiation (establishing your Business,
Functional and Non-Functional Requirements) this isn’t included in the
Design, Develop and Deploy phases.

Or do you want to go to a trader and buy a car from him in the ASDA parking lot and not know where he comes from, hope the the HPI check is legitimate and hope that he hasn’t thrown saw dust in the gear box as well as 1 or 2 banana skins. £10000 and make sure your buyer can’t find you or review your work and make sure you can’t build a reputation to sell so the same buyer again.

Getting the quote right means treating the project in its entirety. There’s one thing I don’t like about this comparison, though, and that’s likening web developers to car dealers. In my experience, and I use those words carefully, web developers are somewhat more honest. I’m sure there are bad ones around – I’ve obviously been fortunate to meet the honest ones. The same cannot be said for car dealers!!

Creating a Configurable Product

Customers can select options when they see a configurable product, e.g. colour or size. This is useful when you want them to click on a generic product name and then tailor the product to suit their needs.

The first thing you have to do is create any new attributes you require. After specifying the values for these, you then create a new attribute set. Drag the new attributes into a new group called Selectable Options.

Next, you create the configurable product. Select the new attribute set and then select only the options you wish to include for this product. You can see by doing this that you could have one attribute set per configurable product type, or you could have one configurable product for all products in the shop.

After doing this you can assign simple products to the configurable product by clicking on Associated Products and selecting them. If the simple products don’t appear in the list as expected, then it’s most probable you either haven’t set the attribute scope to Global (required for all configurable product attributes) or you have assigned a different attribute set to the product.

Rule #1: Attributes used in configurable products need to have a global scope.
Rule #2: Simple products assigned to configurable products need to be assigned the same attribute set.

Top Menu (Category) Page Links

At some point you might need to add a link to a page on the top menu bar, the menu bar where the category anchor links appear. The steps are as follows.

  1. Create a new category named after the name of the link.
  2. Go to Url Rewrite Management. Select the newly created category and note down the target path. During setup this was catalog/category/view/id/21. Set Redirect to Permanent (301). Then save.
  3. Next click Add URL Rewrite. Select Custom. Type the name of the page link in the ID Path field. Type the target path copied in (b) to Request Path. Type the URL for the page in the Target Path field. This must be different to the name entered in the category to prevent a circular reference. Last, select Permanent (301) in the Redirect list. Then save.

Adding a Language Pack

The default Magento build comes with the en-US language pack. To install a local language pack you can either use Magento Connect or do it manually. As Magento Connect doesn’t always work it’s often simpler and quicker to do it manually.

A good tutorial is here: http://www.geekieblog.com/2011/10/adding-a-new-language-to-magento/ but the basic steps are:

  • Grab the translation files
  • Upload them to the appropriate directories as they appear in the download
  • Change you store view locale
  • Delete the cache
  • Refresh the page

Magento Connect Invalid Server Response

The reason for the following error message being shown during an attempt to install an extension in Magento version 1.5 or 1.6 is that the Magento Connect 2.0 extension key needs to be used.

Invalid server response for http://magento-community

When searching for the extension make sure you select the correct version using the dropdown before agreeing to the terms and conditions.

 

Magento Connect File Permissions

Downloading extensions using the web based Magento Connect manager requires the directories and files to be writable. SSH into the root directory of the Magento installation and execute the following.

find . -type d -exec chmod 777 {} ;

Once complete, reset by issuing the following via SSH when running php as a module.

find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
chmod o+w var var/.htaccess includes includes/config.php app/etc
chmod 550 pear
chmod 550 mage #for magento 1.5+
chmod -R o+w media

Instructions are valid for version 1.5 upwards.

Less secure | More secure