Category: Linux

Find in PHP files

Often, I search for a function, most likely a wordpress function, within the PHP files. It is usually done within wordpress themes that contains a few other files too, particularly minified CSS file that results in seeing the entire minified CSS file in the output of the search result. This is pretty annoying to say the least.

Now, I started using an alias that finds only the PHP files and then pass the result to a grep command to find only what I really need. Here’s the alias…

alias findinphp='find * -type f -name '*.php' -print | xargs grep -inr'

I could have used the built-in -exec option too. However, it doesn’t play well when we search thousands of files. Moreover, using xargs is safe and faster.

systemctl automatically restart service


  1. Ensure systemd services restart on failure by Jon Archer
  2. php-fpm systemd unit with auto-restart by Juan Luis Boya García
  3. systemd Project Web Page

systemd is a system and service manager that runs as PID 1 and starts the rest of the system and services. The main command used to introspect and control systemd is systemctl.

Basically do the following to let a service restart automatically…

  • Edit /lib/systemd/system/name.service file
  • Insert “Restart=on-failure” under the section “Service”. Save the file
  • Execute the command… systemctl daemon-reload
  • Execute the command… systemctl restart name_of_the_service
  • (optional) try killing the process now

See for more examples.

PhpMyAdmin Disable Warning: Your PHP MySQL library version differs from your MySQL server version – This may cause unpredictable behavior

Short answer:

For those who still can’t understand…

Open up your PhpMyAdmin’s file and then add the following line in it…

$cfg['ServerLibraryDifference_DisableWarning'] = true;

Now, log out and then log in to PhpMyAdmin. Do you still see the warning?

IPv4 for APT


At times, apt may try IPv6 to resolve a domain name. In which case, it may not be desirable and sometimes, it just doesn’t work for that particular server. So, to let apt to use only ipv4 for DNS resolution…

Edit /etc/gai.conf

uncomment the following line…

precedence ::ffff:0:0/96 100

If the above line doesn’t exist, just insert it at the bottom or at the top of the file!

Verify the changes with the command (before and after the changes)…


UFW error in Debian

UFW, Uncomplicated Firewall, was created for Ubuntu, then ported to other distributions as well, primarily to Debian. So, it’s no wonder, there are some incompatibilities when running UFW under Debian, at times. Those incompatibilities or errors are usually fixed in the stable releases. However, due to the difference between how things work and how we expect things to work, there may be some errors with the default configuration.

In Debian 7, UFW was installed lately. And, in the end of deploying it, the following command was run…

sudo ufw --force enable

Immediately, it provided the following error…

ERROR: problem running ufw-init

Upon digging through the issue, I noticed that IPv6 address wasn’t available in that server and UFW meant to complain about it. So, the solution is to disable IPv6 in UFW, by editing


and then comment out the line



Happy firewalling!

Postfix Flush Deferred Email Queue

Some people try to test out an application, a site, a contact form and may use an email like that would never be delivered by the local email delivery system and would be in the queue forever, or until it is deleted.

Here’s a trick to delete such emails from postfix. Similar commands may be available with other similar tools too.

# to see the mail queue
postqueue -p
# to delete all the deferred emails
postsuper -d ALL deferred

# verify that queue is empty
postqueue -p
# for more info, check out the *man* pages of these commands

Fedora 19 – Setup Hostname & FQDN

Fedora 19 seems to have changed the way one can setup the hostname and fully qualified domain name. By making this change, it streamlined the setup similar to how things work in Debian derivatives, including Ubuntu. Here’s how it’s done…

# as 'root'
cat 'hostname' >> /etc/hostname
sed '1i127.0.1.1 hostname' -i /etc/hosts
hostname -F /etc/hostname

# verification
hostname -f

In Amazon Linux AMI, one still has to set it up only in



Logwatch Template

I use logwatch in almost all the places. So, here is a little piece of template that I use all the time. A little explanation, though. Whenever I setup a new server, I setup a daily logwatch. Once, the server becomes stable, I move it to weekly logwatch. So, during the transition period, it is just a matter of commenting out certain lines and un-commenting certain other lines. Anyway, here, we go…

# global / common directives
MailFrom =
MailTo =

# Un-comment the following two lines, to enable weekly logwatch
# Range = between -7 days and -1 days
# Subject = "Weekly Log from Pothi Inc"

# Comment out the following two lines, to disable nightly logwatch
Subject = "Nightly Log from Pothi Inc"
Detail = High