手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

LAMP安装环境搭建详解

[日期:2017-11-13] 来源:www.cnblogs.com/shenxm  作者:shenxm [字体: ]

实现LAMP

1.LAMP工作原理

LAMP是一个强大的Web应用程序平台,其中L是指linux系统;A是指apache也就是http;M一般是MySQL/mariadb数据库;P一般是php, perl, Python其中之一。

工作过程:

1》当客户端请求的是静态资源时,web服务器会直接把静态资源返回客户端;
2》当客户端请求的是动态资源时,httpd的php模块会进行相应的动态资源运算,如果此过程还需要数据库的数据作为运算参数时,php会连接mysql取得数据然后进行运算,运算的结果转为静态资源并由web服务器返回到客户端。

2.使用yum安装实现LAMP

1)实现环境条件

1》需要两天主机,一台实现LAP,另一台实现M.
2》在两台主机上使用iptables -F关闭防火墙,使用setenforce 0来暂时设置selinux为permisive,或者配置/etc/selinux/config来设置selinux为disable或permisive。

2)所需安装的程序包

CentOS6需要:httpd、php、php-mysql、mysql、mysql-server、mysql-libs
centos7需要:httpd、php-fpm(or php)、php-mysql、mariadb、mariadb-server、mariadb-libs

3)centos6和7上实现

1>安装httpd并开启

centos6上配置为

yum install httpd
chkconfig httpd on
chkconfig --list httpd
service httpd start
service httpd status

centos7上配置为

yum install httpd
systemctl enable httpd
systemctl start httpd
systemctl status httpd
2>安装mysql并开启

centos6上配置为

yum install mysql mysql-server mysql-libs
chkconfig mysqld on
chkconfig --list mysqld
service mysqld start
service mysqld status
/usr/bin/mysql_secure_installation
mysql -uroot -pxm1234
mysql>create user "shenxm"@'%' identified by 'xm1234';

centos7上配置为

yum install mariadb mariadb-libs mariadb-server
systemctl enable mariadb
systemctl start mariadb
systemctl status  mariadb
/usr/bin/mysql_secure_installation
mysql -uroot -pxm1234
MariaDB [(none)]>create user "shenxm"@'%' identified by 'xm1234';
3>安装php相关包

centos6上配置为

yum install  php php-mysql
vim /etc/httpd/conf/httpd.conf
    在文件尾部加两行
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
    修改或添加下面内容
        <IfModule dir_module>
            DirectoryIndex index.php index.html
        </IfModule>
service httpd restart

centos7上配置为

下面模式二选一
1)modules:
    yum install php php-mysql
    vim /etc/httpd/conf/httpd.conf
        在文件尾部加两行
            AddType application/x-httpd-php .php
            AddType application/x-httpd-php-source .phps
        添加修改下面行
            <IfModule dir_module>
                DirectoryIndex index.php index.html
            </IfModule>
    systemctl restart httpd
2)fastcgi:
    yum install php-fpm php-mysql
    vim /etc/httpd/conf/httpd.conf
        在文件尾部加四行
            AddType application/x-httpd-php .php
            AddType application/x-httpd-php-source .phps
            ProxyRequests Off 
            ProxyPassMatch  ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
        修改下面行
            <IfModule dir_module>
                DirectoryIndex index.php index.html
            </IfModule>
    systemctl restart httpd
    systemctl start php-fpm
4>测试配置的LAMP是否成功
vim /var/www/html/index.php
    <html><body><h1>It works!</h1></body></html>
    <?php
    echo date("Y/m/d h:i:s");
    $mysqli=new mysqli("192.168.213.252","wpuser","xm1234");
    if(mysqli_connect_errno()){
    echo "连接数据库失败!";
    $mysqli=null;
    exit;
    }
    echo "连接数据库成功!";
    $mysqli->close();
    phpinfo();
    ?>

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2017-11/148562p2.htm

linux
相关资讯       lamp  LAMP环境搭建  LAMP安装 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款