Tagged: CentOS Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 9:16 am on January 7, 2017 Permalink | Reply
    Tags: CentOS,   

    Categories: Linux ( 95 )

    How to fix duplicate packages in yum 

    From time to time, the yum package manager may encounter issues with duplicate packages that are erroneously installed on a system. This manifests in a yum update going awry, telling us something along the lines of this:

    yum update
    ...
    --> Finished Dependency Resolution
    Error: Package: ntp-4.2.6p5-22.el7.centos.2.x86_64 (@updates)
               Requires: ntpdate = 4.2.6p5-22.el7.centos.2
               Removing: ntpdate-4.2.6p5-22.el7.centos.2.x86_64 (@updates)
                   ntpdate = 4.2.6p5-22.el7.centos.2
               Updated By: ntpdate-4.2.6p5-25.el7.centos.x86_64 (base)
                   ntpdate = 4.2.6p5-25.el7.centos
     You could try using --skip-broken to work around the problem
    ** Found 41 pre-existing rpmdb problem(s), 'yum check' output follows:
    // huge scary list of packages follows
    

    You may at times install all other packages via yum update –skip-broken, but it will still leave some trouble on the system. Best to take care of it.

    Here’s how I’ve managed to do it on many occasions:
    (More …)





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

    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: CentOS   

    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: CentOS   

    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: CentOS   

    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:39 am on November 3, 2016 Permalink | Reply
    Tags: CentOS   

    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 12:14 pm on November 19, 2015 Permalink | Reply
    Tags: CentOS   

    Categories: Linux, Mac OS X ( 95 )

    How to see which users are logged in on OS X and Linux 

    There are two funky commands that can help us see who’s currently logged in, and what operations were performed last. Those two commands are who and last.

    Let me show you how to use them.

    The who command

    Type who at the command prompt and you’ll see a list of currently logged-in users:

    who
    
    versluis tty1         2015-11-19 11:21 (:0)
    root     pts/0        2015-11-19 11:46 (10.0.1.55)
    

    This system has two users logged in: versluis, via TTY, and root via PTS. We also get to see which IP addresses these users are logged in from (:0 is localhost).

    On this note, TTY is the local text based terminal at the machine, while PTS is a pseudo-terminal. This is most likely an SSH session or similar, anything that’s happening remotely.

    who can also show us who we are, in case you’re ever logged in on a system and don’t know which user you are:

    who am i
    
    your-username-here
    

    You can also concatenate who am i into whoami.

    The last command

    The last command can take a moment to execute and will show a list similar to this:

    last
    
    versluis tty1         :0               Tue Feb 10 18:54 - down  (4+13:11)   
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 18:51 - 08:05 (4+13:14)   
    root     pts/1        10.0.1.43        Tue Feb 10 16:33 - 16:44  (00:10)    
    root     pts/0        10.0.1.52        Tue Feb 10 11:36 - down   (07:13)    
    versluis pts/0        :0.0             Tue Feb 10 11:35 - 11:35  (00:00)    
    versluis tty1         :0               Tue Feb 10 11:29 - down   (07:20)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:27 - 18:50  (07:22)    
    root     tty1                          Tue Feb 10 11:16 - down   (00:09)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 11:15 - 11:25  (00:10)    
    reboot   system boot  2.6.32-504.8.1.e Tue Feb 10 10:59 - 11:25  (00:26)    
    root     tty1                          Tue Feb 10 10:29 - down   (00:28)    
    reboot   system boot  2.6.32-504.el6.i Tue Feb 10 10:28 - 10:58  (00:29)    
    
    wtmp begins Tue Feb 10 10:28:53 2015
    

    You can see who has logged in to the system recently, from which IP address, and when each session started and finished. You can also see when the system was last restarted (and in Linux, which Kernel was used to do so).

    The last line (on Linux, beginning with wtmp) shows since when the command was able to display results. last and who both read a file called wtmp (in /var/log/wtmp), which logs all login attempts over time.

    last accepts several filtering options too. For example, to query when a particular user has logged on and off, type last followed by the username:

    last versluis
    
    versluis tty1         :0               Thu Nov 19 11:21   still logged in   
    versluis tty1         :0               Tue Nov 17 12:44 - 22:32  (09:48)    
    versluis tty1         :0               Tue Nov 17 11:13 - down   (01:29)    
    versluis tty1         :0               Sat Oct 31 23:35 - crash (16+12:37)  
    versluis tty1         :0               Sun Aug  9 09:09 - down  (83+14:24)  
    versluis tty1         :0               Tue Jun 30 18:03 - down  (39+15:04)  
    versluis pts/0        10.0.1.52        Thu Feb 19 14:41 - 18:34  (03:52)
    

    Or if you’re only interested in restarts:

    last reboot
    
    reboot   system boot  2.6.32-573.8.1.e Thu Nov 19 11:20 - 12:02  (00:41)    
    reboot   system boot  2.6.32-573.8.1.e Tue Nov 17 12:43 - 12:02 (1+23:18)   
    reboot   system boot  2.6.32-573.7.1.e Tue Nov 17 11:12 - 12:42  (01:29)    
    reboot   system boot  2.6.32-573.7.1.e Sat Oct 31 23:34 - 12:42 (16+14:07)  
    reboot   system boot  2.6.32-573.1.1.e Sun Aug  9 09:08 - 23:33 (83+14:24)  
    reboot   system boot  2.6.32-504.23.4. Tue Jun 30 18:02 - 09:07 (39+15:05)  
    reboot   system boot  2.6.32-504.8.1.e Sun Feb 15 11:30 - 09:07 (174+20:37) 
    

    On OS X the output is somewhat more limited due to the absence of kernels, but it works just the same. For more information on each command, checkout the man pages with man last and man who.





     
  • Jay Versluis 1:06 pm on November 9, 2015 Permalink | Reply
    Tags: CentOS   

    Categories: Linux ( 95 )

    How to set the hostname on CentOS 7 

    CentOS 7 has a nice command called hostnamectl. With it we can display the current hostname, and set any of the three types of hostname:

    • static hostname (something like example.com)
    • transient hostname (anything you like, assigned when using DHCP)
    • pretty hostname (something like Jay’s MacBook Pro)

    By default, a CentOS installation comes back with localhost.localdomain – but that’s not meaningful if you see lots of localhosts on the same network.

    If the IP of the box does not change, we can set the static hostname like this:

    hostnamectl set-hostname example.com --static
    

    No feedback means good news. Likewise, we can set a hostname if were using DHCP to get an IP address, even though it may change every time we connect. To make sure we retain the same name no matter what IP we get, let’s set the transient hostname like so:

    hostnamectl set-hostname myserver --transient
    

    Note that we can’t use spaces or special characters with static or transient hostnames as far as I know.

    Lucky for us there’s also the pretty hostname, which does support special characters. It doesn’t usually appear anywhere on the command line, but GUIs like to display the pretty name of a machine when available:

    hostnamectl set-hostame "Jay's MacBook Pro" --pretty
    

    There’s no need to restart anything, the changes are in effect as soon as we hit return after either command.

    To see the current hostnames, we can use the status switch:

    hostnamectl status
    
       Static hostname: example.com
       Transient hostname: myserver
       Pretty hostname: Jay's MacBook Pro
             Icon name: computer-vm
               Chassis: vm
            Machine ID: 3d1ed70be1e940efaab8fb63b82822cc
               Boot ID: b95807c92b904fc192bd086b2596bea5
        Virtualization: kvm
      Operating System: CentOS Linux 7 (Core)
           CPE OS Name: cpe:/o:centos:centos:7
                Kernel: Linux 3.10.0-229.20.1.el7.x86_64
          Architecture: x86_64
    

    Thanks to Vivek Gite for this wonderful explanation!





     
  • Jay Versluis 11:24 am on November 4, 2015 Permalink | Reply
    Tags: CentOS, , OS X Server   

    Categories: Mac OS X ( 33 )

    OS X Server vs. Parallels Desktop – Overhead Differences 

    Screen Shot 2015-11-04 at 10.28.17

    Ever wondered if there’s a difference in overhead and memory usage when you’re using a VM instead of OS X directly? Here’s a comparison for website hosting.

    The above graph shows the difference of hosting one of my websites for the last few days on OS X Server (in blue) that I got from Hostgator (using their HostGator Thanksgiving Deal 2016 coupon), and in a CentOS VM under Parallels Desktop 10 on the same hardware (in red).

    The traffic logs show that the amount of requests and visitors has remained the same, so we can deduce that the load put on either OS X and the VM is the same. There is a little more overhead when using the VM, but not as much as I had feared: the requests have to be forwarded to another software layer after all, and that takes some CPU power.

    Let’s have a look at memory next:

    (More …)





     
  • Jay Versluis 8:05 am on November 2, 2015 Permalink | Reply
    Tags: CentOS,   

    Categories: Linux ( 95 )

    How to disable SSH access from everywhere except for certain IPs in CentOS 7 

    Here’s how to do it:

    firewall-cmd --zone=internal --add-service=ssh --permanent
    firewall-cmd --zone=internal --add-source=1.2.3.4/32 --permanent
    firewall-cmd --zone=internal --add-source=5.6.7.8/32 --permanent
    firewall-cmd --zone=public --remove-service=ssh --permanent
    
    firewall-cmd --reload
    

    This declares an internal zone with two IPs (add as many or as few as you like) and subsequently removes the SSH service from the public zone altogether. As a result, any other IP gets a message such as “Connection refused” when trying to connect via SSH.

    The “–permanent” switch saves the changes. Remove it for testing or if you don’t want this change to be permanent.

    The last line reloads the current firewall rules (thanks, CertDepot).





     
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