El Capitan: Dev Devil!
Did you break my back?
And so last night I upgraded Mac OS X to El Capitan! Reason for the upgrade could be my fascination with Yosemite and El Capitan or I was picturing my self standing in front of El Capitan! Oh gorgeous!
Let's get this straight. If I could I would live in Yosemite forever. Well, it is my dream and I have to work my way towards this amazing dream. But for now I have to bring El Capitan to my development machine: closer to my eyes, yes I am a developer and surprisingly I stare at my screen all day long :-)
So how did it go?
It sure is breath taking! Yeah, but what else? As we all know upgrades always go smooth :-) and never break anything :-) After upgrades business is as usual and everyone is happy, right? Yeah, that is one of my other dreams...but don't worry I am never going to chase that dream! I'd rather bend my back to fix the broken pieces.
After Upgrade
Did you have XCode installed? If so, update XCode from the app store. XCode is a large size upgrade and so have patience young gunz!
XCode upgraded? Now, go and update the Command Line Tools.
Before Upgrade
I was adding new features onto my SaaS product in no time. I was fixing issues in near real time. Life was good. No complaints. I was flowing in the cloud and my users' were joyous. Then came the upgrade and suddenly I noticed my cloud had disappeared and I was falling from the sky :-)
For my SaaS product I am using,
- Apache
- Mongo
- PHP
So, where exactly things went wrong? Let's take it piece by piece.
Where is my localhost?
I was thrilled to see El Capitan on my desktop and so quite enthusiastically I opened up Chrome and ran for the local host....and I received "Page cannot be found". Figured. I found my troubleshooting hat and went to work. Sure enough I am running Apache and therefore first place to look at is the config files. Really? My grandma even knows that. To my surprise, I saw 3 different httpd.conf files.
- httpd.conf
- httpd.conf.pre-update
- httpd.conf~previous
Yes, the upgrade had retained a working copy of my httpd.conf as httpd.conf~previous. Great. Now I can take the retained copy and overwrite the new httpd.conf, right? Not really. One piece of advise, don't overwrite the new config file as it could have new settings and features that you may not be aware of. I read the previous config(s) and modified the new httpd.conf file to meet my requirements. By doing so, I was able to turn on Apache and have the static pages display in the browser.
Next, I tried to log in to my SaaS product....and...nothing happened. Well not exactly...errors happened.
Where is My Driver?
Guess, where do I go next? Apache logs, yep you guessed it right! At the terminal I type,
cd /var/log/apache2
vi product-error_log
I reviewed the error log and saw,
PHP Fatal error: Class 'MongoClient' not found
Of course the driver went missing. Now who was going to drive my buggati? And so I commenced the process of re-instating my driver.
Check PHP version
At the terminal I typed,
php --version
...and I saw
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so, 9): image not found in Unknown on line 0
PHP 5.5.29 (cli) (built: Sep 9 2015 00:26:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
I know it's a nasty error. But we will take care of it in a minute. Have patience kiddo! Next I typed,
php -m
Sure enough I did not see "mongo" in the list of modules.
First error said it had trouble loading mongo.so. Additionally php -m did not show me mongo. And so now I was tempted to check php.ini just to ensure that mongo extension was enabled. I reviewed the php.ini file and confirmed that mongo extension was enabled.
extension=mongo.so
Not sure where the php.ini file is? Then type below at the terminal and you should see the location of this file.
php -i |grep "php.ini"
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Check PEAR & PECL - Not the fruit & pickle
At the terminal I typed,
pear version
PEAR Version: 1.10.1
PHP Version: 5.5.29
Zend Engine Version: 2.5.0
and then tested for pecl.
pecl version
PEAR Version: 1.10.1
PHP Version: 5.5.29
Zend Engine Version: 2.5.0
If you are not able to see pear and php version(s) then please install PEAR and PECL. Why? Because we will be using PECL to install mongo driver. Remember, I am not installing entire MongoDB. Just the driver. In other words, I am not purchasing a new buggati instead just re-instating a compatible driver.
With fruite & pickle in place, I typed,
sudo pecl install mongo
and I saw mongo driver being built at the terminal...all happy....well not exactly. At the end of the build process I see,
/private/tmp/pear/install/mongo/contrib/php-ssl.h:33:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
^
1 error generated.
make: *** [io_stream.lo] Error 1
ERROR: `make' failed
Aaarrggghhhh....life of a developer...there is always something!
El Capitan: Rootless Feature
As you know I upgraded to El Capitan and so along came the Rootless Feature. Say what? Yeah, in other words System Integrity Protection. In few words...
With System Integrity Protection, Apple decided that there are certain things that should never be permitted for 3rd party software. In a way, it is taking OS X one step towards the type of protection we see in iOS: 3rd party software just got somewhat more restricted. That’s also where the term rootless came from — they essentially somewhat restricted the powers of the root account.
To install mongo driver using PECL (3rd party) I learned that I had to disable the rootless feature. In 4 easy steps we will disable this feature. Remember to turn the feature on when the environment is huffin and puffin.
- Restart Mac in a Recovery mode. But how? Well, during the restart as soon as the screen turns black press Command+R and you should see OSX Utilities.
- From the Utilities menu click Terminal.
- Type csrutil disable and press Enter.
- Restart Mac.
And I am rootless now!
With rootless feature disabled, next we need to build a symlink for openssl which comes with XCode.
At the terminal,
cd /usr/include
sudo -ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/usr/include/openssl
And by doing so /usr/include/openssl is now pointing towards XCode.
Next I will attempt to build Mongo Driver using PECL again!
At the terminal,
pecl install mongo
And voila! I meet my driver again! I see the driver build passed successfully.
Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so'
install ok: channel://pecl.php.net/mongo-1.6.11
Dev God Is Back
And yet again...quite enthusiastically I open Chrome and run towards the localhost. I log in and life is colorful again! Business is as usual.
PS:-) Now, don't forget to turn on the rootless feature. Yes,
- Back to recovery mode
- Open terminal and type csrutil enable
- Restart
And I am ready to flow again. I see clouds appearing in the sky and if you ask me then I am ready for a take off!
So why the heck did I write this article?
Upgrade process shouldn't be painful. Well, let me rephrase it. Life after upgrade should not be as painful. I went through the pain and may be wasted a day or so to bring the life back to normalcy. I'd hate to see my fellow developers' going through similar pain and therefore...here to your pleasure I pen down my pain.
Now, don't forget to visit my Saas Product. It's nothing special but it sure is colorful and pretty cool!
Cheers!
Hi, I am Ritesh Patel. I live in a beautiful town surrounded by the mountains. C&O Canal is few miles away. State parks are only a distance away & bike trails galore. It is home sweet home Frederick, MD. A passionate developer. Love to cook. Enjoy playing "Bollywood Tunes" on my harmonica. Apart from that just a normal guy.