日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Linux下搭建LAMP具體方法

LAMP(Linux-Apache-MySQL-PHP)網(wǎng)站架構(gòu)是目前國際流行的Web框架,該框架包括:Linux操作系統(tǒng),Apache網(wǎng)絡(luò)服務(wù)器,MySQL數(shù)據(jù)庫,Perl、PHP或者Python編程語言,所有組成產(chǎn)品均是開源軟件,是國際上成熟的架構(gòu)框架,很多流行的商業(yè)應(yīng)用都是采取這個架構(gòu),下面為大家分享一下Linux下搭建LAMP具體方法。

準備工作

系統(tǒng)環(huán)境:centos 6.8 x86_64

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@localhost ~]#

LAMP相關(guān)包是否安裝: 默認httpd已經(jīng)安裝,在這里我們說明下:本次實驗我們采用的是yum的方式來進行安裝,httpd就是Apache軟件在RPM中的軟件包名

[root@localhost ~]# rpm -qa httpd
httpd-2.2.15-53.el6.centos.x86_64
[root@localhost ~]# rpm -qa mysql*
[root@localhost ~]# rpm -qa php*
[root@localhost ~]#

L-A-M-P 安裝

LAMP的安裝其實非常簡單,一條命令搞定。個人認為對于初學(xué)著沒有必要搞那么多這個插件,那個插件;到了深入了解了LAMP后在根據(jù)自己實際的需求來進行模塊的安裝,由易道難,循序漸進的學(xué)習(xí)。

yum倉庫的檢查

[root@localhost ~]# yum repolist                 \\查看yum倉庫的情況
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.aliyun.com
base                                                               | 3.7 kB     00:00    
extras                                                             | 3.4 kB     00:00    
updates                                                            | 3.4 kB     00:00    
repo id                             repo name                                 status
base                                CentOS-6 - Base                           6,696
extras                              CentOS-6 - Extras                         62
updates                             CentOS-6 - Updates                        482
repolist: 7,240

我們使用的是centos默認的網(wǎng)絡(luò)yum倉庫,當然如果默認yum倉庫比較慢的話,可以使用epel的軟件包。

yum安裝LAMP

[root@localhost ~]# yum -y install httpd mysql mysql-server mysql-devel php*
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-53.el6.centos will be updated
---> Package httpd.x86_64 0:2.2.15-54.el6.centos will be an update
--> Processing Dependency: httpd-tools = 2.2.15-54.el6.centos for package: httpd-2.2.15-54.el6.centos.x86_64
---> Package mysql.x86_64 0:5.1.73-7.el6 will be installed
..........................
Installed:
 mysql.x86_64 0:5.1.73-7.el6    mysql-devel.x86_64 0:5.1.73-7.el6    mysql-server.x86_64 0:5.1.73-7.el6    
 php.x86_64 0:5.3.3-48.el6_8    php-bcmath.x86_64 0:5.3.3-48.el6_8   php-cli.x86_64 0:5.3.3-48.el6_8        
.........

Updated:
 httpd.x86_64 0:2.2.15-54.el6.centos                                                                                  

Dependency Updated:
 httpd-tools.x86_64 0:2.2.15-54.el6.centos  net-snmp-libs.x86_64 1:5.5-57.el6_8.1  openssl.x86_64 0:1.0.1e-48.el6_8.1

Complete!

我們yum命令安裝httpd ,安裝mysql mysql-server 和mysql-devel開發(fā)包,在php的安裝包上面我們選擇了php* 的命令匹配搜有php相關(guān)的包。注意,注意的操作是為了讓入門童鞋們先了解LAMP的方案,在深入了解后,還是要跟進實際的情況安裝搜需要的包。

LAMP初始化

安裝完成LAMP后,我們需要對LAMP進行初始化,其實也就是啟動服務(wù),開機自起和必要的配置。

Apache的初始化

[root@localhost ~]# service httpd start           \\啟動httpd服務(wù);注意httpd和apache的關(guān)系
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName                                                           [  OK  ] [root@localhost ~]# chkconfig httpd on             \\設(shè)置httpd開啟自器 

mysql的初始化

[root@localhost ~]# service mysqld start           \\開啟mysql服務(wù),會提示需要初始化,很詳細
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                          [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@localhost ~]# chkconfig mysqld on                \\設(shè)置mysql開機自啟動
[root@localhost ~]# mysqladmin -u root password linuxprobe.com
                           \\初始化mysql,在這里需要設(shè)置mysql的root的密碼;命令:mysqladmin -u 用戶 password 密碼
[root@localhost ~]# mysql -u root -p                    \\登錄mysql查看是否能夠登錄        
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>                                             \\ok登錄成功

注意:在yum安裝lamp的時候,其實php只是apache的一個集成的組件,不需要添加模塊的應(yīng)用,只要在配置文件中啟用就可以了。

環(huán)境簡單的測試

查看經(jīng)常mysql和httpd是否運行:

[root@localhost ~]# ps -aux |grep httpd               \\查看httpd的進程
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      2930  0.0  2.9 487660 14664 ?        Ss   10:46   0:00 /usr/sbin/httpd
apache    2933  0.0  1.9 487660  9400 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2934  0.0  1.8 487660  9112 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2935  0.0  1.9 487660  9400 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2936  0.0  1.9 487660  9392 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2937  0.0  1.8 487660  9116 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2938  0.0  1.8 487660  9136 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2939  0.0  1.8 487660  9112 ?        S    10:46   0:00 /usr/sbin/httpd
apache    2940  0.0  2.3 487844 11840 ?        S    10:46   0:00 /usr/sbin/httpd
root     10163  0.0  0.1 103316   868 pts/3    S+   12:23   0:00 grep httpd
[root@localhost ~]# ps -aux |grep mysql               \\查看mysql的相關(guān)進程
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      3035  0.0  0.2 108216  1452 pts/1    S    10:47   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql     3137  0.0  4.3 367512 21444 pts/1    Sl   10:47   0:02 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     10165  0.0  0.1 103316   868 pts/3    S+   12:23   0:00 grep mysql

[root@localhost ~]# netstat -tanulp |grep 80      \\查看httpd 的端口對外監(jiān)聽
tcp        0      0 192.168.1.108:50878         63.80.4.177:80              ESTABLISHED 2629/clock-applet  
tcp        0      0 :::80                       :::*                        LISTEN      2930/httpd          
[root@localhost ~]# netstat -tanulp |grep 3306     \\查看mysql的端口對外監(jiān)聽
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3137/mysqld    

防火墻的相關(guān)設(shè)置

[root@localhost ~]# iptables -L                   \\查看iptables的規(guī)則
Chain INPUT (policy ACCEPT)
target     prot opt source               destination        
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination        
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination    

[root@localhost ~]# iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT    
                                    \\添加iptables INPUT的鏈的第一條規(guī)則允許tcp協(xié)議的80端口
                                 \\關(guān)于iptables 的更多設(shè)置,請參考《linux就該這樣學(xué)》相關(guān)內(nèi)容

[root@localhost ~]# service iptables save        \\將我們的添加的規(guī)則保存在配置文件
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@localhost ~]# iptables -L                         \\查看保存情況
Chain INPUT (policy ACCEPT)
target     prot opt source               destination        
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination        
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

測試httpd的靜態(tài)文件

添加一個測試的靜態(tài)index.html頁面,或者使用默認的頁面進行測試。關(guān)于添加網(wǎng)站頁面的更多問題,請參考《linux就該這樣學(xué)》的相關(guān)內(nèi)容

[root@localhost ~]# echo "hello word" > /var/www/html/index.html

測試用ie瀏覽器測試靜態(tài)頁面:

新手必看,老鳥繞道–LAMP簡易安裝新手必看,老鳥繞道–LAMP簡易安裝

ok,測試成功。

配置文件

[root@localhost ~]# ls /etc/httpd/              \\配置文件目錄,相關(guān)配置模塊conf/    conf.d/  logs/    modules/ run/    [root@localhost ~]# vi /etc/httpd/conf/httpd.conf  magic      [root@localhost ~]# vi /etc/httpd/conf/httpd.conf     \\主配文件[root@localhost ~]# wc -l /etc/httpd/conf/httpd.conf    1009 /etc/httpd/conf/httpd.conf                             \\ 主配文件共有1009行,其中有好多都是注釋的.養(yǎng)成好習(xí)慣,備份默認配置文件[root@localhost ~]# tail /etc/httpd/conf/httpd.conf      \\更多配置建議參考《linux就該這樣學(xué)》相關(guān)內(nèi)容# The first VirtualHost section is used for requests without a known# server name.##                                          \\配置文件中添加虛擬主機的語句#    ServerAdmin webmaster@dummy-host.example.com#    DocumentRoot /www/docs/dummy-host.example.com#    ServerName dummy-host.example.com#    ErrorLog logs/dummy-host.example.com-error_log#    CustomLog logs/dummy-host.example.com-access_log common#

高級環(huán)境的測試

LAMP是一個穩(wěn)定的動態(tài)的網(wǎng)站架構(gòu)方案,在這里我們需要添加php的支持,測試動態(tài)網(wǎng)站。

啟用對php的支持

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

[root@localhost ~]# cat /etc/httpd/conf/httpd.conf |grep  DirectoryIndex    
                                                 \\在配置文件402行添加對php頁面的支持
# DirectoryIndex: sets the file that Apache will serve if a directory

添加php測試頁面,測試

[root@localhost ~]# vi /var/www/html/index.php    
[root@localhost ~]# cat /var/www/html/index.php    \\添加php信息的測試頁面

[root@localhost ~]# vi /var/www/html/test.php
[root@localhost ~]# cat /var/www/html/test.php      \\添加php頁面測試
test
this php test

測試:

新手必看,老鳥繞道–LAMP簡易安裝新手必看,老鳥繞道–LAMP簡易安裝

注意: 動態(tài)網(wǎng)頁搭建動族論壇 過程略,大家自己測試 Apache:httpd(服務(wù)名) 80 (端口) Mysql: mysqld(服務(wù)名) 3306(端口,默認只對本地監(jiān)聽) php:在apache 中集成,只需添加啟用php默認文檔即可 lamp的日志等功能,建議查看相關(guān)文檔 建議安裝lamp為了讓入門童鞋更加容易了解lamp,生產(chǎn)環(huán)境要根據(jù)實際情況安裝不通的組件。

LAMP,so easy?。?!


新聞標題:Linux下搭建LAMP具體方法
本文來源:http://www.dlmjj.cn/article/dpcsphh.html