设为首页 加入收藏

TOP

实现LAMP(一)
2017-10-16 18:18:50 】 浏览:1452
Tags:实现 LAMP

实现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();
    ?>

3.脚本实现源码编译安装LAMP

这是将编译安装实现LAMP的操作写成脚本,通过脚本来实现快速实现。

1)实现环境条件

1》因为这是一个脚本,所以用一台主机来直接实现LAMPM。当然,也可以把脚本分成几个模块,就如同分为centos6和7一样,可以把每个功能分别独立设立为模块,然后需要那个就调用那个应用来配合完成,这样修改或排错的时候更清晰。
2》在主机上使用iptables -F关闭防火墙,使用setenforce 0来暂时设置selinux为permisive,或者配置/etc/selinux/config来设置selinux为disable或permisive。

2)所需的软件包

软件包的版本可以根据需要来进行选择。且需要先创建个/app的目录,把所有软件包都放到这个目录下。
centos7

apr-
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇linux_base_commond_two 下一篇在ubuntu16.04中安装apache2+mods..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目