一、安装apache

1、下载并安装apache 

yum install httpd

2、启动apache

systemctl start httpd.service

3、停止apache

systemctl stop httpd.service

4、重启apache

systemctl restart httpd.service

5、将apache设置为开机启动

systemctl enable httpd.service

 

二、安装php

1、下载php

yum install php

2、安装php组件使其支持MariaDB

yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

 

三、安装MariaDB
1、下载并安装MariaDB

yum install mariadb mariadb-serve

2、启动MariaDB

systemctl start mariadb.service

3、停止MariaDB

systemctl stop mariadb.service 

4、重启MariaDB

systemctl restart mariadb.service

5、将MariaDB设置为开机启动

systemctl enable mariadb.service 

6、拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf 

7、为root用户设置密码

mysql_secure_installation

设置完密码后根据提示一直输入y就好

最后出现:Thanks for using MySQL!

最后再重启一下mariadb

 

四、配置Apache

vim /etc/httpd/conf/httpd.conf #编辑文件

 

ServerSignature off  #添加这一项,禁止在错误页中显示Apache的版本,on为显示

 

Options Indexes FollowSymLinks  #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

 

#Options Indexes FollowSymLinks   #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

 

:wq! #保存退出

 

systemctl restart httpd.service #重启apache

 

五、配置php

vi /etc/php.ini #编辑

 

date.timezone = PRC #找到date.timezone,把前面的分号去掉,改为date.timezone = PRC

 

expose_php = Off #禁止显示php版本的信息

 

short_open_tag = ON #支持php短标签

 

:wq! #保存退出

 

systemctl restart mariadb.service #重启MariaDB

systemctl restart httpd.service #重启apache

 

测试:到/var/www/html里写一个php文件试试

 

六、配置MariaDB

mysql> grant all privileges on *.* TO root@'%' identified by 'root' with grant option;      //开启远程

 

如果要远程调试数据库,则
mysql> grant all privileges on *.* to 连接用户名@客户机ip identified by "远程登录mysql的密码";
(root 为要连接的用户名 @后面是你所要连接mysql服务器的客户机ip,“不是mysql服务器ip”, "1234" 是登录mysql的密码)(这相当于你创建了个新用户,这个用户可以通过你指定的客户机ip连接数据库)

 

此时应再创建一个用户用于后面的开发,因为后面后台开发不能直接使用root用户登录数据库(root权限太大),创建另一个新用户,只赋予其基本权限,步骤如下:

MariaDB>create user '用户名'@'localhost' identified by '用户密码';     //创建用户

MariaDB>grant select,insert,update,delete on 数据库名.* to 用户名@'localhost' identified by '用户密码';  //为指定用户赋予“增删改查”的权限。

MariaDB>flush privileges;  //刷新系统权限表 

相关文章: