0% found this document useful (0 votes)
78 views

Mysql & Apache Web Server: Huy Nguyen

This document discusses MySQL and the Apache web server. It provides an overview of MySQL, including how to install it, set the root password, create and manage databases and tables. It also covers basic operations like inserting, retrieving, updating and deleting records. The document then discusses what a web server is and how HTTP works, noting that Apache is a web server that understands the HTTP protocol. It explains the basic client-server interaction process when a client makes an HTTP request to the Apache web server.

Uploaded by

Ba VuVan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Mysql & Apache Web Server: Huy Nguyen

This document discusses MySQL and the Apache web server. It provides an overview of MySQL, including how to install it, set the root password, create and manage databases and tables. It also covers basic operations like inserting, retrieving, updating and deleting records. The document then discusses what a web server is and how HTTP works, noting that Apache is a web server that understands the HTTP protocol. It explains the basic client-server interaction process when a client makes an HTTP request to the Apache web server.

Uploaded by

Ba VuVan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

MYSQL & APACHE WEB SERVER

Huy Nguyen

1 http://www.tel4vn.com/
Outline
l  MYSQL
l  APACHE

2 http://www.tel4vn.com/
MYSQL
Database and Database Management System
l  Database is simply a collection of data. In relational database,

data is organized into tables.


Student ID Name Major Mark
01 A Class 1 7.5
02 B Class 1 8.0

l  Database Management System (DBMS) is software to


maintain and utilize the collections of data (Oracle,
PostgreSQL, MySQL, SQLite)

3 http://www.tel4vn.com/
MYSQL(cont)
MySQL Introduction
l  MySQL is a database management system
l  SQL stands for the Structured Query Language. It defines how
to insert, retrieve, modify and delete data
l  Free from www.mysql.com
Installation:
l  Ubuntu: apt-get install mysql-server mysql-client
l  CentOS: yum -y install mysql mysql-server mysql-devel
Set root password:
l  CentOS: mysqladmin -u root password 'htkdb1234'
l  Ubuntu: ask root password when installing
4 http://www.tel4vn.com/
MYSQL(cont)
Basic MySQL Operations
l  Create table
l  Insert records
l  Load data
l  Retrieve records
l  Update records
l  Delete records
l  Modify table
l  Join table (option)
l  Drop table
l  Optimize table (option)
l  Count, Like, Order by, Group by (option)
l  More advanced ones (procedures, triggers, views …) (option)
5 http://www.tel4vn.com/
MYSQL(cont)
Login
l  Command: mysql –h hostname –u username –p
l  Example:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 307
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
6 http://www.tel4vn.com/
MYSQL(cont)
Create database:
l  mysql> create database freeswitch;

Query OK, 1 row affected (0.01 sec)


l  mysql> show databases;

Choose database to use:


l  mysql> use freeswitch;

Database changed
l  mysql> show tables;

Grant access for user to use database:


l  mysql> grant all privileges on freeswitch.* to tel4vn@'192.168.1.50'

identified by ‘Passw0rd';
l  mysql> flush privileges;

7 http://www.tel4vn.com/
MYSQL(cont)
Create table
CREATE TABLE `cdr` (
`current_channel` varchar(80) NOT NULL default '0',
`next_room` int(6) NOT NULL default 0,
`move_time` datetime NOT NULL default '0000-00-00 00:00:00',
KEY `current_channel` (`current_channel`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

8 http://www.tel4vn.com/
MYSQL(cont)
Display table structure:
l  mysql> use freeswitch;

Database changed
l  mysql> show tables;

+----------------------+
| Tables_in_freeswitch |
+----------------------+
| cdr |
+----------------------+
1 row in set (0.00 sec)

9 http://www.tel4vn.com/
MYSQL(cont)
Display table structure (cont)
mysql> describe cdr;
+-----------------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------------------+-------+
| current_channel | varchar(80) | NO | MUL | | |
| next_room | int(6) | NO | | 0 | |
| move_time | datetime | NO | | 0000-00-00 00:00:00 | |
+-----------------+-------------+------+-----+---------------------+-------+
3 rows in set (0.00 sec)

10 http://www.tel4vn.com/
MYSQL(cont)
Modify table structure:
Command: ALTER TABLE table_name Operations
l  mysql> ALTER TABLE cdr add enable int(6) NOT NULL default 0;
l  mysql> describe cdr;
+-----------------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------------------+-------+
| current_channel | varchar(80) | NO | MUL | | |
| next_room | int(6) | NO | | 0 | |
| move_time | datetime | NO | | 0000-00-00 00:00:00 | |
| enable | int(6) | NO | | 0 | |
+-----------------+-------------+------+-----+---------------------+-------+
11 http://www.tel4vn.com/
MYSQL(cont)
Insert record
l  mysql> insert into cdr(current_channel,next_room,move_time,enable)

values('abc123','50','2012-03-26 10:30:01','1');
Query OK, 1 row affected (0.01 sec)
Retrieve record
l  Command: SELECT what_columns FROM table or tables WHERE

condition
l  mysql> select * from cdr;

+-----------------+-----------+---------------------+--------+
| current_channel | next_room | move_time | enable |
+-----------------+-----------+---------------------+--------+
| abc123 | 50 | 2012-03-26 10:30:01 | 1 |
+-----------------+-----------+---------------------+--------+
1 row in set (0.00 sec)
12 http://www.tel4vn.com/
MYSQL(cont)
Update record
l  Command: UPDATE table_name SET which columns to change WHERE

condition
l  mysql> update cdr set next_room='100' where current_channel='abc123';

Query OK, 1 row affected (0.00 sec)


Rows matched: 1 Changed: 1 Warnings: 0
l  mysql> select * from cdr;

+-----------------+-----------+---------------------+--------+
| current_channel | next_room | move_time | enable |
+-----------------+-----------+---------------------+--------+
| abc123 | 100 | 2012-03-26 10:30:01 | 1 |
+-----------------+-----------+---------------------+--------+
13 http://www.tel4vn.com/
MYSQL(cont)
Delete record:
l  Command: DELETE FROM table_name WHERE condition
l  mysql> delete from cdr where current_channel='abc123';
Query OK, 1 row affected (0.01 sec)
l  mysql> select * from cdr;
Empty set (0.00 sec)

14 http://www.tel4vn.com/
MYSQL(cont)
Drop table:
Command: DROP TABLE table_name
l  mysql> drop table cdr;
Query OK, 0 rows affected (0.00 sec)
l  mysql> show tables;
Empty set (0.00 sec)
Drop database:
l  mysql> drop database freeswitch;
Exit MYSQL:
l  mysql> exit or mysql> quit;

15 http://www.tel4vn.com/
MYSQL(cont)
Backup database
l  Command: mysqldump -u username -p database_name >

backup_file
[root@appliance ~]# mysqldump -u root -p freeswitch > dump.sql
Enter password:
Restore from mysql dump file
l  Command: mysql -u username -p < dump_file

[root@appliance ~]# mysql -u root -p < dump.sql


Enter password:

16 http://www.tel4vn.com/
MYSQL(cont)
Reset mysql root password
l  Stop mysql:

l  Ubuntu: /etc/init.d/mysql stop

l  CentOS: /etc/init.d/mysqld stop

l  mysqld_safe –-skip-grant-tables &

l  mysql> UPDATE user SET

password=PASSWORD(‘new_password’) WHERE
user=’root’;

17 http://www.tel4vn.com/
WEBSERVER
— What is a Web Server? And What is HTTP?
A Web Server is any Machine that receives requests from a client machine and is able
l 

to turn around process the requests and send back a response. This is usually in terms of
a Web Server to send back a Web pages when people what to go navigate to a webpage
that is hosted on that server now one may ask how do you send and receive the
information to and from the server. This is where HTTP begins to play a role into how
this all goes about.
l  HTTP Protocol: HTTP stands for Hyper-Text-Transfer-Protocol
l  This is the protocol that is used in order to send and receive information from the

server. This is the protocol that the Apache Web Server Understands and it is what it
uses to send information back to the client Machine. If you would want to get a bit
more technical on the subject the Client Machine this case the Browser sends a
HTTP.Request Object to the Server then the Server responds back by using an
HTTP.Response Object. This is the general back and forth between the server and the
browser. Apache is made to handle all of these requests.
18 http://www.tel4vn.com/
WEBSERVER (cont)
Client-Server Interactions
— As we stated before the Client makes an HTTP
request to the server in this case the Apache Web
server then the server handles the server pools
the connections to it, by the basic instructions
within the Apache Core then the server sends
back a response. Many people do not realize that
they be utilizing an Apache web server everyday
since it is the most popular web server out right
now. When you go online and request a webpage.
Most likely an Apache Web server is processing
your request and then it is sending you back the
webpage you requested.

19 http://www.tel4vn.com/
WEBSERVER (cont)
l  Apache2
l  Httpd

20 http://www.tel4vn.com/
WEBSERVER (cont)
Apache Overview
Diagram
— As you can see the
designers of Apache
decided to take a
modular approach so
that anyone can add to
the basic functionality
of the server without
disturbing the basic
Core implementation.

21 http://www.tel4vn.com/
WEBSERVER (cont)
l  Install:
l  apache2: apt-get install apache2

l  httpd: yum install httpd httpd-devel

l  Configuration file


l  apache2:

-  /etc/apache2/apache2.conf (main)
-  /etc/apache2/sites-available/
-  /etc/apache2/sites-enabled/
l  httpd: /etc/httpd/conf/httpd.conf

22 http://www.tel4vn.com/
WEBSERVER (cont)
l  Default document root:
l  apache2: /var/www/

l  httpd: /var/www/html/

l  Monitor service: netstat -ntulp


l  apache2: /etc/init.d/apache2 start/stop/restart

l  httpd: /etc/init.d/httpd start/stop/restart

l  Log file:


l  apache2: tail -f /var/log/apache2/*

l  httpd: tail -f /var/log/httpd/*

l  Test: http://ip-address or domain_name/


23 http://www.tel4vn.com/
WEBSERVER (cont)
l  Protecting Root
<Directory />
Options None
AllowOverride None •  Allowing Limited Access
deny from all Usage of IP Address or
</Directory> partial IP Address
l  Allowing All Access
<Directory "/var/www/ <Directory "/var/www/
html/"> html/">
Order allow,deny Order allow,deny
allow from all deny from all
allow from 10.10.2.15/32
</Directory>
</Directory>
24 http://www.tel4vn.com/
WEBSERVER (cont)
HTTP Basic Authentication
cd /var/www/admin
htpasswd -c .tel4vnpass tel4vn
vi /etc/apache2/httpd.conf
Add as below:
<Directory "/var/www/admin">
AuthType Basic
AuthName "FREEPBX ZONE"
AuthUserFile /var/www/admin/.tel4vnpass
Require valid-user
</Directory>

25 http://www.tel4vn.com/
WEBSERVER (cont)
Example:
Alias /siremis/ "/var/www/siremis-x.y.z/siremis-web/"
<Directory "/var/www/siremis-x.y.z/siremis-web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
RedirectMatch ^/siremis/$ /siremis/bin/
<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>
</Directory>
26 http://www.tel4vn.com/
Reference
—  http://www.mysqltutorial.org/
—  http://httpd.apache.org/docs/2.4/
—  http://code.tutsplus.com/articles/apache-2-basic-
configuration-on-unix-like-systems--net-26607

27 http://www.tel4vn.com/

You might also like