Tagged: Linux Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 4:21 pm on April 22, 2012 Permalink | Reply
    Tags: , Linux,   

    Categories: Linux, MySQL ( 89 )

    How to install MySQL on CentOS 

    This is a step-by-step guide of what you need to do in order to install and setup MySQL on a new server.

    We’ll prepare a fresh CentOS 6 system (64 bit) for use as a database server. All you need is access to an SSH client and your server root credentials.

    (More …)

    • Jeff Huckaby 2:27 pm on June 20, 2012 Permalink | Reply

      Another item I always do is update the default my.cnf. By default, a number of features, such as query caching, is not enabled.

      If you look in:

      You will find some example my.cnf files. I typically use my-large.cnf as a starting point for systems with 4GB of RAM or less. Use my-huge.cnf for systems with more than this.

      Once deployed, check out tools like http://mysqltuner.pl and http://hackmysql.com/mysqlreport to better optimize your installation.

      • Jay Versluis 10:41 pm on June 21, 2012 Permalink | Reply

        Thank you so much for sharing Jeff, much appreciated! I’ll go check it out 😉

    • wayne 12:01 pm on September 2, 2012 Permalink | Reply

      hi, i am trying to set up mysql, and i still don’t see how to get to the actual webpage to set up everything. i set everything up right as far as i know. but i still need help getting to the actual program

    • gunawan 7:20 am on October 1, 2012 Permalink | Reply

      I tried but install but after click the yum
      service ….
      is failed
      then I try
      “error 2002 …”

      what I miss here?

    • Tom 4:30 am on December 24, 2012 Permalink | Reply

      It doesn’t work with me.
      With no configuration, i think it’s impossible

      • Jay Versluis 4:12 pm on December 24, 2012 Permalink | Reply

        What’s the error message you’re getting? Is yum installed on your system?

    • booksd 9:46 am on January 11, 2013 Permalink | Reply

      Any suggestions for the following command and response?

      [root@LiunxCentos arasu]# service mysql start
      mysql: unrecognized service
      [root@LiunxCentos arasu]#

      • Jay Versluis 4:06 pm on January 11, 2013 Permalink | Reply

        Sounds like MySQL is not installed, or your system does not recognize the service command. You can also try this:

        /etc/init.d/mysqld restart

        If you get a similar error message, then MySQL is not installed.

      • Jay Versluis 4:08 pm on January 11, 2013 Permalink | Reply

        I just re-read your command – the service is called mysqld, not mysql. Try again using

        service mysqld restart

        • Yeah 9:44 pm on January 11, 2013 Permalink | Reply

          Yeah, you actually wrote ‘service mysql restart’ in the tutorial, I imagine its tripped up a few others, myself included. Only took me 30 secs on google to figure out its ‘service mysqld restart’..Good article anwyays, thanks

          • Jay Versluis 12:41 am on January 12, 2013 Permalink

            How embarrassing!! I’ll change that right away – thanks for letting me know 😉

          • Carl Partridge 10:40 am on May 3, 2013 Permalink

            Actually, don’t change it – on some installations the service is called mysqld, on some the service is called mysql

            If you install from the current packages as per your tutorial, the service is called mysql

    • Mihai Alexandru 6:51 pm on February 23, 2013 Permalink | Reply

      Go on http://softiny.com and choose the LINUX tab and there are software apps to help you do this…

    • Grover 11:38 pm on March 25, 2013 Permalink | Reply

    • Independent Software Developer 4:14 pm on March 26, 2013 Permalink | Reply

      My first time really getting into CentOS and I’m trying to setup basic hosting for my site… I now have a new found respect for system admins because I have gotten so many headaches its not even funny.

      Thanks for this tutorial!

    • madhu 11:31 pm on January 25, 2014 Permalink | Reply

      hai frnds. . . ..
      iam facing problem with secure installation of mysql in centos 6.5
      while secure installation of mysql : /usr/bin/mysql_secure_installation
      am getting error as:Enter current password for root (enter for none):
      ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
      am entered as enter button only,i got the above error

      • Jay Versluis 11:48 pm on January 25, 2014 Permalink | Reply

        Try setting a password via the mysqladmin command as described by the friendly install message. Also, check if MySQL is actually running – you can’t connect if the service is down.

  • Jay Versluis 1:11 pm on January 11, 2012 Permalink | Reply
    Tags: , Linux, Mod Rewrite   

    Categories: Linux ( 89 )

    How to prevent direct file access in your wp-content directory 

    I was working on a secure site with sensitive video material that we needed strict members access to. Even though many plugins can make sure your direct permalinks can only be seen by logged in members, direct links to files in your wp-content directory are still accessible to others. They can even be hotlinked from other sites.

    One way around this is to move the wp-content directory outside the web visible portion of your directory on the server, but even so WordPress can always link to such files. A better way is to tell your server not to give access to certain files (say ending with mp4 or mp3) and only allow access from your own domain.

    We can use Apache Mod Rewrite for this – it’s a complex language that you can utilise in your .htaccess file within the wp-content folder.

    Let me show you how to keep prying eyes out of your content.

    (More …)

    • Dave 11:24 am on August 29, 2016 Permalink | Reply

      The problem is that legitimate downloads via link from within the site are also being blocked.

      • Jay Versluis 11:29 am on August 29, 2016 Permalink | Reply

        Pass I’m afraid.

        • Dave 12:23 pm on September 5, 2016 Permalink | Reply

          I may have messed up this part:


          What should that look like with the relevant details inserted?


          • Jay Versluis 10:50 am on September 6, 2016 Permalink

            Oh come on, Dave – if you can’t figure that part out, then you really shouldn’t be using this code at all!

          • Dave 11:50 am on September 6, 2016 Permalink

            You really think it’s obvious how a web address fits into this:


          • Jay Versluis 12:22 pm on September 6, 2016 Permalink

            Yes, I think it’s pretty obvious. The trick is this: leave everything as it is, every slash, every scary character, and ONLY replace the URL to your website. For example, if your actual website’s URL is http://www.obvious.com, then the whole block should look like this:

            RewriteEngine On
            RewriteCond %{HTTP_REFERER} !^http://(www\.)?obvious\.com/ [NC]
            RewriteCond %{REQUEST_URI} !hotlink\.(pdf) [NC]
            RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
            RewriteRule .*\.(pdf)$ http://obvious.com/ [NC]

            Note that you have to change the URL in two places in the block, as shown. Also, if you only want to block PDFs, shorten the list of file extensions (like I did here).

    • Noella Rose 9:22 am on August 30, 2016 Permalink | Reply

      My only issue is it’s not redirecting to the page I set, just a 404. It’s not the page that’s 404ing but the file, which is cool enough and works much better than before. I just decided to look into this now, but I had previously assumed that a security plugin had this direct access block thing, hah. Oh well, it works so well, now. Thank you.

    • Muhammad Usman Ghani 6:57 pm on October 21, 2016 Permalink | Reply

      Hey it worked perfect. But I have another case

      I have Mr.A having access to files ABC
      I have Mr.B having access too files XYZ

      But the above code will treat them as same – means registered users and they can swap my member only confidential files!

      How to kill this?

    • Muhammad Usman Ghani 9:46 am on October 22, 2016 Permalink | Reply

      Hi Jay,
      Noted.Will check this and related plugins.would have to see if any such plugin is compatible with my LMS plugin ( Goodlayers Good LMS) too.

    • Jason 4:18 am on October 27, 2016 Permalink | Reply

      We are using essentially the same;
      RewriteCond %{REQUEST_URI} .*[ProtectedFolder].*
      RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
      RewriteRule . /my-account [R,L]

      and it is working perfectly, except for one scenario;
      Video files(mp4) do not play on iOS devices. “Error loading this resource”.

      There does not seem to be any encoding file issues as when I remove the above lines from the htaccess the videos play without issue on iOS devices.

      I have found quite a few posts about the issue from over the preceding years, but none seem to have had a working solution to this issue =(
      I was hoping that you may have some insight?

      • Jay Versluis 4:20 am on October 28, 2016 Permalink | Reply

        Hi Jason, that’s an interesting one indeed. I’m only guessing here, but it may have to do with the way that iOS is requesting the video file over http. Maybe the have a secret way of turning an MP4 file into HLS? https://en.m.wikipedia.org/wiki/HTTP_Live_Streaming

      • Jason 1:11 pm on November 1, 2016 Permalink | Reply

        Well interestingly, it seems that iOS is just fussier with cookies than Android and Desktops when using WP cookies with htaccess to protect folder content.
        Using the “Remember Me” option when logging into WP sites prevents the “Error loading this resource” error message and the videos play fine.

        • Jay Versluis 1:26 pm on November 2, 2016 Permalink | Reply

          Look at that! The mysteries of Apple and their OSes. Thanks for sharing, Jason!

    • Jon 10:10 am on October 29, 2016 Permalink | Reply

      Very nice – perfect, thanks very much Jay!

    • Dirk 4:48 am on January 24, 2017 Permalink | Reply

      Thank you for this post Jay !
      I looked everywhere to find a simple and working solution to this problem.
      Your easy to understand and easy to implement code lines solved my problem.
      Just adding these lines to the already existing .htaccess and adjusting the website url did the trick.

    • mpbawebAndyC 2:11 am on March 24, 2017 Permalink | Reply

      This didn’t work for me. Uploaded the .htaccess to the wp-content folder then went to my website, logged out then entered a url direct to a pdf file in the browser and it opened just fine. Is there some caching going on or is it possible my web server is not using Apache?

      • Jay Versluis 11:38 am on March 24, 2017 Permalink | Reply

        Hi Andy, both of these scenarios are indeed possible. Let’s check one after the other.

        I’d test setups like this with two different web browsers, one in which you’re logged in, and another one in which you’re not (say Chrome and Firefox). Therefore you can make a change and see how the non-logged in browser is affected by it. Using the same browser may indeed give you caching issues and false results.

        To test if your server is running Apache or NGINX, open Terminal or a Command line tool of your choice, then type

        telnet yourdomain.com 80

        Replace yourdomain.com with your actual domain or your server’s IP address. Now we’ll make a simple http request and read the results:

        http / http1.0
        HTTP/1.1 400 Bad Request
        Server: nginx
        Date: Fri, 24 Mar 2017 15:25:07 GMT
        Content-Type: text/html
        Content-Length: 166
        Connection: close

        Only type the first line, the rest will be the output of the telnet tool. In this case, it looks like the server is running NGINX. In reality it’s more complex than that though: on my Plesk machine, there’s a very elaborate setup that first processes PHP via Apache, and then serves those files via NGINX. So although the telnet tool is right in saying the file is served by NGINX, it is processed by Apache beforehand.

        Here’s what an Apache web server might print out:

        http / http1.0
        HTTP/1.1 408 Request Timeout
        Date: Fri, 24 Mar 2017 15:29:48 GMT
        Server: Apache/2.4.6 (CentOS) PHP/5.4.16
        Content-Length: 221
        Connection: close
        Content-Type: text/html; charset=iso-8859-1

        Best ask your hosting provider which web server they’re using on your site. Hope this helps!

  • Jay Versluis 10:52 am on February 12, 2009 Permalink | Reply
    Tags: , , , , , Linux,   

    Categories: Linux ( 89 )

    How to setup a Cron Job in Linux and Plesk 

    Wouldn’t it be great if something could be triggered even when you’re not around? Say once an hour, once a day, once a week or whenever you like in predetermined intervals?

    Then you want to do this with what’s known as a Cron Job, or Scheduled Task.

    Unfortunately, this is a bit beyond what WordPress can do, and it means getting down to the nitty gritty of the internal workings  of your server (after all, that’s where WordPress lives). Bear with me here, I’ll try my best to explain and show solutions.

    I’m using a Cron Job with Manu Flury’s excellent Photo Q Plugin. It posts one of my pictures over at http://www.versluis.com every so many hours. But for this to work properly, both the WordPress Plugin and my (Linux) server need to be setup correctly.

    Some WordPress Plugins (like Rob Felty’s Postie or Charles Johnson’s Feed WordPress) have similar functionality built in, but they rely on a visitor coming to your site at predetermined intervals. That’s not something you can control really. In most cases it works reliable enough for these plugins to work, however many others just don’t have that functionality, or require more accurate control. That’s where your Cron Job comes in.

    So what on earth is a Cron Job?

    In a nutshell, it’s a task that’s triggered at predetermined intervals. But it’s a bit like sitting in front of a Linux Prompt on your SSH connection, and all you have at your displosal is a keyboard with a black screen and white text to type in. What’s worse, your server doesn’t speak “WordPress”, or PHP for that matter. So all you can do really is to give him Linux commands.

    In all likelyhood, you probably want to call a PHP file so that WordPress does something for you (such as check if it’s time for a new post, or maybe a database backup). And you can’t just tell Linux to go to that file, becasue it wouldn’t know what to do with it. I’ve tried this without success many times over (they nearly put me in a mental institution, seriously… I can assure you I’m much better now though).

    So you need to find a command that calls your PHP file as if it were a browser. Lucky for us, the command “wget” will do the trick.

    Wget is really designed for downloading a file to your server, but it’ll work fine for triggering a PHP file, just as a browser would do. The command for calling the Photo Q file for example looks like this:

    /usr/bin/wget -O - -q -t 1 http://www.yourdomain.com/wimpq-cronpost.php

    Confused? Don’t be! Let me explain:

    • “/usr/bin/wget” tells the server where the wget command is (it’s a path to a file if you hadn’t guessed)
    • “-O – -q -t -1” are some random parameters, let’s not concern ourselves with those right now (if you really want to find out, type in “wget –help” at your SSH prompt)
    • http://www.yourdomain.com/wimpq-cronpost.php” is the actual file you want to call, just like what you’d type into your browser

    Now that we know how to call upon a PHP file from our command prompt, we need to tell our server to do this without us being there, and at what times he needs to do this. He’ll be more than happy to oblige, after all, that’s what he was designed to do.

    How to setup a Cron Job in Plesk

    I’ll focus on how to do this in Plesk 9 here, which refers to it as Scheduled Tasks (earlier versions of Plesk call it Crontab).

    Here’s how you get there:

    • from the main menu on the left, select HOME
    • select DOMAINS
    • select the DOMAIN you want to run this task on
    • under Additional Tools, select SCHEDULED TASKS
    • choose the SYSTEM USER you would like this task to be run as
    • select SCHEDULE NEW TASK

    OK, this was complicated enough to figure out – now comes the part nobody ever really talks about. It’s hard to explain, so please bear with me if I’m not making a whole lot of sense at first. In essence, you’re telling your server WHEN to do something, followed by WHAT to do.

    • Each field requires an entry. Don’t leave them blank.
    • The first tick box is to “switch on” the task. That’s what you want, unless you want to suspend the task. Tick it for now.
    • Now tell your server WHEN your task shall be run.
    • a “*” (i.e. star or asterisk) means “every”. So a star in minute would run the task “every minute”, likewise for hours and days of the month
    • You can also create the command “*/5” if you want your task run every 5 hours, every 5 days, every 5 minutes – you get the drift
    • Alternatively, put in the specific date (i.e. “Monday” and “17” for Monday at 5pm)

    After all that, you’re left with one last line, which is the actual command or task you’d like to be run.

    Like I explained above, for a PHP file to be called, use the wget command like so:

    /usr/bin/wget -O - -q -t 1 http://www.yourdomain.com/wimpq-cronpost.php

    Obviously change the path to your file, including “http://”

    Click OK on the bottom and your task should be setup. No need to reboot anything.

    If at any time you feel you want to amend the task, you can do so by just modifying the parameters, or uncheck the “run task” tickbox to suspend the task completely.

    If you want to know even MORE about Cron Jobs, check this out:


    Good Luck, and have fun 😉

  • Jay Versluis 4:20 pm on February 9, 2009 Permalink | Reply
    Tags: , , , , , Linux, ,   

    Categories: Domains and Hosting ( 4 )

    What is a CRON Job? 

    Although I’ve been dealing with webshoting and webdesign since 1995, it took me a whilw to figure this one out. If you’re used to shared shosting packages, it’s likely that you’ve never come in contact with this. Hence, this article is aimed at people who don’t know what it is.

    As explained in Wikipedia:

    Cron is the name of a program that enables unix users to execute commands or scripts (groups of commands) automatically at a specified time/date. It is normally used for sys admin commands, like makewhatis, which builds a search database for the man -k command, or for running a backup script, but can be used for anything. A common use for it today is connecting to the internet and downloading your email.

    So a cronjob is a scheduled action, which is executed by and on your web server. WordPress itself doesn’t do this for you. It’s like having a monkey sitting at a command prompt, typing something in every minute/hour/day – in regular intervals – you get the drift.

    In order to setup this automatic execution, you need to be in control of your own dedicated or virtual server. If you’re on shared a shared hosting plain, you can ask your provider to setup a cron job for you. Just tell them “I want (this particular file in this particular directory) executed every Thursday evening at 9”. Otherwise, use your own administrative panel (like Plesk or Webmin) to set this up.

    Want to know how? Read the following article: How to setup a Cron Job?

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top
go to login
show/hide help
shift + esc