YUM方式安装LAMP

本文介绍两种方法yum安装LAMP,

方法1: 通过httpd的php模块方式安装LAMP

方法2: 通过php-fpm方式安装LAMP

安装环境:CentOS Linux release 7.5.1804

方法1: 通过httpd的php模块方式安装LAMP

安装程序包:

# yum -y install httpd php php-mysql mariadb-server

启动服务:

# systemctl start mariadb

# systemctl start httpd

方法2: 通过php-fpm方式安装LAMP

安装程序包:

# yum -y install httpd php-fpm php-mysql mariadb-server

修改httpd配置

# vim /etc/httpd/conf/httpd.conf
修该配置增加index.php字段
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

在文件末尾新增下面5行配置
IncludeOptional conf.d/*.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

启动服务

# systemctl start mariadb

# systemctl start php-fpm

# systemctl start httpd

测试LAMP是否正常安装

1、测试PHP连通性

# vim /var/www/html/index.php
<?php
       phpinfo();
?>

访问主页进行测试

2、测试PHP和mysql的连通性

修改数据库root的密码
# mysqladmin -uroot password "123456"

修改index.php页面信息
# vim /var/www/html/index.php
<?php
  $link = mysql_connect('localhost','root','123456');
  if ($link)
    echo "Link to mysql success..";
  else
    echo "Link to mysql failure..";
  mysql_close();
?>

访问主页进行测试mysql联通性
原文地址:https://www.cnblogs.com/ysuwangqiang/p/11921794.html