Centos7 搭建Apache+PHP+mariadb环境

安装Apache、PHP、Mysql、连接Mysql数据库的包:

1

2

3

4

5

6

7

8

9

10

11

yum -y install httpd

 

yum -y install php

 

yum -y install php-fpm

 

yum -y install mariadb

 

yum -y install mysql-server

 

yum -y install php-mysql

除了mysql-server其他都安装成功

1

2

3

4

5

错误:No package mysql-server available.

 

Package php-mysql-5.4.16-36.el7_1.x86_64 already installed and latest version

 

Nothing to do

查找原因是因为CentOS 7版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了,

有两种解决方案,一是安装mariadb,二是从官网下载mysql-server.因为对mariadb不熟悉,所以我采用了第二种解决方案。

1

2

3

4

5

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

 

rpm -ivh mysql-community-release-el7-5.noarch.rpm

 

yum install mysql-community-server

然后需要确定,输入y回车即可

1

Isthis ok[y/d/N]:y

接下来等待下载,需要确认的输入y回车即可

成功!

接下来安装常用扩展包

安装Apache扩展包

1

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

安装PHP扩展包

1

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel

安装Mysql扩展包

1

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

配置Apache、mysql开机启动

1

2

3

chkconfig httpd on

 

chkconfig mysqld on

没有error,成功

Centos7 搭建Apache+PHP+mariadb环境

重启Apache、mysql服务(注意这里和centos6有区别,7不能使用6的方式)

1

2

3

4

5

service mysqld restart

 

service php-fpm start

 

service httpd restart

打开mysql

初次安装mysql是没有密码的

1

mysql–u root

Centos7 搭建Apache+PHP+mariadb环境

 

1

show databases;  #注意分号

  

Centos7 搭建Apache+PHP+mariadb环境

可重置密码

1

set password for 'root'@'localhost' =password('lyymysql');

Centos7 搭建Apache+PHP+mariadb环境

环境检查

1

netstat –tunlp

如下图,php监听9000端口,apache监听80端口,mysql监听3306端口

Centos7 搭建Apache+PHP+mariadb环境

php测试环境是否成功

进入apache的web根目录:/var/www/html 中自己写一个最简单的php页面

https://www.cnblogs.com/aksir/p/6771715.html