CentOS 7.x 安装LAMP

Posted ponfey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7.x 安装LAMP相关的知识,希望对你有一定的参考价值。

CentOS 7.x 安装apache
[[email protected] ~]#yum -y install httpd httpd-devel
[[email protected] ~]# systemctl start  httpd
[[email protected] ~]# systemctl enable  httpd
 
CentOS 7.x 安装 Mariadb 数据库
[[email protected] ~]# yum -y install mariadb mariadb-server mariadb-libs mariadb-devel
[[email protected] ~]# systemctl start mariadb [[email protected] ~]# systemctl enable mariadb
数据库安全设置:
[[email protected] ~]# mysql_secure_installation
登陆数据库:
[[email protected] ~]# mysql -uroot -p
 
Centos7.x 使用yum安装php7
1.安装epel-release 
通过命令: 
yum -y install epel-release 
成功安装。 
2.安装PHP7 
终端再次运行如下命令: 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 
成功获取PHP7的yum源,然后再执行: 
yum -y install php70w 
 
Centos7.x 使用yum安装php7.2
1、如果之前已经安装低版本php,先卸载:
[[email protected] ~]#yum -y remove php*
2、由于linux的yum源不存在php7.x,所以我们要更改yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm   rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3、yum 安装php72w和各种拓展模块,选自己需要的即可
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
4、最后,写一个PHP探测指针,测试PHP:
[[email protected] ~]#cd  /var/www/html/
[[email protected] ~]#vi info.php
<?php
        phpinfo();
?>
保存并退出
5、重启apache服务器:
[[email protected] ~]# systemctl restart httpd
6、访问 http://localhost/info.php
*将php与数据库关联:
[[email protected] ~]#yum install php-mysql
 
CentOS 7.x 安装phpmyadmin
1、先安装epel,不然安装pgpmyadmin时会出现找不到包。
[[email protected] ~]# yum install epel-release
[[email protected] ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
2、[[email protected] ~]# sudo yum install phpmyadmin
3、用文本编辑器打开phpMyAdmin的配置文件(路径:/etc/httpd/conf.d/phpMyAdmin.conf),找出并注释掉带有"Require ip XXXX"字样的代码行。会有四处这样的代码行,用"Require all granted"取而代之
[[email protected] ~]# sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
修改后的文件内容
  1. <Directory /usr/share/phpMyAdmin/>
  2.    AddDefaultCharset UTF-8
  3.    <IfModule mod_authz_core.c>
  4.      # Apache 2.4
  5.      <RequireAny>
  6.       # Require ip 127.0.0.1  #注释掉
  7.       # Require ip ::1   #注释掉
  8.       Require all granted   #新添加
  9.      </RequireAny>
  10. </IfModule>
  11. <IfModule !mod_authz_core.c>
  12.      # Apache 2.2
  13.      Order Deny,Allow
  14.      Deny from All
  15.      Allow from 127.0.0.1
  16.      Allow from ::1
  17.    </IfModule>
  18. </Directory>
  19. <Directory /usr/share/phpMyAdmin/setup/>
  20.    <IfModule mod_authz_core.c>
  21.      # Apache 2.4
  22.      <RequireAny>
  23.       #Require ip 127.0.0.1  #注释掉
  24.       #Require ip ::1   #注释掉
  25.       Require all granted   #新添加
  26.      </RequireAny>
  27.    </IfModule>
  28.    <IfModule !mod_authz_core.c>
  29.      # Apache 2.2
  30.      Order Deny,Allow
  31.      Deny from All
  32.      Allow from 127.0.0.1
  33.      Allow from ::1
  34.    </IfModule>
  35. </Directory>
4、[[email protected] ~]# systemctl restart  httpd

以上是关于CentOS 7.x 安装LAMP的主要内容,如果未能解决你的问题,请参考以下文章

如何搭建lamp(CentOS7+Apache+MySQL+PHP)环境

零基础局域网安装Centos7搭建LAMP Web服务器环境

linux搭建Lamp(centos7+apache+mysql)

分离php和MySQL搭建LAMP平台

CentOS7 lamp安装 centoOS6 lamp

centos 使用yum进行安装lamp环境