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

转载自:php

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

1、安装Apachehtml

yum install httpd

安装成功后,Apache操做命令:mysql

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

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

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

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

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

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

重启 Firewalld 使该规则生效,数据库

systemctl restart firewalld

(2)关闭SELINUXapache

vi /etc/selinux/config

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

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

:wq! 保存退出

输入以下命令

setenforce 0 #使配置当即生效

2、 安装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;

3、安装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

输入以下内容

<?php phpinfo(); ?>

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


页面效果

4、安装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 來源:简书 著做权归做者全部。商业转载请联系做者得到受权,非商业转载请注明出处。
相关文章
相关标签/搜索