Tag Archives: php

Mac OSX (10.8) Mountain Lion: Fixing Apache, PHP, Subversion, User Sites, Virtual Hosts Directories

While Mountain Lion (OSX 10.8) has brought many enhancements and fixes (mostly performance), it has also caused frustration to old users.

You might have noticed following issues in Mountain Lion:

  1. Web Sharing Preferences Panel has been removed, i.e. you need to launch apache manually or write some launch-agent script or hack to bring web-sharing preferences panel back
  2. User Sites (per-user web directories) is disabled, i.e. http://localhost/~username doesn’t work by default, and you need to modify apache config file to enable it
  3. PHP extension for Apache is disabled by default i.e. you need to enable it by modified apache config (httpd.conf)
  4. Subversion is not installed by default, either you can install using homebrew or by install XCode command line tools

You can fix these issues (1-4) by following these two links:

Whenever I upgrade to newer version of OSX, I end up with broken development-setup i.e. custom permissions on directories are messed up, configuration files are overwritten/removed, etc.

I think, I have found a way to keep default directory permissions, so future upgrades don’t break things.

My development setup requires my virtual hosts to use directories within my home-directory (and outside of ~/Sites or /Library/WebServer/Documents directories).

I am using following technique to setup my virtual-hosts:

  • Enable User Sites  (i.e. fix #2 problem above)
  • Create symbolic-links(symlinks) of your project folder(s) inside ~/Sites directory
  • Enable FollowSymLinks and SymLinksIfOwnerMatch options in virtual-host configuration.

In my case, I have a project inside ~/projects/myproject . I create a symlink of this directory inside ~/Sites, like this using Terminal (command-prompt)

$ ln -s ~/projects/myproject ~/Sites/myproject

I have following virtual-host configuration for this project:

<VirtualHost *:80>
 DocumentRoot "/Users/myusername/Sites/myproject/trunk/web"
 ServerName  myproject
 ServerAdmin myusername@localhost
 Options Indexes MultiViews Includes +FollowSymlinks +SymLinksIfOwnerMatch
 CustomLog "/private/var/log/apache2/myproject_access.log" common
 ErrorLog "/private/var/log/apache2/myproject_error.log"
</VirtualHost>

I use it on my development machine (i.e. my laptop), so I don’t really bother about security at Apache level, and I take care of security at firewall/other levels.

If you are going to use above technique/configuration, please understand everything (by reading documentation) before you use it.

This set up works for me and solves some problems for me – I don’t have to change default directory permissions, and I don’t have to keep my projects within ~/Sites or /Library/WebServer/Documents directory.

CalDAV and SyncML Resources

One of our projects requires a calendar application with bi-directional synchronization with any other calendar applications/services such as Microsoft Outlook, Mozilla Thunderbird, Google Calendar, Yahoo! Calendar, iPhone, Nokia or others.

We can export iCalendar file, that would be readonly i.e. client applications can not write back to source calendar

I started looking at CalDAV, which is an extension to WebDAV, and SyncML, which is gaining traction because most of the mobile devices use it for synchronization of data. I yet to find where CalDAV fits when it comes to mobile devices.

I found out some interesting links, which I am still going through. I thought, it would be nice to share these links:

Mac OSX: Leopard to Snow Leopard Upgrade

Snow Leopard Installer DVD was delivered in our office on Saturday and I couldn’t wait to upgrade to Snow Leopard (10.6.x). I could have upgraded earlier, if Apple had enough stores and better reseller network in India.

Anyway, upgrade was smoother  compared with Tiger(10.4.x) to Leopard (10.5.x) upgrade. Installer UI has around 4-5 steps and none of steps mention “upgrade” word. Installer is smart enough to detect existing installations, figure out which printer drivers to keep or install. However, it chooses all languages (translation) to install even when you didn’t have those in Leopard.

Within fourty mintues, upgrade was completed and I was back in action.

However, In my case, I have to spend some more time to setup/fix things which were broken, such as:-

  1. Reinstalled MacPort using installer for snow-leopard and upgraded some of packages (libiconv, jpeg, libpng, libmycrypt, openssl, gettext, freetype, openssl, curl) and their dependencies for 64bit compatibilities (+universal, +variants)
  2. Compiled Apache, MySQL and PHP for 64 bit
  3. Reinstalled Remote Desktop Connection using latest installer to fix crash issue on Snow Leopard

If you don’t want to use MacPorts, you can download source of these libraries separately, compile and install. These would be installed in /usr/local unless you change the prefix.

Installing 64 bit version of Apache, MySQL and PHP took around two-three hours because of some issues related to libiconv.2.dylib. Apache would compile but fail to run, reporting incorrect version of libiconv. I downloaded libiconv source, compiled and installed it in /usr/lib (instead of /usr/local/lib). Apache started working but  vim, make, other unix programs (chmod, etc) failed to run using latest libiconv.2.dylib.

I tweaked the setting in /usr/sbin/envvars to use following:-

DYLD_LIBRARY_PATH="/usr/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib:/opt/local/lib:/sw/lib

Basically, added a fallback path so if library is not found in /usr/lib, it would look into other directors, as specified.  After doing this, Apache (64bit) and vim, make, chmod, etc started working.

MySQL compilation was straight forward with following command, thanks to this link, I just added CFLAGS=”-arch x86_64″  while compiling to make sure mysql is compiled for 64 bit. Moved data directory back to new mysql installation directory.

Compiling php 5.2.13 resulted into some errors related to iconv, hash and gd. After spending sometime, I decided to compile without these extensions with following commands:

MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch x86_64 -g -Os -pipe"
LDFLAGS="-arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
./configure --prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --disable-dependency-tracking --sysconfdir=/private/etc --with-apxs2=/usr/sbin/apxs --enable-cli --with-config-file-path=/etc --with-libxml-dir=/usr --with-openssl=/usr --with-kerberos=/usr --with-zlib=/usr --enable-bcmath --with-bz2=/usr --enable-calendar --with-curl=/usr --enable-exif --enable-ftp --without-gd --with-jpeg-dir=/opt/local/lib --with-png-dir=/usr/local/lib --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6 --with-ldap=/usr --with-ldap-sasl=/usr --enable-mbstring --enable-mbregex --with-mysql=mysqlnd --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-iodbc=/usr --enable-shmop --with-snmp=/usr --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --without-xmlrpc --without-iconv --with-xsl=/usr

#if everything goes well
make

#if everything goes above, install php5 in /usr/local/php5
sudo make install

I checked (php -m) some extensions (xdebug, etc) were not loading, so I updated those individually, specially iconv, xmlrpc and gd. Compiling an extension is generally four step process. For example, if you want to compile iconv, you can do the following:

$ cd /php-source/ext/iconv
$ phpize
$ ./configure --with-iconv=/usr
$ make
$ sudo make install

It all worked fine, apache was loading php fine and all my websites and applications work fine.

Flex Compiler Modules

In one of my projects, I was trying to use Flex Compiler Module for Apache. I was doing development on my Mac OSX and everything worked fine. As soon as, I uploaded application on server (CentOS 4.5, x86_64), it didn’t work.

After some debugging, I figured out Flex Compiler Module binaries are compiled as 32bit would not work on 64bit version of Apache. I could have used some third-party wrappers or rebuild it again for 64bit, unfortunately Adobe has not provided source-code for these modules.

There was another problem, it seems this apache-module has dependency on glibc, the required version of glibc is not available for RedHat/CentOS 4.5. Now that’s weird, even if I had source code, not sure I could build against 64bit of CentOS? Not even sure about CentOS 4.5 x86?

BTW! glibc seems to be an important library and one can not just go ahead and update for one requirement, it might actually break many other applications. Hence, I didn’t upgrade glibc on CentOS 4.5 to the required version.

So as an alternative, I used Flex Compiler API by writing some wrappers in Java and then invoke API using PHP. But it seems there is weird licensing i.e. I need to have license of Adobe LCDs in order to use Flex Compiler API?

I have fallen back on pure PHP implementation, I need to figure out about custom logging.

PHP Proxy Script for cross-domain requests

I wrote this php-proxy-script and have been using for different purpose (loading cross-domain data like text, xml, swf, image, etc. or for YouTube REST API  in flash, flex applications).

Often people keep asking about proxy-scripts in forums, now they can download the code and use :)

Download the proxy.php.txt

Usage:-

http://yourserver.com/proxy.php?url=<url_encoded_desitnation_url>[&mimeType=<mimeType>]

Examples:-

To load XML/Text:

http://yourserver.com/proxy.php?url=http%3A//abdulqabiz.com/blog/index.xml

To load a SWF (binary-data):

http://yourserver.com/proxy.php?url=http%3A//abdulqabiz.com/files/some.swf&mimeType=application/x-shockwave-flash

Technorati tags: , ,