Installing / Re-Installing Apache, PHP, libapache2-mod-php

The following is done on an Ubuntu machine but hoping it should cover other Debian instances.

I accidentally deleted php7.0.conf and php7.0.load from the mods-available folder. These files come with libapache2-mod-php. I uninstalled the module and installed it again – but the files didn’t appear. A lot of blogs suggested to remove Apache, PHP and libapache2-mod-php altogether and installing it again and it didn’t work. I used remove, purge and everything suggested but didn’t help. Eventually, I had to search for the installed module by:

dpkg --get-selections | grep libapache2-mod-php

I installed the module above as is but the result showed me libapache2-mod-php7.0. So I went ahead and removed and purged the module listed after which I installed the module again (without the 7.0 suffix) and I was able to recover the files again.

apt-get remove --purge libapache2-mod-php7.0
apt-get install libapache2-mod-php

Since I am covering this topic, let’s talk about installing Apache on Debian and the supported PHP packages along with SSL support.

apt-get install apache2
apt-get install php
apt-get install php-curl
apt-get install libapache2-mod-php

Enable SSL on the site:

cd /etc/apache2/sites-enabled
ln -fs ../sites-available/default-ssl.conf 

Finally, add the necessary modules to support PHP/SSL on Apache

cd /etc/apache2/mods-enabled
ln -fs ../mods-available/ssl.conf
ln -fs ../mods-available/ssl.load 
ln -fs ../mods-available/socache_shmcb.load
ln -fs ../mods-available/php7.0.conf
ln -fs ../mods-available/php7.0.load

Do not forget to restart apache with

service apache2 restart

Linux – Adding useful aliases

I prefer to add the aliases to a different file rather than the .bashrc. You can modify the .bashrc file to include the .bash_aliases file:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

And then create a new file .bash_aliases in the home directory with the following or your own aliases:

# Adding custom aliases
alias l='ls -lrt'
alias lwc='ls -lrt | wc -l'
alias la='ls -lart'
alias lm='ls -lrt | more'
alias lwc='ls | wc -l'
alias f='find . -name $1'
alias b='cd ..'

Finally, to execute the bash_aliases in your current session without having to logout and login again, execute the following command:

. ~/.bash_aliases

Rename files in a sequential order

My camera shoots images until DSC_9999 and after that it resets to DSC_0001. It messes up the sequence of images shot during a day if the sequence is reset. I found this cool solution which resets them in sequential order starting from 1 and also pads 0’s to the beginning if the number is less than 100.

for i in *.JPG; do
  new=$(printf "DSC_%04d.JPG" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1

Debian – Switching the hostname/IP of the machine cleaned up the resolv.conf file

I built a new server to replace an existing staging server. After I did the cutover and made the new one my staging server, I realized I wasn’t able to ping internally on the network as well as outside. I checked the networking on the VMware server and it was set correctly but I still kept getting the following error on ping:

$ ping
ping: unknown host

I checked the hosts file under /etc/hosts and the hostname file and both of them were fine. However, I tried to ping the IP of google and I was able to connect. Which made me realize that resolving of the domain names to IP via DNS (Domain Name System) is not working.

Next, I did a nslookup for an internal system and google and didn’t get any response:

$ nslookup
;; connection timed out; no servers could be reached

And then I tried doing a nslookup by using Google’s Name Server A Name Server is a specialized server on the Internet that handles queries or questions from your local computer, about the location of a domain name’s various services.

A great simple way to think about name servers is using a phone book analogy. If you were trying to call Joe’s Trading Company, you’d want to look it up in a phone directory to find the phone number. The Name Server or DNS Server as it is also called does the same thing with finding out IP addresses for websites/DNS entries.

But anyways, here’s the output of nslookup when I used Google’s Name Server:

$  nslookup

Non-authoritative answer:

So, I came to a conclusion that the DNS resolution wasn’t working. I checked out the resolv.conf file on my local machine and realized it had been blanked out – possibly during the host/IP switchover. I checked another working server and copied over the configuration to my local file under /etc/resolv.conf. resolv.conf is the name of a computer file used in various operating systems to configure the system’s Domain Name System (DNS) resolver.

domain company.pvt
search company.pvt
nameserver 192.168.XXX.XX
nameserver 192.168.XXX.XX

After saving the file, I did a nslookup and got the following result:

$ nslookup
Server:		192.168.XXX.XX
Address:	192.168.XXX.XX#53

Non-authoritative answer:

A little bit more about DNS requests and how they work
But just how exactly did your computer know what webpage to display for you, and what server to pull it from?

Your web-browser knows you typed into the address bar.

Your current nameservers from the resolv.conf file are retrieved.

Your computer asks the nameservers for the A (address) record for

The nameservers respond back with the IP address

Your computer sends a request to that IP address along with the page you're requesting.

The web server hosted on then sends your web browser the requested page.

Note that on occasions, there might be canonical names (CNAME) assigned to a website. If you do a nslookup on the website, the nameserver will respond back stating that the requested entry is a canonical entry and then provide the address (A) record for the main server. e.g. Google uses WebEx’s services and have a unique URL for their operation. They may not have a standalone server but may be sharing the same WebEx’s server with other clients of WebEx. I did a nslookup on and the result confirmed that the dns was a canonical (CNAME) entry

$ nslookup
Server:		192.168.XXX.XX
Address:	192.168.XXX.XX#53

Non-authoritative answer:	canonical name =	canonical name =