Ramblings on technology with a dash of social commentary
RSS icon Email icon Home icon
  • How to install PHP 5.4 or PHP 5.3 on Mac OS X Yosemite

    Posted on December 14th, 2014 PHP Guru No comments

    Yosemite comes with Apache 2.4 & PHP 5.5 preinstalled. You don’t need MAMP, only MySQL or MariaDB.

    Regardless, you can use PHP 5.5, PHP 5.4 or PHP 5.3 as needed. Try the following…

    sudo mv /usr/local/bin/php /usr/local/bin/php55
     sudo mv /usr/bin/php /usr/bin/php55

    Install PHP 5.4

    brew install php54 php54-mcrypt php54-mysql

    Install PHP 5.3

    brew unlink php54
     brew install php53 php53-mcrypt php53-mysql

    Switch to PHP 5.4

    brew unlink php53
     brew link php54

    Switch to PHP 5.5

    brew unlink php54
     brew unlink php53
     sudo ln -s /usr/local/bin/php55 /usr/local/bin/php
     sudo ln -s /usr/bin/php55 /usr/bin/php

    https://gist.github.com/irazasyed/5987693

  • How to start MySQL on Mac OS X

    Posted on December 14th, 2014 PHP Guru No comments

    Observe:

    macpro:~ me$ mysql.server start
    Starting MySQL
    . ERROR!

    macpro:~ me$ sudo mysql.server start
    Password:
    Starting MySQL
    . SUCCESS!

  • Extending Apple Apache & PHP with Homebrew

    Posted on November 18th, 2014 PHP Guru No comments

    Quick start

    I recently got a new Macbook Pro (Mavericks) and decided to use the bundled Apache 2.2.6 and PHP 5.4.30.

    All you have to do is uncomment the PHP extension:

    LoadModule php5_module libexec/apache2/libphp5.so

    in /private/etc/apache2/httpd.conf and start Apache:

    sudo apachectl start

    This had me up and running in no time, but after a few days I realized I needed some additional extensions, including MySQL, Mcrypt, Mongo and Redis.

    Brew to the rescue

    There’s no better package manager for Mac OS X than Homebrew (except possibly Macports). So after installing Homebrew:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    I set off to install some additional software and PHP-native extensions:

    brew install redis
    ...
    redis-server start
    brew install php54-redis
    ==> Installing php54-redis from homebrew/homebrew-php
    ==> Downloading https://github.com/nicolasff/phpredis/archive/2.2.5.tar.gz
    ######################################################################## 100.0%
    ==> PHP_AUTOCONF="/usr/local/opt/autoconf/bin/autoconf" PHP_AUTOHEADER="/usr/local/opt/autoconf/bin/autoheader" /usr/local/Cellar/php54
    ==> ./configure --prefix=/usr/local/Cellar/php54-redis/2.2.5 --with-php-config=/usr/local/Cellar/php54/5.4.33/bin/php-config
    ==> make
    ==> Caveats
    To finish installing redis for PHP 5.4:
    * /usr/local/etc/php/5.4/conf.d/ext-redis.ini was created,
    do not forget to remove it upon extension removal.
    * Validate installation via one of the following methods:
    *
    * Using PHP from a webserver:
    * - Restart your webserver.
    * - Write a PHP page that calls "phpinfo();"
    * - Load it in a browser and look for the info on the redis module.
    * - If you see it, you have been successful!
    *
    * Using PHP from the command line:
    * - Run "php -i" (command-line "phpinfo()")
    * - Look for the info on the redis module.
    * - If you see it, you have been successful!
    ==> Summary
    (beer) /usr/local/Cellar/php54-redis/2.2.5: 3 files, 216K, built in 9 seconds

    Okay, now I should be able to use Redis commands (PHPRedis) in PHP, right?

    Wrong! Whoops:

    sudo apachectl restart

    How about now?

    Nope!

    php -i | grep redis

    Nope, phpinfo() doesn’t show it.

    php -m | grep redis

    Nada; no Redis extension. Rat’s why didn’t that work?

    Solution

    Let’s look back at the output from the brew php54-redis installer. This part in particular:

    * /usr/local/etc/php/5.4/conf.d/ext-redis.ini was created,
    

    So, what gives? That seems pretty legit. At least for an Apache & PHP config installed by Homebrew.

    Oh, right, we didn’t do that.

    Here’s the problem: That’s not where Apple’s default PHP build is configured to load extra parsed ini files from.

    That path, by default, is:

    /Library/Server/Web/Config/php/

    To make the situation even more confusing, that path doesn’t even exist! And, it doesn’t even exist in any config file! It’s actually supplied as an argument (by someone at Apple who worked on the Mac OS X Mavericks Rom supplied to the Macbook Pro factory) when building the PHP binary:

    Configure Command => ... '--with-config-file-scan-dir=/Library/Server/Web/Config/php' ...

    which means we can’t even alter it without re-compiling PHP. Not that we couldn’t, but we don’t need to. Here’s why…

    Symlinks for fun and profit

    All we need to do is get the ini files created by homebrew installers to be loaded by the built-in Apache/PHP that ships with Apple and we are good to go.

    Create this lame, un-changeable non-existent directory tree (-p is recursive; go figure):

    sudo mkdir -p /Library/Server/Web/Config/php

    Next, symlink in there the redis.ini

    sudo ln -s /usr/local/etc/php/5.4/conf.d/ext-redis.ini /Library/Server/Web/Config/php/redis.ini

    Finally, restart Apache

    sudo apachectl restart

    Did that work?

    php -m | grep redis
    redis

    Yep, I take that as a good sign.

    All future installs of PHP extensions can be sudo symlinked into this same config-file-scan-dir and we’re good to go.

  • How to fix WordPress wp-admin htpasswd redirect loop

    Posted on August 6th, 2014 phpguru No comments

    If you want a quick and easy way to boost the security of your WordPress blogs, a simple, fast and easy thing you can do is to place a password on your wp-admin directory. CPanel enables this in a moment, just by going to the “Password Protect Directories” feature within CPanel.

    Password protecting directories works following these simple steps.

    1. Click Password Protect Directories
    2. Navigate to public_html by clicking on the folder ICON
    3. Click the folder name link (NOT the icon) for wp-admin directory
    4. In the dialog, enter a username and password and save the details under the User portion
    5. In the dialog, choose to Enable Protection and give it a name, like ‘Top Secret – No Entry’
    6. Save it and then in another browser tab, navigate to yoursite.com/wp-admin

    Now if you’re like me, your wp-admin is broken with a message, “The page has caused a redirect loop”

    You google something like wp-admin htpasswd redirect loop, and find suggestions how to fix it… and find some blog posts like this or that, but you ask your web host about it, and they don’t let you modify httpd.conf config file.

    What to do?

    It turns out the answer is simple, you just need to edit your .htaccess file and add the following line at the top.

    ErrorDocument 401 default

    If you followed the steps above, the CPanel interface created an .htaccess file for you automatically. Go to the file editor feature within CPanel now, and find this new file inside the wp-admin directory, and click edit. Paste the line at the top, save it, refresh wp-admin, and you should be now seeing a dialog asking for your username and password — the one you set at step 4 above. The final .htaccess file including the password protection we added should look like this when you’re done:

    ErrorDocument 401 default
    AuthType Basic
    AuthName "Top Secret - No Entry"
    AuthUserFile "/home/yourusername/.htpasswds/public_html/wp-admin/passwd"
    require valid-user

    Note, do not edit the path for the AuthUserFile – it will be unique to your account and CPanel configuration. This adds a 2nd layer of protection in front of your wp-admin directory in addition to your existing WordPress administrator username and password.

  • How to fix: The connection has timed out in Firefox 29

    Posted on June 6th, 2014 phpguru No comments

    If your web page dies in 5 minutes, it may not be a server-side issue

    I recently ran into a situation where a long-running webpage would timeout after 5 minutes in Firefox. Every time, with no server logs generated.

    I tried increasing the max_execution_time PHP configuration value with ini_set. That didn’t work. I tried set_time_limit() too, but to no avail.

    After a whole lot of debugging PHP on the server side, I discovered the problem was not related to any timeout on the server configuration. The timeout problem results from a new invisible configuration value that was implemented in Firefox itself at version 29. If you’re running Firefox 28 or before, then there was no such default.

    I tried it in Chrome and things worked fine.

    If you use Firefox, please check your version. If you’re on version 29 then Firefox itself can be the culprit generating a timeout error. You might see, “Sorry, the page could not be displayed.” Try again in a few minutes, check your proxy settings, and so on.

    To fix it:

    1. Quit and restart Firefox so only one tab is open.
    2. Go to about:config (type that into the address bar) and then click OK when you are warned that you are about to void your warranty.
    3. Navigate to the following config key: Network -> http -> request -> timeout
    4. and double click on 300
    5. Change it to a larger value, such as 3600 (1 hour), 7200 (2 hours), or 86400 (24 hours) – the value that works best for your application.

    As you can see, the default timeout in Firefox 29 is 300 seconds, or 5 minutes.

    See the accepted answer on support.mozilla.org/en-US/questions/998088 for the gory details.

  • How to split a file into 2 chunks in bash

    Posted on May 9th, 2014 phpguru No comments

    I have a task to take a file with millions of lines, and to split it in exactly two files, with a controlled top `head` portion part A file, and the remainder of the lines in part B file.

    It actually turns out to be somewhat non-trival to split a file in 2 chunks, with a small defined top portion and a large arbitrary bottom portion.

    The split [OPTION]... [INPUT [PREFIX]] function is really designed to make N chunks out of your file, or M chunks each containing N lines; I debated using it and merging all but the first file back together, but decided to look up sed examples instead.

    I ended up with the below function. There’s almost certainly a faster/better way to achieve it but this seems to work.

    Sample usage

    remainderof bigfile.txt 1000
    When that runs you will have this result

    1000_bigfile.txt // this is the top 1000 lines
    1000R_bigfile.txt // this is the remainder of the file after splitting off the top 1000 lines
    bigfile.txt // the original untouched file

    Using optional 3rd argument

    remainderof bigfile.txt 1000 true
    When that runs you will have this result

    1000_bigfile.txt // this is the top 1000 lines
    bigfile.txt // this is the remainder of the file after splitting off the top 1000 lines
    // the original file no longer exists

    Here’s the function

    alias ll='ls -larth'
    
    function remainderof() {
    
        thefile=$1
        batchsize=$2
            if [ ! -z $3 ]
                    then
            : # $1 was given
            replaceoriginal=$3
            else
            : # $1 was not given
            replaceoriginal=false
            fi
    
        if [ $# -lt 2 ]
        then
             echo "Usage: $0 filename_to_split rows_to_chop [opt_bool_process_in_place_destructively]"
             exit 1
        fi
    
        extension="${thefile##*.}"
        filename="${thefile%.*}"
        length=$( wc -l < $thefile )
        buffer=$(($length-$batchsize))
        echo Splitting $batchsize lines off the top of $filename $extension leaving $buffer from $length  ...
        #  The top chunk filename
        topfile=${filename}_${batchsize}.${extension}
    
        # The bottom chunk = remainder of file
        startofnext=$(($batchsize+1))
        remainder=${filename}_${startofnext}-${length}.${extension}
        echo "Writing $topfile and $remainder"
    
        # Split off the first N lines of the file
        head -n $batchsize $thefile > $topfile
    
        # split off the bottom LENGTH - N lines of the file
        sed "1,${batchsize}d" $thefile > $remainder
    
        # whether to leave a copy
        if [ "$replaceoriginal" = true ] ; then
            rm -rf $thefile
            mv $remainder $thefile
        fi
    
        echo `wc -l < $topfile` lines in $topfile
        echo `wc -l < $remainder` lines in $remainder
    
    
        echo Done
    }
    

    If you have improvements, leave a comment!

  • How to prevent iPhoto launching when connecting iPhone

    Posted on August 25th, 2013 phpguru No comments

    The solution is on the Apple forums:

    1. Plug in your iPhone.
    2. Launch Image Capture from your Applications folder
    3. Select your iPhone once it shows up under devices
    4. Look at the lower bottom pane where you’ll see “Connecting this iPhone opens”
    5. Set this preference to “No application”

     

    See also: How to prevent iTunes from launching when connecting your iPhone or iPad

  • How to prevent iTunes launching when connecting iPhone

    Posted on August 25th, 2013 phpguru No comments

    The solution is on the Apple forums:

    1. From the iTunes menu at the top go to iTunes>Preferences>Devices>Prevent iPods, iPhones and iPads from syncing automatically.
    2. Check the box at the bottom of that window.
    3. Click on [Your Phone's Button] to access the device. This is on the right side of the iTunes main window toward the top, just to the left of the store button. If you don’t see your phone here, unplug it, plug it in again.
    4. Scroll down and uncheck Automatically Sync when this iPhone is connected
    5. Click Done
    6. Quit iTunes.
    7. Unplug and re-plug in your phone. iTunes should not launch.

    If that doesn’t work, also try:

    1. See if iTunes Helper is in System Preferences > Users & Groups > Login Items
    2. If so, delete it (click it then press the minus button)

     

    See also: How to prevent iPhoto from launching when you connect your iPhone

     

  • The never-ending saga of the dual DVI KVM switch

    Posted on December 1st, 2012 phpguru No comments

    It seemed like a good idea at the time.

    My Digital Audio Workstation, or DAW, was acting up. An aging Dell Dimension 4600, it was taking nearly 30 minutes to start up and giving a startup message about lacking a page file on a custom-tweaked dual-boot XP setup. I had set it up several years ago and installed so much crap over the years. I thought it was time to replace it.

    The trouble was, had had been using this setup with 2 other computers, another PC and a Mac, using a pair of VGA-PS/2 KVM switches. The Dimension is a PS/2 based design, and my other computers could share my VGA/DBI displays. I had gotten so used to using two screens, that I almost can’t think straight without it now.

    Well I finally gave in and sent the PC to my brother who happens to be a computer hardware whiz. I figured he could fix it, and I decided to upgrade it to a Dell Precision T1600 workstation. I got a great deal on one at the Dell Outlet. Since I had been using a collection of DVI to VGA adapters on the previous 3-computer 2-monitor configuration, I decided to also upgrade to a dual DVI KVM switch, thereby freeing up some desk space, cleaning up my studio, and giving me more room for my Native Instruments Maschine.

    So, off I go on the internet to search out dual DVI KVM switches.

    The first one I consider is a Belkin Soho on Amazon. I had pretty good luck with my old Belkin VGA-PS/2 KVM switch, and who doesn’t love Amazon, so I decided for $250 it was a pretty decent price and worth a shot. My workstations on are the ends of an L-Shaped desk, and I had to get 3 pairs of dual DVI KVM cables with it. Grand total: around $500.

    Five days later, I get the Belkin Soho dual DVI KVM switch delivered. I open everything extremely carefully, because I wasn’t sure it was going to work, and I wanted to be able to send it back if it didn’t. I open the box, tear down my entire rig across 3 computers and hook everything up, including some new miscellaneous adapters.

    Strike One.

    Wouldn’t you know it? Right out of box the Belkin Soho felt so cheap ho hum. Fragile and weak plastic. I tried it every which way, and was able to get only 1 screen working on a single computer! None of the other ports were sensed properly. I have no idea if I got a defective unit or what, but that thing was a piece of junk and didn’t work at all. Undo everything, redo everything back the way it was, with VGA PS/2 KVM. Everything works fine again, except I’m out 4 hours.

    Over the next few days, I worked with the Amazon seller to get an RMA number to send it back, I lose about $50 in shipping charges in the deal, and now two weeks later, I’m back where I was before.

    So, off I go again on the internet to search out professional quality dual DVI KVM switches. I arrive at a site called (SEO fans should be proud) KVM-Switches-Online.com. They have a whole section of their site dedicated to dual-display and multi-display KVM switches. I look at a couple of Avocent models and a few Adder products.

    I decide to send an email to sales to ask for some advice. A day later, I get a response with a recommendation. I decide to try a 4×2 dual DVI kvm switch (2SVDVI20BND1-001) from Avocent corporation. I later discovered that Avocent is now owned by Emerson, and the model I purchased seems to be either undergoing a transition, or in the process of being discontinued. Anyway, feeling pretty confident from their response and the knowledge of the salesman, John F, I thought I would give it a go, bought it and waited another few days. With 3 sets of 15-foot dual DVI USB KVM cables, this new order set me back close to $800. I figured for nearly twice the price of the Belkin Soho, it ought to be sweet.

    And it was. I got it home and the following weekend, set up this new one. The Avocent is much higher quality and durable feeling than the Belkin. I was immediately thinking this was going to be it, and I could get back to writing music. Another 4 hours later, I have everything all torn down and tested again, and insanely enough, I think I got a defective Avocent! Both screens were detected from all 3 computers, but I only was able to get a few horizontal pixel lines on the second screen, while the rest of screen 2 was completely black!

    “UGH! What a crock,” I complained. “Again?!”

    Strike two.

    Just because I got a defective Avocent KVM switch doesn’t mean you will, give them a try. They make nice stuff and their single-DVI KVMs look just as nice. But for me, having already spent a month an a half trying to solve this problem, I decided to return it a try a different one again. It was now becoming a little bit like deja vu. I tear everything back down, put everything back the way it was, check it all, re-package all the cables and KVM switch, and request another RMA number.

    Finally I decided to contact KVM-Switches-Online. I get forwarded over to John F, who says he’ll either send me a replacement Avocent or help me choose an upgraded product.

    John walks me through selecting an Adderview Pro Multiscreen, a unique product line that comes in Dual-DVI, Tri-DVI, and Quad-DV-USB-KVM switch versions. I have only two displays, so I ordered the dual (Quad pictured above). Adder switches are some of the best on the market, he said. Again I made sure to order 3 sets of dual 15-foot DVI-USB cables and used my RMA credit from the Avocent (now down around $600 after subtracting shipping the return back).

    I wait another few days. Five to be exact.

    When it finally arrives, I’m stoked. The Adderview Pro Multiscreen is really a nice KVM switch. It has a digital readout, not unlike the first digital alarm clock you might’ve had, multiple settings, and keyboard control. I get ready to install it and realize that although the packaging says “5-metre” the cables inside are clearly 3-foot (1m). Not long enough to reach my 3 PC.

    Good lord. Still no luck with 1 of my 3 computers, at this point I’m getting kind of frustrated, but try to keep my cool and contact John again. See, now we start to get on a first name basis, because I had to convince them that I wasn’t insane and that, in fact, the Cables that shipped with the Adder KVM Switch were mis-labeled in the wrong packaging.

    Another day or two goes by (I have a day job – this is for my hobby room’s PCs). I call John again and talk to Krissy, who manages customer orders and returns. She hands me off to John, who says he spoke with Adder, talked to the shipping manager, who called him back on his cell from the warehouse and indeed verified that I am not insane, that there was a packaging mistake, and to hang tight for 6 new 15-foot DVI USB KVM cables. Yes, dual DVI KVM for 3 PCs, six cables. They would offer me a discount of not having to pay shipping for the second shipment. I guess that’s something.

    Alright, great. I wait another five days. It’s been two months now since I started this journey to find the perfect dual DVI KVM switch.

    The new cables arrive, and they’re sweet! A few hours later, the third time now tearing down a 3-PC dual VGA PS/2 KVM and setting up a 3rd KVM switch, I can use my Mac and my Dell XPS perfectly now. But for some reason, the Precision T1600 is only working on one monitor.

    I try port 4 on the KVM instead of port 3. Same thing. Minus another half hour.

    I try to swap out the cables and verify it’s not that. Nope. I flip flop the cables, and see I get the other screen working, but not both. Minus another hour.

    It’s still Saturday afternoon, so I figure I will dig into the issue on the Dell support chat and forums. Turns out, guess what! Duh! My VGA to DVI adapter won’t work…

    “You can drive a VGA display from a DVI connector, but not the other way around,” The Dell support tech says. I was getting only the screen from the DisplayPort to DVI connector. So, off I go to Amazon to order a new Graphics Card that supports Dual DVI – the EVGA nVidia GeForce 620. It’s got exactly the ports I needed, and has 1GB of RAM. I figured that would be perfect.

    Minus another $50 and two hours of research & shopping, followed by another two days of Amazon Prime shipping.

    I get the card upstairs, installed it into the T1600 and still get one monitor to work. I can’t believe it, now. Using this card, only 1 display is recognized! I cannot for the life of me figure it out. I download the tech specs from the Dell Precision T1600 and the EVGA nvidia GeForce 620. There it is, in black and white, clear as crystal:

    GeForce 620: This card requires 350w of power and 18amps on the 12-volt rail.

    Hmmm. I start to become concerned that I don’t know a lot about PC power supplies.

    Precision T1600: Power supply 265w.

    Rats, that has to be it, I thought. Just to be sure, I fire up a chat support with Dell to confirm that upgrading the power supply won’t void the warranty or damage the PC. I’m told not to worry, just that Dell won’t cover the new Power Supply under their warranty and to keep the original one just in case. Surf for a few to find out how complicated buying a PC power supply can be. Doesn’t look too bad, thanks to this article on how to buy the right replacement PC power supply over at computershopper.com.

    Now I’m tearing down my DAW again, to yank the power supply out and head back to the computer store in search of a new replacement higher-wattage power supply. Minus another hour.

    I get back later with a 400w Antec 80+ Bronze power supply and install it. I reconnect the KVM and fire it up. Hmm, not looking good. I get VGA on one screen still.

    I can’t get Windows 7 to even notice that there is a 2nd monitor attached. That seems odd to me, so I Google it. I find a post where a commenter replies that you have to go into the bios and enable multi-monitor support. Hmm. Really? Gosh, I’ve been spoiled by using a Mac for way too long. So I reboot and press F2 and the Dell screen. Strange thing is, I can’t seem to find anything related to multi-monitor support in the BIOS I am running.

    I launch a Dell support chat in the other PC (I have some of the KVM ports working) to ask about that. I decide it would be easier to call and talk to someone.

    Dell: Are you using any adapters?

    Me: No, just DVI cables.

    Dell: The Precision T1600 with your Service Tag says it has integrated graphics, 1 Display port, 1 VGA port, so you must have some adapters if you’re using it with DVI monitors.

    Me: No, I am trying to install and use an nvidia GeForce 620 in PCI slot 4. The specs say it needed a larger power supply so I am also I bought one and I’m using that to rule out lack of power.

    Dell: I see. Well, if you use the DisplayPort with a DVI adapter, and a VGA monitor it should work.

    Me: I don’t have a VGA monitor.

    Dell: Please hold while I look up a few things.

    (Ten minutes go by)

    Dell: Sir, I regret to inform you that the bios on your machine only supports dual screens via the Display Port and VGA adapters. Because that machine came with integrated graphics and not a Dell-approved PCI card for multi-screen technology from the factory, there’s no way for you to enable multi-monitor support in the Bios, I don’t think there’s any way I can solve your issue, and since you’re using a 3rd-party graphics card, we can’t support that, either.

    Me: Wow. Unbelievable. Can I return this computer?

    Dell: I don’t know. Dell Customer Care is open weekdays during normal business hours. Would you like their toll free number?

    Me: Sure. (I write it down.)

    Dell: Is there anything else I can help you with?

     

    ARGH! I wanted to slap that guy! I know it wasn’t his fault and he was just following a script, but my God! I’m now 6 weeks down the road, several thousand dollars out of pocket and still don’t have a working solution to the Dual DVI USB KVM saga.

    Now I’m faced with a dilemma. Do I try to return everything and start over? Pillage all the parts I have in this dell in the fabrication of a new home-built PC? Buy a new one and sell this one on eBay?

    At the end of the day, building a DAW is a tricky pain in the neck, and making a production studio setup with 3 computers sharing one keyboard, mouse and two DVI monitors is even more complicated.

    I know once I get the kinks ironed out, the AdderView Pro Multiscreen is going to do the trick, and I received very good customer service from KVM-Switches-Online.com — they were all helpful and polite and were clearly interested in getting my order and my setup done right!

  • How to buy the right power supply for your PC

    Posted on December 1st, 2012 phpguru No comments

    Whether your power supply is blown, or you want to add a new PCI card upgrade, you really ought to check out this fantastic write up on PC computer power supplies. Very informative.

    http://computershopper.com/feature/2010-ultimate-guide-how-to-buy-a-pc-power-supply/(page)/1