Each time an upgrade to OS X comes along, I end up have to go through a whole mess of updating Perl modules. Why? I made the mistake of writing a utility in Perl that relies on several CPAN modules, including Curses, Curses::UI, Mac::iTunes::Library, and File::HomeDir. At the time I wanted to learn to use Curses. I should remake this utility in something else, but when Perl is working the utility works like I need it to. The utility allows me to sync playlists from my iTunes library to SD cards, without the chore of manually moving them around.
After an upgrade, I usually end up with several errors like this:
Can't locate Curses.pm in @INC (you may need to install the Curses module) (@INC contains: /Users/xxxxx/Library/Perl /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/xxxxx/Library/Perl/Curses/UI/Common.pm line 20.
Tired of seeing this, I removed the dependency for “File::HomeDir” with a minor change to my MediaSync perl source code. That still leaves the problem of the other modules.
I described in an earlier post how to install CPAN modules in OS X. Since this method uses sudo, I’ll use it only to install the Curses module.
Now I am going to setup a module library that is independent of the Perl version, and not going to become broken when OS X is upgraded.
- Create a directory to hold the Perl modules. I chose “~/Library/Perl”, which is in my users Library. Open the Library folder, and create a new sub folder called Perl.
- Copy your other CPAN modules to the new “~/Library/Perl” folder. If the module has a directory structure to it, copy it intact. For example, the two modules I need are Curses::UI, and Mac::iTunes::Library. You can see I moved the entire directory structure over intact.
- Next, Perl needs to be able to find the custom location of my module library. The @INC path needs to get updated. To do this, you need to export the path you want to add from your bash shell’s profile (~/.bash_profile). Add the following line:
- With the above line added, each time the shell is invoked Perl will add the defined path to @INC when started.
Now the my module library is independent of the installed Perl version, and won’t get wiped out by an OS update. You might ask why I didn’t include the Curses module. My response is that the OS Curses library may be updated with an OS update, and I want the Perl module to be rebuilt so it reflects any new or removed functions in the base OS library.
And MediaSync is running again:
This post has been a draft for a long time, it’s time to publish it! It explains how to setup a Synology DiskStation NAS running DSM (Disk Station Manager) to serve web pages (including PHP) and provide SQL services (via MySQL). Your NAS can still sleep properly with this setup while giving you the benefit of running a LAMP stack. The average user won’t need this. If you know what PHP, SQL, and LAMP are then you might be interested.
I needed this to host an application I wrote in PHP that uses MySQL on the backend to store data. When I maintained an externally hosted web site it was running there. I rely on the application but no longer wanted to maintain the external web site, so this solution came about. Purely for reference, my application is for vehicle service history.
- First you need to login to the DSM interface as the root/admin user.
- Next enable PHP by navigating to Control Panel / Web Services / PHP Settings. You’ll want to enable the PHP cache and safe mode options. Click “Apply” to turn it on:
- Next click “Select PHP extension”. You will need to turn on at least the “mysql”, “mysqli”, “pdo_mysql”, and “dba” extensions. I used a few others; “get text” and “mcrypt”. Click OK when done:
- Next enable the web server and MySQL server by navigating to Control Panel / Web Services / Web Applications. Unless you closed the window, you should be able to just select the “Web Applications” tab. Check the “Enable Web Station” and “Enable MySQL” options, then click “Apply” to turn them on:
- Before closing the window click on the “Virtual Host” button under “Enable Web Station”. This is where you will define a URL name and sub-folder to store the application. In my case I stored it in a folder called “servicehistory” and gave it a URL name of “servicehistory.home”. The name given must be resolvable on your network. If you are using DD-WRT router firmware, you can enable local DNS as I described in this post. Click OK when done:
- Now the web and database service is available. You need to install the database management package (phpMyAdmin). Open Package Center from the Application Panel:
- Click “Utilities”, find “phpMyAdmin”, click the “Install” button. You may also need to install “Perl” if your application needs it:
- Next you need to make sure the packages are running. Click “Installed”, find the package, click “Run”. Close the Package Manager when done.
- Next you need to login to phpMyAdmin and set the root password. From the Application Panel, select “phpMyAdmin”. Login as “root”. There is no password initially.
- Click “Change Password”. Enter a new password, re-enter the new password, and click “OK”.
- Now you can create databases and tables as you see fit. Close phpMyAdmin when you are done:
- All that is left is to populate your application into the web server directory as specified in the Virtual Host definition (in my case “servicehistory”). You can use SCP if you have SSH enabled, or the Synology File Manager. Include any and all folders and files your application needs:
- Now you should be able to access your application from the Synology NAS web server by entering the URL you set in the Virtual Host setting into your browser (in my case “servicehistory.home”):
That’s it! You can also serve multiple applications by creating multiple virtual hosts and placing those applications in the proper directories.
Mac OSX comes pre-installed with Perl. This is how you install CPAN modules into the bundled Perl. Don’t know what Perl or CPAN is? This article isn’t for you. 😛
It needs to be done as root, so use sudo.
- Open Terminal.
- Launch the CPAN shell and enter the password when requested:
sudo perl -MCPAN -e "shell"
- Download the CPAN library you want to install (example is Mac::iTunes::Library):
Now you can include the module in your Perl application as so: