Tuesday, October 16, 2012

Linux Mysql Configuration and Backup Tutorial



Mysql Configuration :

Mysql is one of the enterprise database provided by Oracle.

First Check the Mysql server and client packages are installed.

Check with rpm -qa | grep mysql




Check the mysql daemon is running or not.

service mysqld status 

if not

service mysqld start




Connect to the mysql use the following command.

mysql -u root -p 

you will connect to mysql database.

mysql>

mysql > show databases;  (This command list the available databases)




Create a new database called senthil.

mysql> create database senthil;



mysql> use senthil; ( Use named database)

mysql> show tables; (List the tables in the database)




Create a new table.
mysql> create table login (uanme varchar(20), upass varchar(20));




To insert a values into that table,

mysql> insert into login values ("sdfdf", "sadsf");




To list the records in that table, 

mysql> select * from login;




Mysql databse backup:

In linux OS prompt execute the following command.

# mysqldump -u root -p senthil > /root/bacup.sql





Once the backup is done, login to mysql.

mysql> drop database senthil;  ( This removes the database) *** This you can test only the dummy database.




Restoring the database:

In Linux Os prompt use the following command.

# mysql -u root -p senthil < /root/backup.sql





Now you check with show databases;



All the records are restored.




Mysql stores in /var/lib/mysql location ( All databases files)




Linux Apache Server Configuration Tutorial


Apache Server Configuration:

The Apache Web Server is one of the most popular open-source HTTP Servers that exists today. It's a powerful, secure, and fully featured web server that can be found hosting anything from personal web sites to corporate domains. If you have a DSL or Cable connection with a static IP then you can use the Apache web server to host your web site (as long as your ISP doesn't have a problem with you running a server on their network). This tutorial will teach you how to set up your own Apache web server on Linux so you can host your own web sites either at home or work.


Configuring Apache Server Settings (httpd.conf)

Apache's main configuration file is called httpd.conf and is located in /etc/httpd/conf/. The default httpd.conf will work without any changes, however we want to customize Apache a little bit. Our main focus is to setup the use of Virtual Hosts so we can run as many web sites as we want using a single IP address.


Check the Apache (httpd) Package is installed or not.

rpm -qa | grep httpd




The main location of the configuration files are reside at /etc/httpd.

Which contains the conf and conf.d directory.



The main configuration file for Apache server is /etc/httpd/conf/httpd.conf




This file contains three major sections.

1. Global Environment
2. Main Server Section
3. Virtual Hosts Section




I . Global Environment Section:

Here all the major values are called as directives. 

Serverroot directive  ---- /etc/httpd   ---- Which contains all Apache config files.



Connection time out Directive  -- Default value is 120 seconds



Apache uses the HTTP protocol and uses the 80 as port number.

Listen directive  with port number 80.



Load modules directive defines, what are the modules loaded when the apache will restarted.



It includes the configuration files available in /etc/httpd/conf.d . Like php.conf, mysql.conf and ssl.conf



II. Main Server Section:

Server administrator directive  --- mail id of the web administrator.



Documentroot = /var/www/html . Which defines the web application deployment location (Source codes like HTML and Php)


Directory security directive  --- / (root) no one can not access 
It will set as 
Allow override None.



If you want to exceute the CGI scripts then add ExecCGI.




Set this directive as Allow from All.


Set the home index pages.



Error log location and error log format.


To execute the CGI scripts enable the scriptalias.




III. Virtual Host Section:

1. IP Based
2. Name Based --- Which uses the multiple websites single ip address.

Enable name based virtual host.



Now add the multiple site information in the virtual host section.




Now deploy the web site applications in the document root ... /var/www/html location.




Create the index.html file






For this example, i am using two websites, 

1. www.senthil.com
2. www.kumar.com

Now check the httpd daemon is running or not.

service httpd status

if not 

service httpd start


elinks and lynx are the text browsers in linux.

elinks http://www.senthil.com







Now we are accessing through the firefox browser  (www.senthil.com)


(www.kumar.com)



You can check the logs in /var/logs/httpd.

senthil_access_log
senthil_error_log





You can check who are all accessed the website using the access log file.