当前位置:Gxlcms > PHP教程 > Linux6下yum方式安装配置LAMP平台

Linux6下yum方式安装配置LAMP平台

时间:2021-07-01 10:21:17 帮助过:3人阅读

Linux下搭建LAMP是经典的不能再经典的中小企业站点构建平台。它的全称是Linux+Apache+Mysql+PHP,常用来搭建动态网站,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。因此在网络上也有比叫有名的LAMP一键安装解决方案。但是对于运维人员来讲,有必要了解其完成的安装过程。本文主要描述基于CentOS 6 下使用yum方式来快速构建LAMP平台(Linux安装忽略)。

一、准备yum源(本文使用了163镜像)

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos.d/# yum clean all# yum makecache

二、安装apache httpd

详细可以参考:Linux下安装Apache httpd

###检查是否已安装httpd# rpm -qa|grep httpd        httpd-tools-2.2.15-45.el6.centos.x86_64        httpd-2.2.15-45.el6.centos.x86_64# yum -y install httpd   ###此时我们看到httpd的小版本从45变成了53# rpm -qa|grep httpd        httpd-tools-2.2.15-53.el6.centos.x86_64        httpd-2.2.15-53.el6.centos.x86_64###查询生成的相关配置文件# rpm -qc httpd|grep conf        /etc/httpd/conf.d/welcome.conf        /etc/httpd/conf/httpd.conf        /etc/httpd/conf/magic        /etc/sysconfig/htcacheclean        /etc/sysconfig/httpd###启动httpd# /etc/init.d/httpd start        Starting httpd:                                            [  OK  ]# netstat -nltp|grep 80        tcp        0      0 :::80          :::*      LISTEN      7621/httpd###验证web服务# curl -I http://localhost        HTTP/1.1 403 Forbidden        Date: Tue, 12 Jul 2016 09:25:15 GMT        Server: Apache/2.2.15 (CentOS)        Accept-Ranges: bytes        Content-Length: 4961        Connection: close        Content-Type: text/html; charset=UTF-8###编写一个php页面测试# echo "> > 

This is a php test page.

> > phpinfo();> ?>> ">>/var/www/html/index.php ###测试
结果为phpinfo函数没有被解释# curl http://localhost/index.php

This is a php test page.

phpinfo(); ?>

三、安装php

###安装php,同时会安装依赖包# yum install php
        Installing:
         php                      x86_64     5.3.3-47.el6      base     1.1 M
        Installing for dependencies:
         php-cli                  x86_64     5.3.3-47.el6      base     2.2 M
         php-common               x86_64     5.3.3-47.el6      base     530 k

###查看php安装清单 # rpm -ql php
        /etc/httpd/conf.d/php.conf
        /usr/lib64/httpd/modules/libphp5.so
        /var/lib/php/session
        /var/www/icons/php.gif 

###查看php的配置文件 # grep -vE "^#|^$" /etc/httpd/conf.d/php.conf 
        
          LoadModule php5_module modules/libphp5.so
        
        
          LoadModule php5_module modules/libphp5-zts.so
        
        AddHandler php5-script .php
        AddType text/html .php
        DirectoryIndex index.php

###在上面的配置文件中,由于php以模块化方式与httpd结合工作,根据httpd的mpm模式不同,###其所需要的php模块格式有所不同;    prefork模式使用libphp5模块    worker和event模式则使用libphp5-zts模块###重启httpd已使得php模块生效# /etc/init.d/httpd configtest
        Syntax OK

# /etc/init.d/httpd restart
        Stopping httpd:                 [  OK  ]
        Starting httpd:                 [  OK  ]

###验证php模块已经被加载# httpd -M |grep php
        php5_module (shared)

###验证php页面 # curl http://localhost/index.php|more
        
        

This is a php test page.

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""DTD/xhtml1-transitional.dtd">