LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。
下面我们便开始lamp环境的搭建,及lamp的应用。 为方便我们后续软件包的安装, 配置本地yum: [root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo [rhel-server] name=Red Hat Enterprise Linux server baseurl=file:///mnt/cdrom/Server enabled=1 gpgcheck=1 gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release yum配置完成,开始lamp环境搭建:查看相关的软件包:[root@localhost ~]# yum list all |grep -E "httpd|mysql|php" 然后来安装我们所需的软件包:[root@localhost ~]# yum install httpd mysql mysql-server php php-mysql php-gd php-mbstring php-xml 接下来便要开启相关服务:[root@localhost ~]# service httpd start启动 httpd: [确定][root@localhost ~]# service mysqld start 设置开机启动:[root@localhost ~]# chkconfig httpd on[root@localhost ~]# chkconfig mysqld on[root@localhost ~]#同时还可以查看我们的mysql服务的端口:[root@localhost ~]# netstat -tupln |grep mysqld 我们可以尝试进入数据库,初始默认root,密码为空。[root@localhost ~]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show databases; //查看所有数据库+--------------------+| Database |+--------------------+| information_schema || mysql | | test | +--------------------+3 rows in set (0.00 sec) mysql>mysql> use mysql; //使用数据库(此处使用mysql数据库)Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A Database changedmysql> show tables; //查看该数据库所有表(mysql数据库下的所有表)+---------------------------+| Tables_in_mysql |+---------------------------+| columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | proc | | procs_priv | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type || user | +---------------------------+17 rows in set (0.00 sec) mysql>mysql> \q; //退出数据库操作界面Bye[root@localhost ~]# 为我们的root账号配置密码:[root@localhost ~]# mysqladmin -u root -p password '123' 配置新密码为 123Enter password: 注意:此处要输入的是旧密码,为空,我们直接回车即可。[root@localhost ~]# 然后便可以在进入试试,看看密码是否已经生效:[root@localhost ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> 如图示,密码已经生效。然后,进入/var/www/html目录下,编辑index.php文件[root@localhost html]# vim index.php<?phpphpinfo();?>~ 然后我们便在宿主机上看看能不能访问到这个页面:在宿主机浏览器或运行里输入虚拟机的ip: 如上图,我们已经能够查看php的相关信息了。接下来进行进一步的测试:重新编辑我们的index.php文件:[root@localhost html]# vim index.php<?php$link=mysql_connect('127.0.0.1','root','123');if($link)echo "ok";elseecho "not";?> 然后再进行上面的操作,在宿主机上: 如上图所示,成功访问。当我们关闭mysqld服务时,就不能访问了。如下图: 我们这部分的测试已经结束了,接下来安装phpmyadmin(注意版本匹配问题),图形化管理。如下图所示,我们的root/目录下已经有了相关软件包: 解压缩:拆解到当前目录,然后移动到/var/www/html/phpmyadmin[root@localhost ~]# unzip phpMyAdmin-2.11.10.1-all-languages.zip[root@localhost ~]# mv phpMyAdmin-2.11.10.1-all-languages /var/www/html/phpmyadmin[root@localhost ~]# 在我们的浏览器里访问http://192.168.44.127/phpmyadmin出现了如下页面:解决上面问题的办法: 先拷贝我们的阳样例文件,命名为config.inc.php,然后修改config.inc.php文件 [root@localhost phpmyadmin]# cp -p config.sample.inc.php config.inc.php 修改第十七行,引号之间的内容可以随便填:
保存退出后, 重启我们的apache服务: [root@localhost phpmyadmin]# service httpd restart 停止 httpd: [确定] 启动 httpd: [确定] [root@localhost phpmyadmin]# 刷新我们刚才的页面,便么有问题了。(如果不行,请清理浏览器的缓存)
可以发现页面下方还报有一个小错误,无法载入mcrypt扩展。 那么我们便要安装mcrypt安装包 [root@localhost ~]# rpm -ivh libmcrypt-2.5.7-5.el5.i386.rpm //该包为关联包 warning: libmcrypt-2.5.7-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6 Preparing... ########################################### [100%] 1:libmcrypt ########################################### [100%] [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 Preparing... ########################################### [100%] 1:php-mcrypt ########################################### [100%] [root@localhost ~]# 然后我们再去刷新之前的页面,便可以发现没有问题了:
然后我们登录进去,root用户,密码123.
进入图形化管理界面,我们可以随意创建一个数据库,假设我们创建一个论坛的数据库discuz。
如图示,我们已经成功创建discuz数据库。
搭建好lamp环境之后,我们便可以进入实际应用过程了: 假设我们搭建一个论坛, 请自行到discuz官网下载最新压缩包, 在我们的root目录下已经有Discuz_X2.5_SC_GBK.zip了:(我们在此处使用的是discuz,同样流行的还有phpwind以及国外的wordpress,使用方法大同小异)
解压缩到/var/www/html/mybbs目录下 [root@localhost ~]# unzip Discuz_X2.5_SC_GBK.zip -d /var/www/html/mybbs 进入/var/www/html/mybbs目录下查看
然后我们可以试图直接访问index.php页面:
如上图所示,能成功访问,但是因为编码格式,会出现乱码问题。 我们需要修改etc/httpd/conf目录下的httpd.conf文件 将UTF-8字符集禁掉(可以在滴行命令模式下搜索UTF:”:/UTF”) 然后重启apache服务: [root@localhost upload]# vim /etc/httpd/conf/httpd.conf
[root@localhost upload]# service httpd restart 停止 httpd: [确定] 启动 httpd: [确定] [root@localhost upload]# 然后我们重新访问,便不会出现编码问题了:
进入安装向导,可以看到很详细的安装步骤。 但是因为权限问题,会出现如下提示:
那么我们便去修改相关目录的权限: [root@localhost upload]# chmod -R o+w data //-R参数为递归修改 [root@localhost upload]# chmod -R o+w config [root@localhost upload]# chmod -R o+w uc_client/ [root@localhost upload]# chmod -R o+w uc_server/ [root@localhost upload]#
然后刷新我们的页面,便可以正常进行了:
成功安装后,我们可以进入mysql查看一下: [root@localhost upload]# 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' to clear the buffer. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | discuz | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> use discuz; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +--------------------------------------+ | Tables_in_discuz | +--------------------------------------+ | discuz_common_admincp_cmenu | | discuz_common_admincp_group | | discuz_common_admincp_member | | discuz_common_admincp_perm | | discuz_common_admincp_session | | discuz_common_admingroup | | discuz_common_adminnote | | discuz_common_advertisement | | discuz_common_advertisement_custom | | discuz_common_banned | | discuz_common_block | | discuz_common_block_favorite | | discuz_common_block_item | | discuz_common_block_item_data | | discuz_common_block_permission | | discuz_common_block_pic | | discuz_common_block_style | | discuz_common_block_xml | | discuz_common_cache | | discuz_common_card | | discuz_common_card_log | | discuz_common_card_type | | discuz_common_connect_guest | | discuz_common_credit_log | | discuz_common_credit_rule | | discuz_common_credit_rule_log | | discuz_common_credit_rule_log_field | | discuz_common_cron | | discuz_common_devicetoken | | discuz_common_district | | discuz_common_diy_data | | discuz_common_domain | | discuz_common_failedlogin | | discuz_common_friendlink | | discuz_common_grouppm | | discuz_common_invite | | discuz_common_magic | | discuz_common_magiclog | | discuz_common_mailcron | | discuz_common_mailqueue | | discuz_common_member | | discuz_common_member_action_log | | discuz_common_member_connect | | discuz_common_member_count | | discuz_common_member_crime | | discuz_common_member_field_forum | | discuz_common_member_field_home | | discuz_common_member_grouppm | | discuz_common_member_log | | discuz_common_member_magic | | discuz_common_member_medal | | discuz_common_member_profile | | discuz_common_member_profile_setting | | discuz_common_member_security | | discuz_common_member_stat_field | | discuz_common_member_status | | discuz_common_member_validate | | discuz_common_member_verify | | discuz_common_member_verify_info | | discuz_common_myapp | | discuz_common_myinvite | | discuz_common_mytask | | discuz_common_nav | | discuz_common_onlinetime | | discuz_common_patch | | discuz_common_plugin | | discuz_common_pluginvar | | discuz_common_process | | discuz_common_regip | | discuz_common_relatedlink | | discuz_common_report | | discuz_common_searchindex | | discuz_common_secquestion | | discuz_common_session | | discuz_common_setting | | discuz_common_smiley | | discuz_common_sphinxcounter | | discuz_common_stat | | discuz_common_statuser | | discuz_common_style | | discuz_common_stylevar | | discuz_common_syscache | | discuz_common_tag | | discuz_common_tagitem | | discuz_common_task | | discuz_common_taskvar | | discuz_common_template | | discuz_common_template_block | | discuz_common_template_permission | | discuz_common_uin_black | | discuz_common_usergroup | | discuz_common_usergroup_field | | discuz_common_word | | discuz_common_word_type | | discuz_connect_disktask | | discuz_connect_feedlog | | discuz_connect_memberbindlog | | discuz_connect_postfeedlog | | discuz_connect_tthreadlog | | discuz_forum_access | | discuz_forum_activity | | discuz_forum_activityapply | | discuz_forum_announcement | | discuz_forum_attachment | | discuz_forum_attachment_0 | | discuz_forum_attachment_1 | | discuz_forum_attachment_2 | | discuz_forum_attachment_3 | | discuz_forum_attachment_4 | | discuz_forum_attachment_5 | | discuz_forum_attachment_6 | | discuz_forum_attachment_7 | | discuz_forum_attachment_8 | | discuz_forum_attachment_9 | | discuz_forum_attachment_exif | | discuz_forum_attachment_unused | | discuz_forum_attachtype | | discuz_forum_bbcode | | discuz_forum_collection | | discuz_forum_collectioncomment | | discuz_forum_collectionfollow | | discuz_forum_collectioninvite | | discuz_forum_collectionrelated | | discuz_forum_collectionteamworker | | discuz_forum_collectionthread | | discuz_forum_creditslog | | discuz_forum_debate | | discuz_forum_debatepost | | discuz_forum_faq | | discuz_forum_forum | | discuz_forum_forum_threadtable | | discuz_forum_forumfield | | discuz_forum_forumrecommend | | discuz_forum_groupcreditslog | | discuz_forum_groupfield | | discuz_forum_groupinvite | | discuz_forum_grouplevel | | discuz_forum_groupuser | | discuz_forum_imagetype | | discuz_forum_medal | | discuz_forum_medallog | | discuz_forum_memberrecommend | | discuz_forum_moderator | | discuz_forum_modwork | | discuz_forum_onlinelist | | discuz_forum_order | | discuz_forum_poll | | discuz_forum_polloption | | discuz_forum_pollvoter | | discuz_forum_post | | discuz_forum_post_location | | discuz_forum_post_moderate | | discuz_forum_post_tableid | | discuz_forum_postcache | | discuz_forum_postcomment | | discuz_forum_postlog | | discuz_forum_poststick | | discuz_forum_promotion | | discuz_forum_ratelog | | discuz_forum_relatedthread | | discuz_forum_replycredit | | discuz_forum_rsscache | | discuz_forum_spacecache | | discuz_forum_statlog | | discuz_forum_thread | | discuz_forum_thread_moderate | | discuz_forum_threadaddviews | | discuz_forum_threadclass | | discuz_forum_threadclosed | | discuz_forum_threaddisablepos | | discuz_forum_threadimage | | discuz_forum_threadlog | | discuz_forum_threadmod | | discuz_forum_threadpartake | | discuz_forum_threadpreview | | discuz_forum_threadrush | | discuz_forum_threadtype | | discuz_forum_trade | | discuz_forum_tradecomment | | discuz_forum_tradelog | | discuz_forum_typeoption | | discuz_forum_typeoptionvar | | discuz_forum_typevar | | discuz_forum_warning | | discuz_home_album | | discuz_home_album_category | | discuz_home_appcreditlog | | discuz_home_blacklist | | discuz_home_blog | | discuz_home_blog_category | | discuz_home_blog_moderate | | discuz_home_blogfield | | discuz_home_class | | discuz_home_click | | discuz_home_clickuser | | discuz_home_comment | | discuz_home_comment_moderate | | discuz_home_docomment | | discuz_home_doing | | discuz_home_doing_moderate | | discuz_home_favorite | | discuz_home_feed | | discuz_home_feed_app | | discuz_home_follow | | discuz_home_follow_feed | | discuz_home_follow_feed_archiver | | discuz_home_friend | | discuz_home_friend_request | | discuz_home_friendlog | | discuz_home_notification | | discuz_home_pic | | discuz_home_pic_moderate | | discuz_home_picfield | | discuz_home_poke | | discuz_home_pokearchive | | discuz_home_share | | discuz_home_share_moderate | | discuz_home_show | | discuz_home_specialuser | | discuz_home_userapp | | discuz_home_userappfield | | discuz_home_visitor | | discuz_mobile_setting | | discuz_portal_article_content | | discuz_portal_article_count | | discuz_portal_article_moderate | | discuz_portal_article_related | | discuz_portal_article_title | | discuz_portal_article_trash | | discuz_portal_attachment | | discuz_portal_category | | discuz_portal_category_permission | | discuz_portal_comment | | discuz_portal_comment_moderate | | discuz_portal_rsscache | | discuz_portal_topic | | discuz_portal_topic_pic | | discuz_security_evilpost | | discuz_security_eviluser | | discuz_security_failedlog | | discuz_ucenter_admins | | discuz_ucenter_applications | | discuz_ucenter_badwords | | discuz_ucenter_domains | | discuz_ucenter_failedlogins | | discuz_ucenter_feeds | | discuz_ucenter_friends | | discuz_ucenter_mailqueue | | discuz_ucenter_memberfields | | discuz_ucenter_members | | discuz_ucenter_mergemembers | | discuz_ucenter_newpm | | discuz_ucenter_notelist | | discuz_ucenter_pm_indexes | | discuz_ucenter_pm_lists | | discuz_ucenter_pm_members | | discuz_ucenter_pm_messages_0 | | discuz_ucenter_pm_messages_1 | | discuz_ucenter_pm_messages_2 | | discuz_ucenter_pm_messages_3 | | discuz_ucenter_pm_messages_4 | | discuz_ucenter_pm_messages_5 | | discuz_ucenter_pm_messages_6 | | discuz_ucenter_pm_messages_7 | | discuz_ucenter_pm_messages_8 | | discuz_ucenter_pm_messages_9 | | discuz_ucenter_protectedmembers | | discuz_ucenter_settings | | discuz_ucenter_sqlcache | | discuz_ucenter_tags | | discuz_ucenter_vars | +--------------------------------------+ 271 rows in set (0.00 sec) mysql> \q Bye [root@localhost upload]# 没有问题,那么接下来我们试试看 可不可以访问了:
如上图所示,成功访问。 我们以管理员身份登录,便可以在该页面对搭建的论坛进行操作了。
至于discuz的使用,编者就不在此赘述了,读者可以自行摸索。
本文出自 “清浅时光彼岸流年” 博客,请务必保留此出处http://6764177.blog.51cto.com/6754177/1177637