Recent Updates Page 3 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 10:45 am on November 30, 2016 Permalink | Reply
    Tags:   

    Categories: Linux ( 95 )

    How to use variables in a BASH shell script 

    Here’s how to use simple variables in BASH shell scripts. It appears there are no data types, and everything’s a string (correct me if I’m wrong). We can define a variable by first setting it to a value, then later refer to that value with a dollar sign in front of the variable name.

    Here’s an example:

    #!/bin/bash
    
    VARIABLE="Testing"
    echo $VARIABLE

    Note that there are no spaces between the variable name, the equal sign or the value. Adding those will result in a runtime error.

    Variables can be defined in upper or lower case letters, or a combination thereof.

    BASH Variables have a global scope, unless they are prefaced with the local keyword inside functions (in which case, only said function will have access to its value).

     
  • Jay Versluis 10:44 pm on November 29, 2016 Permalink | Reply
    Tags:   

    Categories: Linux, PHP ( 95 )

    How to install PHP from source on CentOS 

    PHP-IconI have recently installed PHP 7 from source on a fresh minimal CentOS 7 box. No previous version of PHP was installed, and I thought I’d give 7 a spin. There were a few pitfalls I hadn’t come across before, so here’s what worked for me.

    Downloading and extracting the source code

    It sounds crazy, but this was the hardest part of the whole installation! There were two problems I’ve encountered here.

    The first was that PHP offer downloads via a mirror. A direct link may look something like this: http://php.net/get/php-7.0.12.tar.bz2/from/this/mirror. This means that if we were to download this file using wget, it would be saved as “mirror”. Now what we want.

    So instead we can ask wget to give the download a different name using the -O parameter, like so:

    wget -O php7.tar.bz2 http://php.net/get/php-7.0.12.tar.bz2/from/this/mirror

    This will save our file as php7.tar.bz2 instead. So far so good. Unpacking this file seems to be impossible. From what the internet tells me, this should be the correct way of extracting a tar.bz2 file:

    tar -jxvf php7.tar.bz2

    But that didn’t work, not matter how hard I tried. All I ever got was a “non-recoverable” error. Which sucks. In the end I extracted the file on my Mac, created a ZIP archive and downloaded that instead. Unnecessarily cumbersome and idiotic, but worked. Finally I had them on my CentOS box.

    Building the source code

    Jumping into the extracted directory, the configure command can prepare the build. At this stage I encountered an error:

    configure: error: xml2-config not found. Please check your libxml2 installation.

    This can be fixed by installing the libxml2-devel package (NOT libxml2 as the error would have you believe). Let’s do that and run configure again:

    yum install libxml2-devel
    ./configure

    Now we can run make, followed by make test to see if the installation is going to go well. This will take a few minutes.

    make
    make test

    Feel free to skip “make test” if you’re in a hurry. In my case, after over 10.000 tests, PHP told me this:

    You may have found a problem in PHP.
    This report can be automatically sent to the PHP QA team at
    http://qa.php.net/reports and http://news.php.net/php.qa.reports
    This gives us a better understanding of PHP's behavior.
    If you don't want to send the report immediately you can choose
    option "s" to save it. You can then email it to qa-reports@lists.php.net later.

    Perplexed yet unfazed, I continued on and installed PHP anyway:

    make install

    And only moments later, PHP 7 was running on my CentOS system.

    php -v
    
    PHP 7.0.12 (cli) (built: Nov  8 2016 06:59:14) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

    Not sure what else to tell you.

     
  • Jay Versluis 9:53 am on November 11, 2016 Permalink | Reply
    Tags:   

    Categories: Linux, WordPress ( 95 )

    Upgrade Trouble: when WordPress is asking for FTP details, but there’s no FTP server on your system 

    wordpress-iconI was working on a CentOS 7 server the other day that had a LAMP stack installed. It was used to host only a single instance of WordPress.

    Upgrading themes and plugins from the admin interface worked fine, but curiously, WordPress core upgrades did not. Instead, WordPress was asking for FTP details every time, which also prevented auto upgrades from being installed.

    This didn’t make any sense because there was no FTP server installed on the box, nor had there ever been one. But it did indicate that WordPress had an issue with overwriting core files.

    The first thing I checked was that the /var/www/html directory had the correct file and ownership permissions. It all looked correct, even though I did manually set them again just to make sure. Without success. WordPress was still asking for FTP credentials.

    After some research, I found that there is a setting for how WordPress accesses the filesystem when it’s upgrade time. We can define it with a constant called FS_METHOD in wp-config.php. The ins and outs are explained in the codex, under Upgrade Constants:

    FS_METHOD forces the filesystem method. It should only be “direct”, “ssh2”, “ftpext”, or “ftpsockets”. Generally, you should only change this if you are experiencing update problems. If you change it and it doesn’t help, change it back/remove it. Under most circumstances, setting it to ‘ftpsockets’ will work if the automatically chosen method does not. Note that your selection here has serious security implications. If you are not familiar with them, you should seek help before making a change.

    • (Primary Preference) “direct” forces it to use Direct File I/O requests from within PHP. It is the option chosen by default.
    • (Secondary Preference) “ssh2” is to force the usage of the SSH PHP Extension if installed
    • (3rd Preference) “ftpext” is to force the usage of the FTP PHP Extension for FTP Access, and finally
    • (4th Preference) “ftpsockets” utilises the PHP Sockets Class for FTP Access.

    So on this particular server, for whatever reason, WordPress did not choose the first method (direct), even though it should have. Defining this constant manually did the trick, all I had to do was add this line to my wp-config.php file:

    // explicitly use direct mode and stop asking for FTP details
    define('FS_METHOD','direct');

    Now updates are working as expected. I’ve never seen this problem on LAMP stacks before. Guess you learn something new every day.

     
  • Jay Versluis 10:34 am on November 7, 2016 Permalink | Reply
    Tags:   

    Categories: Linux, Python ( 95 )

    How to install Python 3 from source in CentOS 

    python-logoCentOS 6 comes with Python 2.6 installed, and CentOS 7 comes with Python 2.7. But right now, Python 3.5 is all the rage, so I thought I’d install it alongside Python 2.x on the same machine.

    Here’s how I did it.

    I’m using a CentOS 6 32 bit system here, but I’ve tried the same on a CentOS 7 64 bit rig. You need to be root or have superuser privileges to do this successfully. (More …)

     
  • Jay Versluis 11:19 am on November 6, 2016 Permalink | Reply
    Tags:   

    Categories: Linux ( 95 )

    How to extract tar.xz files on CentOS 

    CentOS-LogoI’ve recently come across a tarsal files that used xz compression (namely the Python source code).

    This means that my usual way of extracting a tarsal via the command line using the following command did not work:

    tar -zxvf Python*
    
    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now

    That had me stumped! Turns out that files with a tar.gz ending can be extracted this way (because the use gzip compression, specified by the z parameter). If tar is instructed to use this format on a tar.xz file, it fails.

    The solution: specify the xz compression, using the capital letter J, like this:

    tar -Jxvf Python*
    [massive list of files goes here]

    Another Linux mystery solved – thanks to Justin Solver for this tip!

     
  • Jay Versluis 11:06 am on November 5, 2016 Permalink | Reply
    Tags:   

    Categories: Mac OS X, Windows ( 34 )

    How to fix problems with Logitech Unifying Receivers 

    screen-shot-2016-11-04-at-17-12-10I’ve recently bought a new Logitech K360 keyboard for my HP Z600 workstation. I also had a Logitech M325 mouse, both of which came with Unifying USB receivers. I could plug both receivers in, and both devices would work great.

    However, I heard good things about these little receivers and wanted to free up a USB port, and thought I’d connect both devices to the same receiver. Apparently you can connect up to 6 devices to one receiver and store any spare ones inside the mouse or keyboard. Being an all-efficient belt-and-braces kinda guy, I tried my luck.

    Turns out it was relatively easy to pair both devices to the same receiver, thanks to a small piece of software that can be found here, along with instructions on how to use it:

    It all worked fine on my Windows 10 machine, until I wanted to use the mouse (not the keyboard) with my Mac. I know, it’s exotic, and perhaps I should have just bought another mouse. But there’s only so much space on my desk, and I really don’t need more clutter in front of me for just an occasional switch.

    I regretted pairing both devices to the same receiver and wished I hadn’t done that, for this very eventuality. So now I had to figure out how to UN-pair both devices again and put them back to how things used to be (before I started messing with them). (More …)

     
    • rexwu2013 12:38 am on June 11, 2017 Permalink | Reply

      The ONLY KVM technology can work with Logitech Unifying receiver is “DDM” class KVM switches. DDM (Dynamic Device Mapping). It had been proofed that current DDM version can match up to 6 Logitech USB Unifying devices with one single wireless dongle plug in to the share DDM port of the DDM KVM switches.

      When wnat to make sure 100% Unifying devices sharing experience, looking for DDM KVM switch. Again, this is truth since 2009 when DDM technology had been patented and delivered. Until now, it is still the only solution with Unifying Devices sharing.

  • Jay Versluis 10:54 am on November 4, 2016 Permalink | Reply  
    Categories: Mac OS X, Screencast ( 34 )

    How to launch a Mac App with Command Line Parameters from the Dock 

    In this video I’ll show you how to launch a Mac App from the Command Line, so that we can pass parameters. I’ll also explain how to wrap up such a command into your own app and add an icon to it, so that you can launch it from the dock with a single click.

    This can be useful if you need to convince Google Chrome or any other app to launch with certain parameters and modify its behaviour somehow. In my example I’m using Blender, and I’m using a startup parameter to change its default render engine upon launch. The same principles apply to any app you need to launch with startup parameters.

    The process is as follows:

    • find out the full path of the app you want to launch
    • try launching your app from the command line
    • now add parameters to the end of the launch command
    • create an Automator App
    • change its icon from from the generic Otto Icon to your desired app’s icon
    • drag your new launcher app into the dock

    I’ll explain all the gory details in this video.

    Enjoy!

     
  • Jay Versluis 11:39 am on November 3, 2016 Permalink | Reply
    Tags:   

    Categories: Linux ( 95 )

    How to boot CentOS 7 into Command Line or GUI Mode 

    CentOS-LogoIn CentOS 7 we can use the systemctl command to select which mode the OS boots into. If you have a GUI like Gnome or KDE installed, it’s easy to boot directly into your preferred environment.

    To find out what mode CentOS is currently using, use this:

    systemctl get-default
    

    This will give you one of two “targets”, either

    • multi-user.target (the command line), or
    • graphical.target (the Windows-like GUI)

    To change from one to the other, use one of these commands:

    systemctl set-default multi-user.target
    systemctl set-default graphical.target
    

    What happened to runlevels?

    In previous versions of CentOS, switching boot modes was achieved through runlevels. Those were saved in /etc/inittab, but this file is no longer used by CentOS 7 and above. However, the file still exists and contains a little extra info this matter, including how to change boot modes:

    # multi-user.target: analogous to runlevel 3
    # graphical.target: analogous to runlevel 5
    #
    # To view current default target, run:
    # systemctl get-default
    #
    # To set a default target, run:
    # systemctl set-default TARGET.target
    
     
  • Jay Versluis 4:29 pm on August 23, 2016 Permalink | Reply  
    Categories: Mac OS X ( 34 )

    How to kill a Mac App via the Command Line 

    Sometimes it’s’ necessary for us to force-close an app on our Mac if it’s no longer responding to our commands. Usually we’d do that by pressing CMD+OPT+ESCAPE, which brings up a handy window from which we can choose a troublesome app.

    Screen Shot 2016-08-23 at 16.10.14

    But sometimes, this keyboard combination won’t work – for example, if we’re dealing with a remote Mac to which no physical keyboard is attached. In such cases, we can choose to force-close an app via the command line. Let me show you how to do that.

    Connect to your Mac via SSH using a Terminal Session and find out what apps are currently running. We’ll so that with the top command:

    top -u

    Using the -u switch tells top to list the app with the highest CPU usage over time first. The command will display a list of running processes, much like this:

    Screen Shot 2016-08-23 at 16.15.04

    Take a look at the list and make a note of the troublesome app. In my case it’s Carrara, using 165% of my CPUs resources. By definition impossible, but let’s not worry about that. The important thing is this app’s PID (Process ID). Write it down or take a screenshot, we’ll need it in amount to kill the app (mine is 5964).

    Press CTRL+C to stop top and return to the command line. Now issue the following command, replacing 5964 with your own PID:

    kill -9 5964

    And that’s it: the troublesome app has been force-closed and should vacate your system sharpishly. For more information on both top and kill, check out their respective man pages on your Mac.

     
  • Jay Versluis 5:43 pm on August 7, 2016 Permalink | Reply
    Tags:   

    Categories: iOS, Mac OS X ( 222 )

    How to make Notes App sync properly on iOS 

    ios9-notes-app-iconHave you ever wondered why some notes seemingly sync just fine between your iOS devices, but others do not? Wether a note is not fully updated, or you find a duplicate entry in the list, it can be an exercise in frustration.

    But fret not, it doesn’t have to be! This is not a bug in the Notes app; it’s the way we’re using it.

    Let me show yo what you can do to avoid such problems, and how they can happen in the first place.

    Why do we sometimes get random duplicate notes?

    This has to do with the way the app stores data in the cloud. Notes saves your content only when you close the note, or when you switch away from it. Your note is not saved while you’re typing it.

    Likewise, iOS can only “save over” the current note if you’re not actively editing it. Leaving it open, even if you’re only looking at it, means your note is locked for edits from other devices.

    When you make a change on device A, and the same note is opened and edited on device B, then iCloud cannot save your changes to the current note. Hence it creates a duplicate entry. This is a safety mechanism so that your changes are saved rather than lost, and you can decide which copy you’d like to keep when you’re done.

    How to avoid sync trouble on iPhone

    So on iPhone, the solution is simple: always return to the list view of all your notes. Do not leave a note open. That way, another device can edit its contents without trouble.

    How to avoid sync trouble on iPad and Mac?

    On the iPad as well as your Mac, things are a little different due to the nature of the Split View Controller. It displays both the list of your notes, as well as a note next to it. Even when you hold your iPad in portrait mode and cannot see the list view, one note is ALWAYS open and displayed, and therefore cannot be edited by another device. That’s usually when and why iOS (or macOS) saves a duplicate.

    To avoid this situation, make sure you switch to a note that you’re unlikely to edit from another device. Perhaps create a “dummy note” without content and switch to it when you’re finished with the Notes app.

    Remember you can look at a note even if it’s open on another device – it’s just that when editing an open note, trouble keeps in.

    Hope this helps 🙂

     
    • juliav305 8:26 pm on August 7, 2016 Permalink | Reply

      Another great article thank you – another part of the system that made me think I was going slightly crazy with duplicate notes of the same thing or not syncing up at all. Mystery solved 🙂

      • Jay Versluis 8:33 pm on August 7, 2016 Permalink | Reply

        Thanks Julia 🙂

      • Jay Versluis 8:34 pm on August 7, 2016 Permalink | Reply

        Thank you, Julia 🙂

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel