安装lamp服务器系统,LAMP安装环境搭建详解

实现LAMP

1.LAMP工作原理

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

2d8eec79af64cb87c3e04666742c2636.png

工作过程:

148562.htm

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

修改或添加下面内容

DirectoryIndex index.php index.html

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

添加修改下面行

DirectoryIndex index.php index.html

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

修改下面行

DirectoryIndex index.php index.html

systemctl restart httpd

systemctl start php-fpm

4>测试配置的LAMP是否成功

vim /var/www/html/index.php

It works!

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();

?>

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值