The Dev Pages

A knowledge base for simple (and beyond) web applications development

Archive for the ‘General Dev’ Category

PHP and MySQL setup on Mac OS X 10.5 Leopard


Posted on September - 10 - 2009



Full fledged open-source MAMP development environment with php, mysql, and apache on Mac OS X 10.5 Leopard

Goal: A complete php development environment using Mac OS X 10.5 Leopard’s out of the box apache2/php install, and an install of the latest mysql and eclipse software with all the necessary plugins for php debugging. ALL 64-BIT!

Admittedly, it was a challenge to get a fully functioning php dev environment up based on Mac OS X 10.5 Leopard’s configuration. But I succeeded in not installing a separate apache/php 32-bit install, or bailing out to use a linux Virtual Box.

Enabling PHP

PHP5

This one was pretty easy. Just uncomment out the line

#LoadModule php5_module        libexec/apache2/libphp5.so

in the httpd.conf apache config (/etc/apache2/httpd.conf) so it includes the php5 module that comes with the OS.

Make sure your extension_dir in php.ini points to /usr/lib/php5/extensions/no-debug-non-zts-20060613/ or go nuts and do your own extension directory.

Debugging 64-bit

This was one of the trickier things. You need to get an X-Debug extension setup. Hopefully you can just use my 64-bit extension file, and put that in your extensions directory (/usr/lib/php5/extensions/no-debug-non-zts-20060613/). Then add the zend_extension directive to the php.ini, along with the X-Debug settings, pointing to your (local or remote) host. In your php.ini:

(left bracket)xdebug(right bracket)
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=true
xdebug.remote_host=natest.crimereports.com  ; if debugging on remote server, put client IP here
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

xbedug.so (specific to 64-bit Mac OS X)

If that short version doesn’t work, you need to compile a 64-bit extension from the xdebug source, which was sort of tricky. You’ll need to get a compiler installed on your Mac OS if you haven’t got the right developer tools installed (XCode from the install disk or mac;s website), and then follow the instructions in this article.

http://www.vividreflection.com/blog/installing-xdebug-on-macosx/
http://www.designified.com/blog/article/60/compiling-installing-xdebug-for-php-525-entropych-build-on-os-x-105

Installing MySQL

Use the installer from MySQL’s site, and it goes pretty seamlessly. You may have to edit the php.ini to use the mysql server.

The tricky part of this is if you use a framework, or your code uses the pdo database interface. Again, you can try my 64-bit version, or compile your own pdo_mysql extension. Enable the extension in the php.ini by addin gthe line extension=pdo_mysql.so

pdo_mysql.so (specific to 64-bit Mac OS X)

http://www.hoboes.com/Mimsy/hacks/adding-pdo-mysql-mac-os-x-leopard-server/
http://www.spiration.co.uk/post/1332/install%20PDO_MYSQL%20-%20mysql_config%20and%20header%20files%20problem

Eclipse

So there is a Cacao version that is 64-bit. I guess the difference here, as I’ve read online, is that the Carbon version is more stable, but also legacy and in the future will be deprecated soon.

I love using the update site to get plugins. That seemed to work best for PDT php, aptana, SVN (subclipse), and various editors, etc.

Flex

I sort of copped-out here when I learned the 64-bit version of eclipse doesn’t work well with Flex-Builder as an Eclipse plugin. I’m planning on installing the stand-alone version of flex builder, and using that separately (a little but resource wasteful, but far more convenient).




I absolutely hate the new project dialog in eclipse. It seems like each plugin (PHP, Flex, Aptana, SVN, etc.) has its own way of doing a new project.

Here’s one reason I hate these dialogs – If I want to add a new project into my workspace, I can’t put the files there first and then make it a project. Why would I want to do this? 1)I want to clone a git project from a remote repository into my workspace. Right now there is no way to do this with an add project dialog. So the files get to my workspace, but they don’t show up as a project. Same goes for SVN stuff where I want to re-add the files as a new project without having to check the whole stinking repository out again. Plus, it would be nice if I wanted to add files first, then make projects. Is that so hard? I understand eclipse doesn’t want to muck around in a folder with no project data to make a new project, but really, is it so hard to make a non-project folder a project folder? And if eclipse isn’t meant to do this, GET RID OF THE ‘Create project from existing source’ option because it doesn’t work with many project types.

So here is a way I found that works swimmingly. I wonder if this came as an option with a plugin. If so, I am using PDT php, Aptana, Subclipse, and I think those are the main ones. If you don’t get this option in your menu, than who knows what plugin you may need. I’m just glad I got it to work for me.

SOLUTION: Screw the new project dialog. Do File->import then select the folder ‘Other’->Existing Folder as New Project. This works great for my goal of 1)having files in my workspace that are not a project in eclipse and then making that folder and all its files a new project.




When doing a push to master I was getting

bash: git-upload-pack: command not found
bash: git-receive-pack: command not found

For me my server was not recognizing the git command. I had to add the server paths to my local git config

receivepack = /home3/<myusername>/local/git-1.6.4/git-receive-pack
uploadpack = /home3/<myusername>/local/git-1.6.4/git-upload-pack

where the config file is in the .git directory of my project on local. This line is under the entry for the remote I had set up called ‘origin’ (use the path on the server where the git install is located and make sure git-receive-pack is in there on the server).

BUT,I think the following is be the better solution. Editing the .bashrc worked like a charm. I added the following line to my .bashrc file (look in /etc or you home/ directory if on a shared server) and things worked swimmingly.

export PATH=”$PATH:/home3/<myusername>/local/git-1.6.4″

replace /home3/… with whatever the path to your git install may be.

I’m still not clear on why the path would be different for a bash ssh command, and a client sending a request over ssh to the server. It seems as if even though my server environment variable $PATH includes the path to the git install, the $PATH variables does not include that path if the git commands are invoked over a remote ssh request (like my eclipse working with git). But if I was logged in on a bash shell, the git commands worked great, with no ‘command not found’ errors. Make sure when you install git, that you understand how to make your server recognize the git executable commands, both from the bash and also from remote requests. I’m still unclear on the difference between 1) editing the $PATH environment variable to include your git directory 2) Editing the .bashrc with the export $PATH setting. 3) Making symbolic links from the bin folder to your git install.

See http://stackoverflow.com/questions/225291/git-upload-pack-command-not-found-how-to-fix-this-correctly

make[2]: execvp: Permission denied


Posted on August - 30 - 2009



make[2]: execvp: true: Permission denied

You need to do chmod 755 true on the true script on your bin, For me I had followed the instructions at:

http://blogs.koolwal.net/2009/07/20/howto-installing-git-on-bluehost-domain-hosted-websites/

for installing git on bluehost. I had to make a script called ‘true’, and put it in my local bin to get git to compile.

make[2]: execvp: <YOUR FILE HERE>: Permission denied

These errors mean that your script does not have execute rights. You can ‘chmod 755 <YOUR FILE>’ and it should work.




Getting an HTTP_Request class was pissing me off. So it seems like you can’t install PECL classes on your php install because of rights issues on a shared hosting environment.

BUT, you can get PEAR classes installed through the cPanel, using the PHP PEAR Packages link. I was adding the HTTP_Request package (HTTP_Request2 won’t install because there is no stable release as of yet).

But even after the install, the classes could not be found. Like when I did require_once(’HTTP/Request.php’) I was getting the classic not found warning and error:

Warning: include(HTTP/Request.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening ‘HTTP/Request.php’ for inclusion
Fatal error: Class ‘HTTP_Request’ not found

You have to edit the php.ini (or ini_set the include_path ) to include :/home/yourusername/php, or in my case the home directory is now home3 for some reason, with some weird aliasing allowing for home I think. The PEAR packages install to /home/yourusername/php, so this needs to be added to the include path.

If you still get:
PHP Fatal error:  main(): Failed opening required ‘PEAR.php’
Then your include_path may be missing :/usr/lib/php, this is the main (not your local user) php lib folder that, I think, has the main PEAR files (The ones that your local PEAR package installs like HTTP_Request will be calling). So when you install a PEAR package via the cPanel, it puts them in /home/yourusername/php, and those files will need to know about the main PEAR install in /usr/lib/php by having /usr/lib/php in the include path.




private function XMLtoHTMLEntities($string){
//get rid of any XML entity encoding that may have been applied (like in an RSS feed)
$unXMLEntify = str_replace ( array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), ->
array ( '&', '"', "'", '<', '>') , $string );
return htmlentities($unXMLEntify);
}

phpunit: command not found


Posted on August - 4 - 2009



phpunit: command not found

Your phpunit file needs execute access and has to be in a ‘bin’ folder (/usr/bin or usr/local/bin)

How to install the pdo myql drivers for php


Posted on August - 3 - 2009



First install pdo.

I already had php 5 with the pdo extension included in the build. But I needed the mysql driver for the php extension since it only came with 2 (sqlLite, sqlLite2).

To add the mysql driver for pdo in your php install, put (pdo_mysql.so – you’ll have to compile this) in your extensions directory and then enable that extension in php.ini. WTF, pretty simple but there are no web pages with instructions. And compiling in Mac OS X sucks because you need to install extra Developer tools and than run the command line compile commands.

http://pecl.php.net/package/PDO_MYSQL




-When you setup additional folders outside of the ‘Sites’ folder to serve files, they cannot be in a directory path where in higher up directory has restricted rights (you can’t serve files from anywhere in the ‘Documents’ folder).

-If you add a virtual host, make sure the home directory/ doc root has a corresponding directory entry. So the <VirtualHost>’s docroot needs to have a <Directory> to make it so the default apache settings for directories don’t deny the server access.

-When you uncomment the link to the virtual hosts file, make a vhost for localhost too.

-When you specify an error log output file for php, chmod it to be globally writable (so php can write to it).

-Eclipse in Mac OS X is funky (Ganymede) with the pdt plugin.

-The debugger module does not work for php unless you compile a 64-bit version of xdebug, which didn’t work easily.

-the zend_path or whatever sucks! This needs to point to the xdebug.so, this was not documented anywhere for mac os x. You have to move it to the weird extensions folder in usr/lib/php or edit the extension_dir, after you have compiled and put the xdebug.so in that location.

-The extension_dir should not be ‘./’, which just means current folder, but should point to ‘usr/lib/php/extensions’ or something (by mem, update later)

-Updating the mysql values in php.ini is pretty straight forward.

Cruise Control and/or ANT out of memory error


Posted on February - 4 - 2009



When setting up a flex app auto build task, I started getting the following error consistently.

Error: null
java.lang.OutOfMemoryError

THE FIX, for me was: Add to ant.bat, antRun.bat

set ANT_OPTS=-Xmx512m
set ANT_OPTS=-Xms64m -Xmx512m

First I tried changing the Cruise Control memory settings in cruisecontrol.bat (CC_OPTS=-Xms256m -Xmx768m -Xmn256m).But I think it was less likely for the cruise control process to have memory issues than the ant tasks I was using (as Jeffrey pointed out before I could clean this up a bit – thanks).

I was noticing that the java.exe service that was handling the process would go up to 100 MB of memory usage, and then stop there, and then tank. The following article points out how to change the ant task memory settings. Because of the way cruise control was calling the ant task, it made it necessary to modify the the .bat files in the ant folder (You can use the <ant><jvmarg>… tag, as per the links below, in some cases). Once the .bat’s had the ANT_OPTS memory settings in place, the process would use more memory and build the flex app. Nice.

Check out the following articles:

http://confluence.public.thoughtworks.org/display/CC/OutOfMemoryError

http://cruisecontrol.sourceforge.net/main/configxml.html#ant