Category Archives: Ubunto

Some common ssh command that we use regularly

SSH Command Explanation
ls Show directory contents (list the names of files).
cd Change Directory.
mkdir Create a new folder (directory).
touch Create a new file.
rm Remove a file.
cat Show contents of a file.
pwd Show current directory (full path to where you are right now).
cp Copy file/folder.
mv Move file/folder.
grep Search for a specific phrase in file/lines.
find Search files and directories.
vi/nano Text editors.
history Show last 50 used commands.
clear Clear the terminal screen.
tar Create & Unpack compressed archives.
wget Download files from the internet.
du Get file size.

PHP+Ubuntu Send email using gmail form localhost


Please do following steps to send mail from localhost on Ubuntu/Linux through gmail :-

For that you need to install msmtp on Linux/Ubuntu server.

Gmail uses https:// (it’s hyper text secure) so you need install ca-certificates

~$ sudo apt-get install msmtp ca-certificates
It will take few seconds to install msmtp package.

Now you have to create configuration file(msmtprc) using , gedit editor.

~$ sudo gedit /etc/msmtprc
Now you have to copy and paste following code in gedit (file you created with above command)

tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
port 587
auth on
logfile /var/log/msmtp.log
Don’t forget to replace MY_GMAIL_ID with your “gmail id” and MY_GMAIL_PASSSWORD with your “gmail password” in above lines of code.

Now create msmtp.log as

~$ sudo touch /var/log/msmtp.log

You have to make this file readable by anyone with

~$ sudo chmod 0644 /etc/msmtprc

Now Enable sendmail log file as writable with

~$ sudo chmod 0777 /var/log/msmtp.log

Your configuration for gmail’s SMTP is now ready. Now send one test email as

~$ echo -e “Subject: Test Mail\r\n\r\nThis is my first test email.” |msmtp –debug –from=default -t
Please check your Gmail inbox.

Now if you want to send email with php from localhost please follow below instructions:-

Open and edit php.ini file

~$ sudo gedit /etc/php/7.0/apache2/php.ini
You have to set sendmail_path in your php.ini file.

Check your SMTP path with

~$ which msmtp
and you will get /usr/bin/msmtp like that.

Search sendmail_path in php.ini and edit as below

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
sendmail_path = /usr/bin/msmtp -t
Please check 3rd line carefully there is no semicolon before sendmail_path.

Now save and exit from gedit. Now it’s time to restart your apache

~$ sudo /etc/init.d/apache2 restart
Now create one php file with mail function from

Do test and enjoy !!

Ubuntu allow www-data to write to new files

You will need to make sure that the directory you are writing to allows for www-data to write to it. Typically, you will want to put that directory in a place that is away from other files etc…

sudo chown  www-data:www-data <DIRNAME>
sudo chmod -R  g+w <DIRNAME>

For changing owner  :

sudo chown -R  <owner name > <dir name>


For globally set write permission fro www-data user :

sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www


Setting up the VirtualHost Configuration File

We start this step by going into the configuration files directory:

cd /etc/apache2/sites-available/

Since Apache came with a default VirtualHost file, let’s use that as a base. (gci.conf is used here to match our subdomain name):

sudo cp 000-default.conf gci.conf

Now edit the configuration file:

sudo nano gci.conf

We should have our email in ServerAdmin so users can reach you in case Apache experiences any error:


We also want the DocumentRoot directive to point to the directory our site files are hosted on:

DocumentRoot /var/www/gci/

The default file doesn’t come with a ServerName directive so we’ll have to add and define it by adding this line below the last directive:


This ensures people reach the right site instead of the default one when they type in

Now that we’re done configuring our site, let’s save and activate it in the next step!


After setting up our website, we need to activate the virtual hosts configuration file to enable it. We do that by running the following command in the configuration file directory:

sudo a2ensite gci.conf

You should see the following output

Enabling site gci.
To activate the new configuration, you need to run:
  service apache2 reload

After activating your site you need to edit your hosts file

The easiest way (most GUI) would be to use gedit. You could also use any other editor you prefer (e.g. nano or vi). Just run the editor as root using sudo and you’re good to go! You need to pass 1 argument: the path to the file you want to edit (in this case /etc/hosts).

The full command:

sudo -i gedit /etc/hosts

To load the new site, we restart Apache by typing:

service apache2 reload

For  index.php file hiding  needs to put this

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2’s
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/