天天看點

LAMP環境搭建之rpm軟體包

Linux+Apache+Mysql+Perl/PHP/Python一組常用來搭建動态網站或者伺服器的開源軟體,本身都是各自獨立的程式,但是因為常被放在一起使用,擁有了越來越高的相容度,共同組成了一個強大的Web應用程式平台。随着開源潮流的蓬勃發展,開放源代碼的LAMP已經與J2EE和.Net商業軟體形成三足鼎立之勢,并且該軟體開發的項目在軟體方面的投資成本較低,是以受到整個IT界的關注。從網站的流量上來說,70%以上的通路流量是LAMP來提供的,LAMP是最強大的網站解決方案.

LAMP介紹

LAMP指的Linux(作業系統)、ApacheHTTP 伺服器,MySQL(資料庫軟體)和PHP(有時也是指Perl或Python)的第一個字母,一般用來建立web 伺服器。

雖然這些開放源代碼程式本身并不是專門設計成同另幾個程式一起工作的,但由于它們的免費和開源,這個組合開始流行(大多數Linux發行版本捆綁了這些軟體)。當一起使用的時候,它們表現的像一個具有活力的解決方案包。其他的方案包有蘋果的WebObjects(最初是應用伺服器),Java/J2EE和微軟的.NET架構。

LAMP包的腳本元件中包括了CGIweb接口,它在90年代初期變得流行。這個技術允許網頁浏覽器的使用者在伺服器上執行一個程式,并且和接受靜态的内容一樣接受動态的内容。程式員使用腳本語言來建立這些程式因為它們能很容易有效的操作文本流,甚至當這些文本流并非源自程式自身時也是。正是由于這個原因系統設計者經常稱這些腳本語言為膠水語言。

LAMP環境搭建

[root@localhost ~]# mkdir /mnt/cdrom

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom                    #建立挂載點并挂載CD光牒

mount: block device /dev/cdrom is write-protected,mounting read-only

[root@localhost ~]# vim/etc/yum.repos.d/rhel-debuginfo.repo        #修改yum配置檔案,能夠解決軟體包安裝之間的依賴關系

[root@localhost ~]# vim/etc/yum.repos.d/rhel-debuginfo.repo

[rhel-Server]

name=Red Hat Enterprise Linux Server

baseurl=file:///mnt/cdrom/Server/    #修改yum源為本地的CD光牒軟體包Server目錄

enabled=1                            #允許

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release     # 本地CD光牒的GPG校驗

[root@localhost ~]# yum install httpd mysql-servermysql php php-gb php-mysql

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

rhel-Server                                              |1.3 kB     00:00    

rhel-Server/primary                                      | 732 kB     00:00    

rhel-Server                                                          2292/2292

Setting up Install Process

No package php-gb available.

Resolving Dependencies

--> Running transaction check

---> Package httpd.i386 0:2.2.3-31.el5 set to be updated

rhel-Server/filelists                                    | 2.3MB     00:00    

---> Package mysql.i386 0:5.0.77-3.el5 set to beupdated

--> Processing Dependency: perl(DBI) for package:mysql

---> Package mysql-server.i386 0:5.0.77-3.el5 setto be updated

--> Processing Dependency: perl-DBD-MySQL forpackage: mysql-server

---> Package php.i386 0:5.1.6-23.2.el5_3 set to beupdated

--> Processing Dependency: php-cli =5.1.6-23.2.el5_3 for package: php

--> Processing Dependency: php-common = 5.1.6-23.2.el5_3for package: php

---> Package php-mysql.i386 0:5.1.6-23.2.el5_3 setto be updated

--> Processing Dependency: php-pdo for package:php-mysql

---> Package perl-DBD-MySQL.i386 0:3.0007-2.el5 setto be updated

---> Package perl-DBI.i386 0:1.52-2.el5 set to beupdated

---> Package php-cli.i386 0:5.1.6-23.2.el5_3 set tobe updated

---> Package php-common.i386 0:5.1.6-23.2.el5_3 setto be updated

---> Package php-pdo.i386 0:5.1.6-23.2.el5_3 set tobe updated

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package              Arch       Version                Repository         Size

Installing:

httpd                i386       2.2.3-31.el5           rhel-Server       1.2 M

mysql                i386       5.0.77-3.el5           rhel-Server       4.8 M                                        #安裝mysql工具包

mysql-server         i386       5.0.77-3.el5           rhel-Server       9.8 M                                        #安裝mysql-server伺服器

php                 i386       5.1.6-23.2.el5_3       rhel-Server       1.1 M

php-mysql            i386       5.1.6-23.2.el5_3       rhel-Server        85 k                                          #安裝php與mysql的連接配接包

Installing for dependencies:                                #檢測依賴關系

perl-DBD-MySQL       i386       3.0007-2.el5           rhel-Server       147 k

perl-DBI             i386       1.52-2.el5             rhel-Server       605 k

php-cli              i386       5.1.6-23.2.el5_3       rhel-Server       2.1 M

php-common           i386       5.1.6-23.2.el5_3       rhel-Server       151 k

php-pdo              i386       5.1.6-23.2.el5_3       rhel-Server        64 k

Transaction Summary

Install     10Package(s)        

Update       0Package(s)        

Remove       0Package(s)        

Total download size: 20 M

Is this ok [y/N]: y

Downloading Packages:

--------------------------------------------------------------------------------

Total                                           3.0GB/s |  20 MB     00:00    

warning: rpmts_HdrFromFdno: Header V3 DSA signature:NOKEY, key ID 37017186

rhel-Server/gpgkey                                       | 1.1 kB     00:00    

Importing GPG key 0x37017186 "Red Hat, Inc.(release key) <[email protected]>" from/mnt/cdrom/RPM-GPG-KEY-redhat-release

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing     :php-common                                             1/10

Installing     :perl-DBI                                               2/10

Installing     :mysql                                                   3/10

Installing     :perl-DBD-MySQL                                          4/10

Installing     :php-pdo                                                5/10

Installing     :php-cli                                                 6/10

Installing     :httpd                                                  7/10

Installing     :mysql-server                                           8/10

Installing     :php                                                    9/10

Installing     :php-mysql                                             10/10

Installed:

httpd.i386 0:2.2.3-31.el5                 mysql.i386 0:5.0.77-3.el5          

mysql-server.i386 0:5.0.77-3.el5          php.i386 0:5.1.6-23.2.el5_3        

php-mysql.i386 0:5.1.6-23.2.el5_3        

Dependency Installed:

perl-DBD-MySQL.i386 0:3.0007-2.el5     perl-DBI.i386 0:1.52-2.el5            

php-cli.i386 0:5.1.6-23.2.el5_3        php-common.i386 0:5.1.6-23.2.el5_3    

php-pdo.i386 0:5.1.6-23.2.el5_3      

Complete!

[root@localhost ~]# service httpd start                    # 啟動httpd服務

Starting httpd:                                           [  OK  ]

[root@localhost ~]# chkconfig httpd on                     # 将httpd服務加入開機啟動項

[root@localhost ~]# service mysqld start                   #  啟動mysql服務

Initializing MySQL database:  Installing MySQL system tables...

130826 15:44:01 [Warning] option 'max_join_size':unsigned value 18446744073709551615 adjusted to 4294967295

OK

Filling help tables...

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for yoursystem

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL rootUSER !

To do so, start the server, then issue thefollowing commands:

/usr/bin/mysqladmin -u root password'new-password'

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

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

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 withmysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

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

The latest information about MySQL isavailable on the web at

http://www.mysql.com

Support MySQL by buying support/licenses athttp://shop.mysql.com

                                                         [  OK  ]

Starting MySQL:                                           [  OK  ]

[root@localhost ~]# netstat -tupln |grep mysqld      #mysql服務的端口是3306

tcp     0     0 0.0.0.0:3306    0.0.0.0:*      LISTEN     4970/mysqld        

[root@localhost ~]# chkconfig mysqld on              #将mysqld服務加入開機啟動項

[root@localhost ~]# mysqladmin -u root -p password'root'                #出于對資料庫安Enter password:                                       全性的考慮,對資料庫通路設定密碼

[root@localhost ~]# cd /var/www/html/

You have mail in /var/spool/mail/root

[root@localhost html]# ll

total 0

[root@localhost html]# vim index.php        # 測試http與php的結合使用效果,進入網站主目錄建立簡單的頁面,使用php參數,在頁面顯示php相關資訊

<?php

Phpinfo()

?>

LAMP環境搭建之rpm軟體包

上面就是我們建立的php站點頁面,顯示有關php的版本資訊,說明http與php結合正确

[root@localhost html]# vim index.php      #再次編寫一個連接配接資料庫的檔案,測試mysql與php結合是否可用,如果連接配接成功輸出“ok”否則輸出“not”

$link=mysql_connect('127.0.0.1','root','root');

if ($link)

echo "ok";

else

echo "not";

LAMP環境搭建之rpm軟體包

[root@localhost html]# service mysqld stop                #關閉mysql服務,檢視測試頁

Stopping MySQL:                                           [  OK  ]

上面的通路顯示頁面證明http、php與mysql三者結合是正确的,LAMP環境搭建完畢。

案例1:discuz論壇安裝

[root@localhost ~]# ll

total 10328

drwxr-xr-x 2 root root     4096 Jul 10 17:24Desktop

-rw-r--r-- 1 root root 10485407 Aug 26 16:38 Discuz_X3.0_SC_GBK.zip

-rw------- 1 root root     1176 Jul 11 01:19anaconda-ks.cfg

-rw-r--r-- 1 root root    35236 Jul 11 01:19install.log

-rw-r--r-- 1 root root     3995 Jul 11 01:17install.log.syslog

drwxr-xr-x 2 root root     4096 Aug  2 14:17 readme

drwxr-xr-x 12 root root     4096 Aug 2 14:17 upload

drwxr-xr-x 4 root root     4096 Aug  2 14:17 utility

[root@localhost ~]# mv ./upload//var/www/html/discus             将網站目錄上傳到站點預設主目錄

LAMP環境搭建之rpm軟體包
LAMP環境搭建之rpm軟體包

[root@localhost html]# service httpd restart            #重新開機httpd服務再次檢視安裝頁面

Stopping httpd:                                             [  OK  ]

Starting httpd:                                             [  OK  ]

LAMP環境搭建之rpm軟體包

檢測安裝環境是否符合要求

LAMP環境搭建之rpm軟體包

[root@localhost discuz]# ls -a

.         archiver         data         index.php   portal.php template

..        config           favicon.ico  install    robots.txt  uc_client

admin.php connect.php      forum.php    member.php search.php  uc_server

api       cp.php           group.php    misc.php   source      userapp.php

api.php   crossdomain.xml  home.php     plugin.php static

[root@localhostdiscuz]# chmod -R a+w config data uc_client uc_server        這些目錄要求可寫入,為了目錄安全性,我們隻需将安裝環境需要可寫入的目錄設定為可寫,由于我們是做實驗,我們就簡化這些操作,不再一一修改權限。

再次檢測安裝環境

LAMP環境搭建之rpm軟體包

安裝資料庫需要我們添加相關資訊,如果某些參數填寫與實際不符,必将産生錯誤。

LAMP環境搭建之rpm軟體包

安裝資料庫

LAMP環境搭建之rpm軟體包

安裝完成

LAMP環境搭建之rpm軟體包

論壇首頁

LAMP環境搭建之rpm軟體包

登入論壇背景(管理中心)

LAMP環境搭建之rpm軟體包

在論壇的背景可以任意添加修改闆塊以及其他衆多設定

LAMP環境搭建之rpm軟體包

[root@localhost ~]# mysql -u root –p                        

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 16

Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' toclear the buffer.

mysql> show databases;                           # 檢視安裝discuz論壇産生的資料庫

+--------------------+

| Database           |

| information_schema |

| discuz             |

| mysql              |

| test               |

4 rows in set (0.00 sec)

mysql> use discuz;

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Database changed

mysql> show tables;                                #論壇資料庫共建立了286張表

+-----------------------------------+

| Tables_in_discuz                  |

| pre_common_admincp_cmenu          |

| pre_ucenter_notelist              |

| pre_ucenter_pm_indexes            |

| pre_ucenter_pm_lists              |

| pre_ucenter_pm_members            |

| pre_ucenter_pm_messages_0         |

| pre_ucenter_pm_messages_1         |

| pre_ucenter_pm_messages_2         |

| pre_ucenter_pm_messages_3         |

| pre_ucenter_pm_messages_4         |

| pre_ucenter_pm_messages_5         |

| pre_ucenter_pm_messages_6         |

| pre_ucenter_pm_messages_7         |

| pre_ucenter_pm_messages_8         |

| pre_ucenter_pm_messages_9         |

| pre_ucenter_protectedmembers      |

| pre_ucenter_settings              |

| pre_ucenter_sqlcache              |

| pre_ucenter_tags                  |

| pre_ucenter_vars                  |

286 rows in set (0.01 sec)

由于字元界面的管理資料庫有些麻煩,我們可以借助phpmyadmin在網頁上管理我們的資料庫。

[root@localhost ~]# mvphpMyAdmin-2.11.10.1-all-languages    /var/www/html/phpmyadmin         #将解壓後的phpmyadmin目錄移動到網站主目錄

[root@localhost ~]# cd/var/www/html/phpmyadmin/

[root@localhost phpmyadmin]# cp -pconfig.sample.inc.php config.inc.php     #拷貝樣例配置檔案進行修改,解決遇到的無法登入資料庫的錯誤

LAMP環境搭建之rpm軟體包
LAMP環境搭建之rpm軟體包
LAMP環境搭建之rpm軟體包

登入頁面出現“無法加載mcrypt擴充”,隻需将mcrypt的軟體包安裝即可

[root@localhost ~]# ls

libmcrypt-2.5.7-5.el5.i386.rpm                php-mcrypt-5.1.6-5.el5.i386.rpm      Discuz_X3.0_SC_GBK.zip  readme

wordpress_v3.0.5-zh_CN.zip

[root@localhost~]# rpm -ivh php-mcrypt-5.1.6-5.el5.i386.rpm

warning: php-mcrypt-5.1.6-5.el5.i386.rpm:Header V3 DSA signature: NOKEY, key ID 217521f6

error: Failed dependencies:

      libmcrypt.so.4is needed by php-mcrypt-5.1.6-5.el5.i386

安裝出現依賴關系,先安裝依賴共享庫的軟體包

[root@localhost ~]# rpm -ivhlibmcrypt-2.5.7-5.el5.i386.rpm  

warning: libmcrypt-2.5.7-5.el5.i386.rpm: Header V3 DSAsignature: NOKEY, key ID 217521f6

Preparing...        ###########################################[100%]

1:libmcrypt         ########################################### [100%]

[root@localhost ~]# rpm -ivhphp-mcrypt-5.1.6-5.el5.i386.rpm

Preparing...         ########################################### [100%]

1:php-mcrypt         ########################################### [100%]

LAMP環境搭建之rpm軟體包

解決mcrypt擴充,我們可以登入我們的資料庫進行資料庫管理了。

LAMP環境搭建之rpm軟體包

案例2:wordpress部落格網站

[root@localhost ~]#unzip  wordpress_v3.0.5-zh_CN.zip

[root@localhost wordpress-3.0.5-zh_CN]# mvwordpress/ /var/www/html/wordpress                                                                      # 解壓網站檔案并上傳網站主目錄

[root@localhost wordpress-3.0.5-zh_CN]# cd/var/www/html/wordpress/

[root@localhost wordpress]# ls -a

.               wp-atom.php           wp-includes        wp-rss.php

..               wp-blog-header.php    wp-links-opml.php  wp-rss2.php

index.php        wp-comments-post.php  wp-load.php        wp-settings.php

license.txt      wp-commentsrss2.php   wp-login.php       wp-signup.php

readme.html      wp-config-sample.php  wp-mail.php        wp-trackback.php

wp-activate.php  wp-content            wp-pass.php        xmlrpc.php

wp-admin         wp-cron.php           wp-rdf.php

wp-app.php       wp-feed.php           wp-register.php

安裝出現錯誤,需要實作配置wp-config.php配置檔案,可以通過本頁面建立,處于安全的考慮,最好是手動建立。

LAMP環境搭建之rpm軟體包

[root@localhost ~]# mysql -u root -p

Your MySQL connection id is 87

mysql> create database wordpress;                   # 先建立我們部落格網站的資料庫

Query OK, 1 row affected (0.00 sec)                   再拷貝樣例配置檔案進行修改

LAMP環境搭建之rpm軟體包

首次通路部落格網站,進行網站配置

LAMP環境搭建之rpm軟體包

wordpress部落格網站配置完成

LAMP環境搭建之rpm軟體包

mysql> show databases;                                      檢視部落格網站的資料庫

| wordpress          |

5 rows in set (0.00 sec)

使用管理者身份進入部落格網站背景,在背景可以管理子產品以及其他衆多設定。

LAMP環境搭建之rpm軟體包
LAMP環境搭建之rpm軟體包

檢視我們的部落格網站前台頁面

LAMP環境搭建之rpm軟體包

如果看着這個頁面沒一點個性,那麼我們可以再下載下傳一些部落客題,将主題解壓縮移動到部落格網站的主題目錄,再次通路即可實作更換主題的效果。

[root@localhost wordpress]# llwp-content/themes/

total 8

-rw-r--r-- 1 root root   30 Feb 8  2011 index.php

drwxr-xr-x 4 root root 4096 Feb  8  2011twentyten

繼續閱讀