Setup LAMP on centos 7

Here are steps provided to install LAMP on centos 7.

Check version of OS using command

cat /etc/redhat-release

Command to install all packages required for Apache, mysql and php

yum install httpd php php-mysql mariadb-server -y

Let’s enable and start all services using commands

systemctl enable httpd mariadb

Now start httpd and mariadb services.

systemctl start httpd mariadb

Try to access your server IP in browser and you will find apache accessible.

To check php version execute following command

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Try to access this page using url

http://IP-of-machine/phpinfo.php

Let’s configure mysql service.

To configure MariaDB, run ‘mysql_secure_installation’

[root@midnight~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: NewPasswordHere
Re-enter new password: NewPasswordHere
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

Now your server is ready to host website supporting php and mysql database.

Restore a Deleted File in Linux

We will learn how to restore delete file in linux

Foremost is not available in any of the CentOS/RHEL repositories, so we’ll need to install it using RPM.

For centos 7 use following command

yum install https://forensics.cert.org/centos/cert/7/x86_64//foremost-1.5.7-13.1.el7.x86_64.rpm -y

For Centos 6 use following command

yum install https://forensics.cert.org/centos/cert/6/x86_64//foremost-1.5.7-13.1.el6.x86_64.rpm -y

Once formost installed let’s try to delete one file and recover it.

Get details of file midnight.jpg which we will delete and recover

file midnight.jpg
md5sum midnight.jpg

Now delete file

rm -f midnight.jpg

Restore a Deleted File

mkdir /root/recover
foremost -i /dev/sda1 -t jpg -o /root/recover/

Here -i used to specify disk and -t used to define type of file which we want to restore.
This command will find any .jpg files in /dev/sda1 and restore them into the /root/restored/ directory, as long as the space they are using on disk has not yet been overwritten by anything else.
Now go to /root/restored/jpg folder and execute md5sum 17602156.jpg and you will find md5 hash of this file is exactly same as that of midnight.jpg.

Types of Webhosting

Types of webhosting.

There are mainly two types of web hosting 1: Managed hosting 2: Un-Managed hosting.

Managed hosting: Here, web hosting provider provide complete support. Even if client send email and ask them to create email account they will create email account for him.

Creating email account is very simple task client just need to login his cPanel account and Go to Email section and create account with few clicks. In un-manage hosting web hosting provider will reply you and ask to create it yourself 🙂

What are pros and cons of Managed hosting

1: Just email or initiate live chat and ask them to perform any smallest and easiest task.

2: Client can blame for any issue like downtime, site hacked or slow loading speed.

3: Client can get assistance to configure and install 3rd party applications like WordPress ,Joomla or any application which need manual installation.

Cons:

1: Only one so far I noticed you need to pay almost double price every month even if you are managing site/server yourself.

Un-managed hosting pros.

1: Client get hosting at very low cost.

Cons:

1: Client need to take care of his hosting.

2: Maintain backups, Install and configure applications.

3: Client need to learn all technical stuffs ie. optimizing server, services, applications he has installed.

Suggestion: If client want to run wordpress site and he is non-technical guy. Then he shall go for managed hosting once he learn how to download backup and upgrade applications and maintain his site then he can shift to un-managed hosting and save money.

cPanel web hosting

Featured

cPanel Webhosting.

cPanel is most user friendly panel in web hosting. Most of the shared hosting provider , reseller, dedicated & cloud server use this panel to manage client’s site or their own site. Most important feature of cPanel is it provide lots of features like. Create email accounts, setting filters, forwarders, FTP accounts , Password protect folders etc…

For hosting provider it is very important to manage and monitor activities going on their server especially on shared server. Main advantage of shared hosting server is you can host lots of sites and oversell resources.

What is overselling. Suppose you have server with 16 CPUs, 300 GB disk, 10 TB (10240 GB) bandwidth and 32 GB RAM. Such server will cost provide around $200 per month. Here hosting provider will provide client basic plan like: 10 GB , and 100 GB bandwidth for $2. He would able to host such 500 Clients on his cPanel server because most of the client ie. 90% will not use even 10 GB bandwidth and 1 GB disk space while hosting a site. Also most of sites will have very low traffic in such case they will not be using even 1% of server’s total resources.

In this way shared hosting server would able to make $1000 per server costing him $200 including cPanel license.

I will write few more post about Web hosting business. Feel free to raise any question either technical or non-technical in comment or contact us form. I would glad to assist free of cost.

What is web hosting

What is Web hosting and web hosting service providers.

Web hosting means rent web space for your web site so that it will be accessible using internet allover world.

Web hosting services provide web space on their server to host your website (developed with help of webdeveloper) .  These servers are very high powered hardware configuration and internet connectivity upto 1 GB ie. 1024 mbps.  Once you host your web site internet user can type your web site in browser and access your web site.

How to Use the Traceroute Command

How to run traceroute/tracert for domain or IP.

Sometimes end user is not able to access specific site or IP,  Even end user IP is not blocked on server. In such case user need to take traceroute to IP or domain and provide it to ISP.

ISP would check if there any issue at any specific hop. Output of traceroute is also useful when site loading speed is slow for specific user/ISP.

Below are steps to get traceroute IP or website for linux.

Open command prompt/ hash prompt and execute command

Using traceroute for domain

traceroute midnight-cafe.com

Using traceroute for IP

traceroute 103.228.112.92

Below are steps to get traceroute IP or website for Windows.

Using traceroute for domain and IP

start > run > cmd

tracert midnight-cafe.com

tracert 103.228.112.92

run cronjob on random time

 

Cronjob to run on random time.

Some users need cronjob to be run every after X hours and random min ie. X hours and (1 to 60 mins).

Let say you need to run cronjob every after 4 hrs and 1-100 mins. Then it would be like given below:

* */4 * * * sleep $[ ( $RANDOM % 100 ) + 1 ]m; /path/to/script or command

 

command to delete empty folders on linux

Sometime we need to find remove only those folders which are empty. (Doesn’t contains any file or folder) .  rmdir is command which will delete folder only if it is empty.

find . -type d -exec rmdir {} \;
This command will find all files with type d (type d means all files those are directories) in present folder. Then execute rmdir for all directories but since rmdir will remove only empty folder and for other it will throw error.

Creating mysql user and database without prefix

Create mysql user and database without prefix.

By default cPanel used to create database and DB user with cPanel username _as prefix. But now cPanel version 68 allows you to disable prefixing so you can create single DBs and DB users.

You can enable disable prefix feature from

WHM > Tweak Setting >  Require a username prefix on names of new databases and database user

Example: If you create database with name wp as cPanel user india. It will create database as india_wp but if you disable this then it will allow you to create database with name wp only.

Automated Backup of mysqlDB on cpanel

Here we will learn how to backup all databases of cPanel server in specified folder say /home/mysqlbackup

First of all we will list all databases in a file using command

  • echo “show databases” | mysql > /home/DB_list.txt

By default first line of the output is DATABASE and rest of lines are name of databases.

Second command will help to get rid of first line.

  • tail -n +2 /home/DB_list.txt > /home/DB_list2.txt

So we have DB_list2.txt with list of all databases.

Here we will use for loop to backup all databases listed in DB_list2.txt

  • for m in `cat /home/DB_list2.txt`;do mysqldump $m > /home/mysqlbackup/$m.sql;done