Browsing articles in "Mac"

VirtualBox Guest Additions with Shared Folders on Mac OS X

In order to access certain aspects of a virtual machine in VirtualBox, you will need to install Guest Additions (similar to VMWare Tools I guess)

There is a manual page for installing Guest Additions but not all of it is self-explanatory…

Install DKMS

This part is relatively straightforward.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install dkms

Where to find VBoxGuestAdditions.iso

Usefully Oracle don’t tell you in their guide, but it is available with the rest of the downloads at http://download.virtualbox.org/virtualbox/

So for example for version 4.1.6 the VBoxGuestAdditions_4.1.6.iso is located at http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso

How to mount the image

Since I can’t remember the last time I had to mount something in *nix from the command-line, here’s a quick way.

sudo mkdir /dev/dvd
sudo mount /dev/dvd1 /mnt/dvd/
cd /mnt/dvd

Then you should see VBoxLinuxAdditions, which you need to run as per the manual. If the above doesn’t work it might be because your DVD drive in VirtualBox is called something else, like dvd (instead of dvd1) which probably differs depending on which distro you’re using.

Then you need to run the installer.

sudo sh ./VBoxLinuxAdditions.run

Once that’s done you can restart.

sudo reboot now

Kernel header problems

I got some missing kernel header problems when trying to install Guest Additions, which if building the main Guest Additions module fails will be logged.

cat /var/log/vboxadd-install.log

If you see something like this…

Error! Your kernel headers for kernel 2.6.35-28-generic cannot be found at
/lib/modules/2.6.35-28-generic/build or 
/lib/modules/2.6.35-28-generic/source.
You can use the --kernelsourcedir option to tell DKMS where it's located,
or you could install the linux-headers-2.6.35-28-generic package.

So you can do just that!

sudo apt-get install linux-headers-2.6.35-28-generic
sudo ./VBoxLinuxAdditions.run

Hopefully this should install now (although the XFree86 bit will fail, assuming you’re using the command-line) and you may need to restart the VM, although I’m not sure.

Mount the host folder

You can create the host folder in the VirtualBox Manager in the Shared Folders tab on the Settings for that VM. If you add it on the command-line it’ll appear under the machine folders anyways. If you want to type it though, here’s what you’d type into the Mac OS X terminal (note this is the only thing that you’d type into the host itself)

VBoxManage sharedfolder add "my-ubuntu-vm" \
--name "websites" --hostpath "/Users/andrew/pizza"

To mount the Shared Folder from within the guest, the instructions from Ubuntu (as my guest is Ubuntu, although I think this is a better way to mount it anyways) were very useful.

sharename="whatever.you.want.to.call.it";
sudo mkdir /mnt/$sharename \
sudo chmod 777 /mnt/$sharename \
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename \
ln -s /mnt/$sharename $HOME/Desktop/$sharename

Just change the target to be wherever you want the Shared Folder to be mounted in the guest. Now in theory if you go to that path in the guest, it should be the same as the directory you shared from the host!

Zend Server lighttp not running (phpMyAdmin) but Apache is? How to start it manually

If for some reason you’ve powered on and while Apache seems to be running OK, lighttp isn’t (for example phpMyAdmin isn’t working on localhost:10081/phpmyadmin) then you will need to start it manually. This is probably caused by a dirty restart, such as a power failure. On Mac OS X run this command…

sudo /usr/local/zend/bin/lighttpdctl.sh start

For Windows, I’m afraid I will have to find that out!

Samba share path incorrect even though it’s mounted in the Finder

Sometimes if a Samba share (Windows share or a Samba share from Unix) does not disconnect cleanly in Mac OS X, you may end up with a broken symlink in /Volumes/

This means that even if you re-mount the same share, and it will be named the same in the Finder, the actual symlink path won’t be the same. For example if you’re using a Workspace in Eclipse that points to that share, you won’t be able to use it because /Volumes/ will look like this:

Andrew:Volumes andrew$ pwd
/Volumes
Andrew:Volumes andrew$ ls
Macintosh HD    share    share-1

The old symlink will still be there, and it will create another one with a number appended. If this does happen, disconnect the Samba share from the Finder, then delete the remaining share from /Volumes/ and then re-mount it in the Finder.

The share should then mount with the correct path!

 

Configuring Zend Server CE on Mac OS X

Unlike Windows which doesn’t come with Apache by default, or distributions of Linux which (usually) have their own package management systems, Mac OS X comes with an outdated version of Apache which isn’t handled by package management. This means it’s a pain to either update or remove it. Any Mac PHP developer will probably have tried MAMP which gives you a relatively pain-free installation, but for anything complex it can be a bit tricky due to the way it’s self-contained. As a Zend Framework developer I use Zend Server and Zend Server CE at work now and figured now that I’ve got to do some work at home I should look to get it installed and configured…

Just to check that everything is working OK to start with, go to http://localhost/ and you should see the default Mac OS X homepage which will be located in your Sites directory.

Installation

Download Zend Server CE from Zend and install as usual.

Configuration

Disable the default Apache installation

apachectl stop

Replace the default apachectl with Zend Server’s apachectl

Easiest way to do this (without uninstalling anything) is to replace the default apachectl with Zend Server’s apachectl, that way it will just appear to be launching Apache as per usual when OS X starts up.

Firstly move apachectl to a safe place, such as your home directory:

cd /usr/sbin/
sudo mv apachectl /Users/yourusername/

Then create a symbolic link to Zend Server’s apachectl:

sudo ln -s /usr/local/zend/apache2/bin/apachectl ./ 

Start Zend Server’s Apache:

sudo apachectl start

You should then see:

/usr/sbin/apachectl start [OK]

This will indicate that you are running Zend Server’s Apache as opposed to Mac OS X’s Apache (as the latter doesn’t output to the terminal when you start/stop it) although if you go to http://localhost/ you will notice that you will get a 404.

Configure Apache to use port 80

I’m assuming to avoid any conflict with the default Apache installation that Zend Studio’s Apache comes preconfigured to use port 10088. To change this simply edit the configuration:

sudo vi /usr/local/zend/apache2/conf/httpd.conf

… or if you dont use Vi, use another text editor such as Nano:

sudo nano /usr/local/zend/apache2/conf/httpd.conf

Look for the line Listen 10088, then either comment it out and add a new line or edit the port to be port 80.

#Listen 10088
Listen 80

You may also need to change the DocumentRoot and first Directory parameters to your webroot (/Users/username/Sites for example)

Save httpd.conf (Ctrl + x in Nano to exit then y to save) and restart Apache:

sudo apachectl restart

If you go to http://localhost/ in your browser you should now see the default Mac OS X homepage, as httpd.conf should already be setup to point to your Sites directory by default.

If you get any complaints about the FQDN when you start Apache, such as:

httpd: Could not reliably determine the server's fully qualified domain name, using iMac.local for ServerName

Then you need to explicitely set the name of the domain to be used (in this case, localhost)

#ServerName www.example.com:10088
ServerName localhost:80

Configure Zend Framework

sudo ln -s /usr/local/zend/share/ZendFramework/bin/zf.sh ./zf

Configure Pear

sudo ln -s /usr/local/zend/bin/pear ./
sudo pear upgrade pear

Configure MySQL

You can create symbolic links for the typical MySQL commands if you wish (although you can change the include paths for the shell if you so desire)

sudo ln -s /usr/local/zend/mysql/bin/mysql ./
sudo ln -s /usr/local/zend/mysql/bin/mysqladmin ./
sudo vi /usr/local/zend/mysql/data/my.cnf
#socket = /usr/local/zend/mysql/tmp/mysql.sock
socket = /tmp/mysql.sock

Configure phpMyAdmin

If you change the web root for Apache, you will have to create a Directory entry and Alias for phpMyAdmin, since it exists somewhere else:

sudo vi /usr/local/zend/apache2/conf/httpd.conf

Alias /phpMyAdmin /usr/local/zend/share/phpmyadmin

<Directory "/usr/local/zend/share/phpmyadmin">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Install PHPUnit

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
sudo pear update-channels
sudo pear install --alldeps phpunit/PHPUnit
sudo ln -s /usr/local/zend/bin/phpunit ./
sudo pear install --alldeps phpunit/PHPUnit

Mac OS X Apache not starting properly

Whilst trying to figure out why Zend Server CE wasn’t working properly on my Mac (again…) I realised that something was wrong with the version of Apache shipped with OS X. Luckily Chris Oliver found the problem in the Apache control script.

http://excid3.com/blog/2010/12/usrsbinapachectl-line-82-ulimit-open-files-cannot-modify-limit-invalid-argument/

It’d be nice if web stacks were as simple as on Linux (or even Windows) but you can but dream…