热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Centos7安装配置Apache+PHP+Mysql+phpmyadmin

一、安装Apacheyuminstallhttpd安装成功后,Apache操作命令:systemctlstarthttpd启动apachesystemctlstophttp

一、安装Apache

yum install httpd

安装成功后,Apache操作命令:

systemctl start httpd      //启动apache
systemctl stop httpd //停止apache
systemctl restart httpd //重启apache
systemctl enable httpd //设置apache开机启动

异常处理
我再阿里云上配置并出现启动Apache后无法访问的问题,但是一般服务器访问Apache可能需要如下操作:
(1)在防火墙中开放80端口
现在需要将 http 服务加入防火墙以允许外部访问,

firewall-cmd --add-service=http --permanent

–permanent 参数表示这是一条永久防火墙规则,如果不加则重启系统后就没有这条规则了。

而对于自定义的端口(如81),也需要添加防火墙规则,

firewall-cmd --zOne=public --add-port=81/tcp --permanent

重启 Firewalld 使该规则生效,

systemctl restart firewalld

(2)关闭SELINUX

vi /etc/selinux/config

注释掉如下两句,添加最后一项

\#SELINUX=enforcing #注释掉
\#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加

:wq! 保存退出

输入如下命令

setenforce 0 #使配置立即生效

二、 安装MariaDB (MySQL的一个开源分支)

yum install mariadb mariadb-server

MariaDB安装成功后,需要配置MySQL的root密码,此外,备注一下启动关闭MariaDB的常用命令

systemctl start mariadb     //启动MariaDB
systemctl stop mariadb //停止MariaDB
systemctl restart mariadb //重启MariaDB
systemctl enable mariadb //设置开机启动

设置root账户密码

mysql_secure_installation

Enter current password for root (enter for none):
Set root password? [Y/n]

点击回车然后提示是否设置root账号密码,输入y

New password:
Re-enter new password:
Password updated successfully!

提示输入新密码和重复输入新密码,重复输入两次后,出现更新密码成功提示。

然后一路输入y就可以。

Remove anonymous users? [Y/n] y
... Success!

Disallow root login remotely? [Y/n] y
... Success!

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reload privilege tables now? [Y/n] y
... Success!

Thanks for using MariaDB!

设置root密码后,重启MariaDB生效

systemctl restart mariadb.service

测试访问数据库:

mysql -uroot -p

然后输入密码,登录成功后显示如下:

Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

输入如下命令,查看数据库服务器的数据库

show databases;

退出命令:

exit;

三、安装PHP以及PHP拓展

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

安装完成后,重启Apache服务器

systemctl restart httpd.service

测试PHP安装结果

vi /var/www/html/index.php

输入如下内容


phpinfo();
?>

输入:wq! 保存退出
在浏览器中输入服务器地址,查看是否可以看到:


页面效果

四、安装phpmyadmin

使用yum安装phpmyadmin

yum install phpmyadmin php-mcrypt

phpMyAdmin 的默认安装目录是 /usr/share/phpMyAdmin,同时会在 Apache 的配置文件目录中自动创建虚拟主机配置文件 /etc/httpd/conf.d/phpMyAdmin.conf(区分大小写)。默认情况下,CentOS 7上的phpMyAdmin只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。

vi /etc/httpd/conf.d/phpMyAdmin.conf

修改配置文件,如下:

<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8

<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
# Require ip 127.0.0.1 #注释掉
# Require ip ::1 #注释掉
Require all granted #新添加
RequireAny>
IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
IfModule>
Directory>

<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#Require ip 127.0.0.1 #注释掉
#Require ip ::1 #注释掉
Require all granted #新添加
RequireAny>
IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
IfModule>
Directory>

然后重启Apache服务器

systemctl restart httpd

然后就可以通过浏览器访问http://服务器ip地址/phpmyadmin访问


访问phpmyadmin页面


文/TyiMan(简书作者)
原文链接:http://www.jianshu.com/p/bc14ff0ab1c7
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

推荐阅读
  • 阿里云主机实战应用之centos7上的防火墙设置
    最近公司又上了一台服务器,以前都是用centos6系统,这次选择使用了centos7系统的安装镜像,因为现在程序版本在centos7上一般php默认就是5.4以上的,mysql也 ... [详细]
  • 基于CentOS7的服务器环境搭建(LAMP环境)一、安装MySQL组件  1.由于在CentOS7中,默认yum安装库中不含有mysql,我们可以下载mysql的分支Mari ... [详细]
  • centos7下安装docker(15.3跨主机网络-macvlan)
    除了ovrlay,docker还开发了另一个支持跨主机容器的driver:macvlanmacvlan本身是linukernel模块,其功能是允许在同一物理网卡上配置多了MAC地址,即:多 ... [详细]
  • 一安装配置1.配置文件mongod.cfg(路径:D:\data\config\mongod.cfg)如下:    systemLog:destination ... [详细]
  • 在云服务器中搭建Jupyter Notebook环境
    目录前言二、JupyterNotebook搭建步骤1.云服务器准备2.安装Python及pip3.安装JupyterNotebook4.运行JupyterNoteboo ... [详细]
  • 本文介绍了在CentOS 7.x上进行端口映射配置的方法,通过修改内核和配置防火墙实现端口映射。作者分享了自己使用华为服务器进行端口映射的经验,发现网速比直连还快且稳定。详细的配置过程包括开启系统路由模式功能、设置IP地址伪装、设置端口映射等。同时,还介绍了如何监听本地端口的tcp请求,以及删除规则和开放的端口的方法。 ... [详细]
  • centos7如何利用yum安装mysql 8.0.12
    这篇文章将为大家详细讲解有关centos7如何利用yum安装mysql8.0.12,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了CentOS7编译mysql8.0.12相关的知识,希望对你有一定的参考价值。步骤一:安装 ... [详细]
  • MySQL for OPS 08:MHA 高可用
    MySQL for OPS 08:MHA 高可用 ... [详细]
  • 搭建NFS文件服务器,导出WordPress文件夹
    实验目的:搭建NFS文件服务器,导出wordpress文件夹给主机A和主机B,主机A和主机B同时使用httpd访问。实验环境:主机A:CentOS7,IP:192.168.60.1 ... [详细]
  • CentOS7搭建ApachePHPMySQL环境安装Apache1.安装yum-yinstallhttpd2.开启Apache服务systemctlstarthttpd.serv ... [详细]
  • >>>CentOS7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下1、直接关闭防火墙systemctlstopfirewalld.serv ... [详细]
  • 这里我们采用两台Nginx服务器作为前端,一主一从,Keepalived实现状态监测,保证Nginx正常对外提供服务,即主Nginx服务进程死掉之后,keepalived能够通过其自身的检测机制 ... [详细]
  • 用户管理_用户管理的小项目
      之前学习链表数据结构的时候,写过(相信很多人都做过)dos窗口版的学生管理系统,通过输入数字来实现CURD学生的信息,顶多就是把数据写入文件来存储数据 ... [详细]
  • 系统不能本文来源gaodai$ma#com搞$代*码*网连接数据库,关键要看两个数据:1、数据库系统允许的最大可连接数max_connections。这个参数是可以设置的。如果不设 ... [详细]
author-avatar
包千卿_413
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有