Realization of lamp architecture in Linux

Source: Internet
Author: User
Tags install php php and mysql php mysql php source code phpinfo

Lamp:linux+apache+mysql+perl/php/python a group of open-source software that is often used to build dynamic Web sites or servers, itself is a separate program, but because it is often used together, Having a high degree of compatibility together makes up a powerful Web application platform. From the traffic on the site, more than 70% of the traffic is lamp to provide, lamp is the most powerful website solution.

1.1 Experimental topological structure

Figure 1-1 Lamp experimental topological structure

1.2 Project requirements

Build a Web site that supports PHP and MySQL successfully, and access test.php and mysql.php in the browser, as shown in the page (take alice.com as an example):

(1)/var/www/html/test.php source code:

<?php phpinfo ();?>

To access the page in the browser:

Figure 1-2 Access Php.test success

(2)/var/www/html/mysql.php source code:

#cat/var/www/html/mysql.php

<?php

$link = mysql_connect ("localhost", "root", "112233");

if (! $link)

{die (' could not connect: '. Mysql_error ());}

Else

echo "MySql linked";

Mysql_close ($link);? >

To access the page in the browser:

Figure 1-3 Access Mysql.test success

1.3 Project development Ideas (mind map)

Figure 1-4 Lamp Experimental thought map

1.4 Experimental Steps

(1) Basic network construction

(2) on the DNS Server (192.168.0.253)

1) Install the DNS server

[[Email protected] Desktop]# yum install bind-y

2) Configuring the Master profile named.conf

[[Email protected] Desktop]# gedit/etc/named.conf

Options {

Listen-on Port: (any;};

Directory "/var/named";

Dump-file "/var/named/data/cache_dump.db";

Statistics-file "/var/named/data/named_stats.txt";

Memstatistics-file "/var/named/data/named_mem_stats.txt";

allow-query {any;};

};

Zone "Liaoyuanyang.com" in {

Type master;

File "named.liaoyuanyang.com";

};

Zone "0.168.192.in-addr.arpa" in {

Type master;

File "named.192.168.0";

};

3) Configure the positive solution database file

[[Email protected] Desktop]# cd/var/named/

[email protected] named]# Touch named.liaoyuanyang.com

[Email protected] named]# gedit named.liaoyuanyang.com

$TTL 3H

@ in SOA master.liaoyuanyang.com. Admin.mail.liaoyuanyang.com. (

0; Serial

1D; Refresh

1H; Retry

1W; Expire

3H); Minimum

@ in NS master.liaoyuanyang.com.

Master.liaoyuanyang.com. In A 192.168.0.253

Www.liaoyuanyang.com. In A 192.168.0.100

Client.liaoyuanyang.com. In A 192.168.0.10

4) Configure the anti-decryption database file

[[Email protected] Desktop]# cd/var/named/

[email protected] named]# Touch named.192.168.0

[Email protected] named]# gedit named.192.168.0

$TTL 3H

@ in SOA master.liaoyuanyang.com. Admin.mail.liaoyuanyang.com. (

0; Serial

1D; Refresh

1H; Retry

1W; Expire

3H); Minimum

@ in NS master.liaoyuanyang.com.

253 in PTR master.liaoyuanyang.com.

In PTR www.liaoyuanyang.com.

Ten in PTR client.liaoyuanyang.com.

5) Firewall Open 53 port

[[email protected] named]# iptables-i input-i eth0-p UDP--dport 53-j ACCEPT

[[email protected] named]# iptables-i input-i eth0-p tcp--dport 53-j ACCEPT

Figure 1-5 DNS Server Open 53 port

6) Start the DNS service

[[Email protected] named]# service named start

(3) on Web Server (192.168.0.100)

1) Set host name

[[Email protected] Desktop]# gedit/etc/sysconfig/network

Hostname=www

2) Web Services

A) Start the Web service (installed by default)

[[Email protected] Desktop]# service httpd start

b) Local test access Web

Figure 1-6 Web server local test Web

c) firewall open to 80 ports

[[Email protected] Desktop]# iptables-i input-i eth0-p tcp--dport 80-j ACCEPT

3) MySQL Service

A) installing the MySQL service

[[Email protected] Desktop]# yum-y install MySQL mysql-server mysql-devel

b) Start mysqld service

[[Email protected] Desktop]# service mysqld start

c) Set the password for MySQL

[[Email protected] Desktop]# mysql_secure_installation

4) PHP Service

A) Installing the PHP service

[[Email protected] Desktop]# yum-y install PHP php-mysql

b) Restart the HTTPD service

[[Email protected] Desktop]# service httpd restart

(4) Writing PHP and MySQL websites

[[Email protected] Desktop]# cd/var/www/html/

[email protected] html]# Touch test.php mysql.php

[Email protected] html]# gedit test.php mysql.php

Add in test.php:

<?php phpinfo ();?>

Figure 1-7 test.php Source code

Add in MySQL:

<?php

$link = mysql_connect ("localhost", "root", "666666");

if (! $link)

{die (' could not connect: '. Mysql_error ());}

Else

echo "MySql linked";

Mysql_close ($link);

?>

Figure 1-8 mysql.php Source code

(5) Setting up a DNS server on the client

[Email protected] ~]# gedit/etc/resolv.conf

Name Server 192.168.0.253

1.5 results Test (in Client on)

(1) test.php

Figure 1-9 Test Access test.php

(2) mysql.php

Figure 1-10 Test Access mysql.php

"All rights reserved, please specify the original source:http://www.cnblogs.com/liaoyuanyang/p/7029194.html "

Realization of lamp architecture in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.