Linux Server Administration Tips

SMTP server telnet connection refused on Linux?

I was testing the WP Mail SMTP plugin to send emails in WordPress via SMTP servers but when it was trying to connect to the remote SMTP server, it kept getting error “Connection refused”. So I tried: telnet smtp.xxxx.com 587 To test the connection. Turned out my own server is preventing the outgoing request because …

SMTP server telnet connection refused on Linux? Read More »

Whitelist server IPs for SSH connection against ERROR – ssh: connect to host port: Connection refused

If you have multiple servers you’d probably need rsync to transfer files among servers via SSH. An error like this, however, will occur when CSF protects the servers against malicious SSH connection attempts: The solution is very simple. Just whitelist each server IP on the other server and vice versa: Wherein 1.1.1.1 is the other …

Whitelist server IPs for SSH connection against ERROR – ssh: connect to host port: Connection refused Read More »

Clone any static site by a simple Linux command WGET

Just use this and the WGET command will start crawling the target site and download certain levels of pages from the starting URL, including all its assets such as images or CSS files. wget -k -K -E -r -l 1 -p -N -F –convert-links -H -Dcdn.shopify.com,v.shopify.com,www.yoursite.com,your-site.myshopify.com –restrict-file-names=windows https://www.yoursite.com/ The -D option specifies all the hosts …

Clone any static site by a simple Linux command WGET Read More »

500 Internet Server Error for Incorrect Permissions after Installing suPHP and Uploading PHP Script

Many’s the time after you have uploaded some PHP script to your server and point the web browser to the address it gives 500 Internet Server Error. If you have suPHP installed this is very likely because the uploaded PHP script (files and directories) have wrong permissions set to them. With regards to Linux permissions, …

500 Internet Server Error for Incorrect Permissions after Installing suPHP and Uploading PHP Script Read More »

Linux: How to delete / remove hidden files with ‘rm’ command?

To delete all content in any directory, including all sub-directories and files, I’ve been using this: rm -rf somedir/* If it is to delete all content of the current directory: rm -rf * However, it turns out ‘rm -rf’ doesn’t remove hidden files such as .htaccess (Files with a name starting with a dot are …

Linux: How to delete / remove hidden files with ‘rm’ command? Read More »

Linux: How to ‘find’ and search ONLY text files?

The ‘find’ command in Linux systems searches through a directory and return files that satisfy certain criteria. For instance, to find a file that contains the string ‘needle text’ in the ‘mydocs’ directory: find mydocs -type f -exec grep -l “needle text” {} \; The problem of this approach is that it would search through ALL files …

Linux: How to ‘find’ and search ONLY text files? Read More »

Use stat command to display file system meta information of any file or directory under Linux

PHP has a stat() function that returns an array containing the meta information of a file such as owner, size, time of last access, last modification or last change. It’s basically the stat command under Linux that returns and shows the file system meta information of any file or directory: stat myfile.txt Which returns: File: …

Use stat command to display file system meta information of any file or directory under Linux Read More »

Linux: How to open and extract an RAR zipped file and unrar the archive?

Funny I should use “zipped” for an RAR compressed package. Anyway, you can easily zip or unzip a zip file or tar compress a package, but how does one do it with an RAR file? WinRAR is well distributed across all Windows systems. But on Linux, you have to first install the command package rar. …

Linux: How to open and extract an RAR zipped file and unrar the archive? Read More »

scp, rsync: Transfer Files between Remote Servers via SSH

Chances are you have a bunch of different hosts that are housing your website files, for the sake of data safety (never put all eggs in a single basket) and possibly some SEO advantage. If that is the case, you will infrequently come to the need to move some files from one host server to …

scp, rsync: Transfer Files between Remote Servers via SSH Read More »

Linux: Find files changed or modified within xx day or older than xx day

One of the utility commands of Linux that you should know in the first day of your Linux learning seminar is find. To search recursively in the directory somedir for files changed / created / modified within 1 day: find somedir -ctime -1 Or within 5 days: find somedir -ctime -5 To search recursively in …

Linux: Find files changed or modified within xx day or older than xx day Read More »

Linux: Change Directory or CD to the Previous Directory / Last Path

cd is the command in Linux to change the current working directory. While you can change to your home directory by cd ~, you can change to the previous directory or last directory you were in by: cd – Which would come very handy when you are working across multiple directories back and forth. To …

Linux: Change Directory or CD to the Previous Directory / Last Path Read More »

Linux: Check how much disk storage each directory takes up (Disk Usage command – du)

The Linux command du stands for disk usage which is used to check the amount of disk storage any particular directory or file is using. By default, the simple command: du Would return the disk usage in God-knows-what-unit of each of the directories in the current working directory and those beneath them — in a …

Linux: Check how much disk storage each directory takes up (Disk Usage command – du) Read More »

Linux: How to find all the files containing a particular text string?

At Linux command line, to find a particular text string in all the files from the current directory recursively (that is, including all those files from the child or grandchild directories), use something like this via SSH: find . -exec grep -l "needle" {} \; This command searches through all directories from the current directory …

Linux: How to find all the files containing a particular text string? Read More »

Linux wget Command to Download and Mirror a Website in Static Local Copy

wget is such a wonderful command in Linux you can ever get. Consider blessed to have it in your SSH arsenal. Now, not only does it allow you to download something neatly from the command line to the current working directory — that’s why WordPress always puts the latest version of the blog script at …

Linux wget Command to Download and Mirror a Website in Static Local Copy Read More »

How to Recover or Reset MySQL root Password after You Forgot and Lost It

MySQL has come with a safe mode wherein access privileges are not checked, which essentially enables you to log in anonymously to change anything in any database. And we are going to get in this safe mode to reset the lost MySQL root password. First, you need to stop the current MySQL daemon by: /etc/init.d/mysql …

How to Recover or Reset MySQL root Password after You Forgot and Lost It Read More »

Linux, PHP: Differences between File Modification Time: filemtime() and File Change Time: filectime()

In most Unix file systems, the modification time and the change time of a file may not necessarily be the same, they are actually 2 very distinct concepts to deal with: File modification time represents when the data blocks or content are changed or modified, not including that of meta data such as ownership or …

Linux, PHP: Differences between File Modification Time: filemtime() and File Change Time: filectime() Read More »

Where is php.ini located?

Well it depends on the Linux distribution you are using, the version of php and the way you install it with Apache web server. Php.ini may be here: /etc/php.ini Or here: /etc/php/php.ini /etc/php5/php.ini Or here: /usr/bin/php5/bin/php.ini Anyway, you can always find any file named php.ini in this manner find / -name php.ini The simplest yet …

Where is php.ini located? Read More »

Scroll to Top