您的位置:首页 > 产品设计 > 产品经理

LAMP环境搭建之rpm软件包

2013-08-27 13:58 393 查看
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 #建立挂载点并挂载光盘
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源为本地的光盘软件包Server目录
enabled=1 #允许
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release # 本地光盘的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
--> Running transaction check
---> 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) <security@redhat.com>" from/mnt/cdrom/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
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
130826 15:44:01 [Warning] option 'max_join_size':unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables...
130826 15:44:01 [Warning] option 'max_join_size':unsigned value 18446744073709551615 adjusted to 4294967295
130826 15:44:01 [Warning] option 'max_join_size':unsigned value 18446744073709551615 adjusted to 4294967295
OK

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 testdatabases and anonymous user created bydefault. This isstrongly 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.plcd 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 athttp://www.mysql.comSupport 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()
?>



上面就是我们建立的php站点页面,显示有关php的版本信息,说明http与php结合正确[root@localhost html]# vim index.php #再次编写一个连接数据库的文件,测试mysql与php结合是否可用,如果连接成功输出“ok”否则输出“not”<?php$link=mysql_connect('127.0.0.1','root','root');if ($link)echo "ok";elseecho "not";?>


[root@localhost html]# service mysqld stop #关闭mysql服务,查看测试页Stopping MySQL: [ OK ]

上面的访问显示页面证明http、php与mysql三者结合是正确的,LAMP环境搭建完毕。案例1discuz论坛安装[root@localhost ~]# lltotal 10328drwxr-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.syslogdrwxr-xr-x 2 root root 4096 Aug 2 14:17 readmedrwxr-xr-x 12 root root 4096 Aug 2 14:17 uploaddrwxr-xr-x 4 root root 4096 Aug 2 14:17 utility[root@localhost ~]# mv ./upload//var/www/html/discus 将网站目录上传到站点默认主目录





[root@localhost html]# service httpd restart #重启httpd服务再次查看安装页面Stopping httpd: [ OK ]Starting httpd: [ OK ]


检测安装环境是否符合要求



[root@localhost discuz]# ls -a
. archiver data index.php portal.php template.. config favicon.ico install robots.txt uc_clientadmin.php connect.php forum.php member.php search.php uc_serverapi cp.php group.php misc.php source userapp.phpapi.php crossdomain.xml home.php plugin.php static [root@localhostdiscuz]# chmod -R a+w config data uc_client uc_server 这些目录要求可写入,为了目录安全性,我们只需将安装环境需要可写入的目录设置为可写,由于我们是做实验,我们就简化这些操作,不再一一修改权限。
再次检测安装环境



安装数据库需要我们添加相关信息,如果某些参数填写与实际不符,必将产生错误。


安装数据库


安装完成



论坛主页


登录论坛后台(管理中心)


在论坛的后台可以任意添加修改板块以及其他众多设置

[root@localhost ~]# mysql -u root –p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 16Server 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 namesYou can turn off this feature to get aquicker startup with -A
Database changedmysql> 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 #拷贝样例配置文件进行修改,解决遇到的无法登录数据库的错误











登录页面出现“无法加载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 217521f6error: 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
warning: php-mcrypt-5.1.6-5.el5.i386.rpm:Header V3 DSA signature: NOKEY, key ID 217521f6Preparing... ########################################### [100%]
1:php-mcrypt ########################################### [100%]



解决mcrypt扩展,我们可以登录我们的数据库进行数据库管理了。


案例2wordpress博客网站[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.phpindex.php wp-comments-post.php wp-load.php wp-settings.phplicense.txt wp-commentsrss2.php wp-login.php wp-signup.phpreadme.html wp-config-sample.php wp-mail.php wp-trackback.phpwp-activate.php wp-content wp-pass.php xmlrpc.phpwp-admin wp-cron.php wp-rdf.phpwp-app.php wp-feed.php wp-register.php安装出现错误,需要实现配置wp-config.php配置文件,可以通过本页面建立,处于安全的考虑,最好是手动创建。

[root@localhost ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 87Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> create database wordpress; # 先创建我们博客网站的数据库Query OK, 1 row affected (0.00 sec) 再拷贝样例配置文件进行修改


首次访问博客网站,进行网站配置


wordpress博客网站配置完成



mysql> show databases; 查看博客网站的数据库+--------------------+| Database |+--------------------+| information_schema | | discuz | | mysql | | test | | wordpress | +--------------------+5 rows in set (0.00 sec)使用管理员身份进入博客网站后台,在后台可以管理模块以及其他众多设置。




查看我们的博客网站前台页面


如果看着这个页面没一点个性,那么我们可以再下载一些博客主题,将主题解压缩移动到博客网站的主题目录,再次访问即可实现更换主题的效果。[root@localhost wordpress]# llwp-content/themes/total 8-rw-r--r-- 1 root root 30 Feb 8 2011 index.phpdrwxr-xr-x 4 root root 4096 Feb 8 2011twentyten
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息