当前位置:Gxlcms > 数据库问题 > Centos7安装配置Apache+PHP+Mysql+phpmyadmin

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

时间:2021-07-01 10:21:17 帮助过:6人阅读

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

  1. <code class="gauss">systemctl start httpd <span class="hljs-comment">//启动apache
  2. systemctl <span class="hljs-keyword">stop httpd <span class="hljs-comment">//停止apache
  3. systemctl restart httpd <span class="hljs-comment">//重启apache
  4. systemctl <span class="hljs-keyword">enable httpd <span class="hljs-comment">//设置apache开机启动</span></span></span></span></span></span></code>

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

  1. <code class="brainfuck"><span class="hljs-comment">firewall<span class="hljs-literal">-<span class="hljs-comment">cmd <span class="hljs-literal">-<span class="hljs-literal">-<span class="hljs-comment">add<span class="hljs-literal">-<span class="hljs-comment">service=http <span class="hljs-literal">-<span class="hljs-literal">-<span class="hljs-comment">permanent</span></span></span></span></span></span></span></span></span></span></span></code>

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

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

  1. <code class="brainfuck"><span class="hljs-comment">firewall<span class="hljs-literal">-<span class="hljs-comment">cmd <span class="hljs-literal">-<span class="hljs-literal">-<span class="hljs-comment">zone=public <span class="hljs-literal">-<span class="hljs-literal">-<span class="hljs-comment">add<span class="hljs-literal">-<span class="hljs-comment">port=81/tcp <span class="hljs-literal">-<span class="hljs-literal">-<span class="hljs-comment">permanent</span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>

重启 Firewalld 使该规则生效,

  1. <code class="ebnf">systemctl restart firewalld</code>

(2)关闭SELINUX

  1. <code class="arduino">vi /etc/selinux/<span class="hljs-built_in">config</span></code>

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

  1. <code class="clean">\#SELINUX=enforcing #注释掉
  2. \#SELINUXTYPE=targeted #注释掉
  3. SELINUX=disabled #增加</code>

:wq! 保存退出

输入如下命令

  1. <code class="nginx"><span class="hljs-attribute">setenforce <span class="hljs-number">0 <span class="hljs-comment">#使配置立即生效</span></span></span></code>

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

  1. <code class="sql">yum <span class="hljs-keyword">install mariadb mariadb-<span class="hljs-keyword">server</span></span></code>

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

  1. <code class="armasm"><span class="hljs-symbol">systemctl start <span class="hljs-keyword">mariadb //启动<span class="hljs-keyword">MariaDB
  2. <span class="hljs-symbol">systemctl stop <span class="hljs-keyword">mariadb //停止<span class="hljs-keyword">MariaDB
  3. <span class="hljs-symbol">systemctl restart <span class="hljs-keyword">mariadb //重启<span class="hljs-keyword">MariaDB
  4. <span class="hljs-symbol">systemctl enable <span class="hljs-keyword">mariadb //设置开机启动</span></span></span></span></span></span></span></span></span></span></span></code>

设置root账户密码

  1. <code>mysql_secure_installation</code>

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生效

  1. <code class="css"><span class="hljs-selector-tag">systemctl <span class="hljs-selector-tag">restart <span class="hljs-selector-tag">mariadb<span class="hljs-selector-class">.service</span></span></span></span></code>

测试访问数据库:

  1. <code class="ebnf">mysql -uroot -p</code>

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

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)]>

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

  1. <code class="sql"><span class="hljs-keyword">show <span class="hljs-keyword">databases;</span></span></code>

退出命令:

  1. <code class="awk"><span class="hljs-keyword">exit;</span></code>

三、安装PHP以及PHP拓展

  1. <code class="crmsh">yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-<span class="hljs-keyword">xml <span class="hljs-title">php-xmlrpc php-mbstring php-bcmath php-mhash</span></span></code>

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

  1. <code class="css"><span class="hljs-selector-tag">systemctl <span class="hljs-selector-tag">restart <span class="hljs-selector-tag">httpd<span class="hljs-selector-class">.service</span></span></span></span></code>

测试PHP安装结果

  1. <code class="awk">vi <span class="hljs-regexp">/var/www<span class="hljs-regexp">/html/index.php</span></span></code>

输入如下内容

  1. <code class="xml"><span class="php"><span class="hljs-meta"><?php
  2. phpinfo();
  3. <span class="hljs-meta">?></span></span></span></code>

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

技术分享
页面效果

四、安装phpmyadmin

使用yum安装phpmyadmin

  1. <code class="cmake">yum <span class="hljs-keyword">install phpmyadmin php-mcrypt</span></code>

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

  1. <code class="vim"><span class="hljs-keyword">vi /etc/httpd/<span class="hljs-keyword">conf.d/phpMyAdmin.<span class="hljs-keyword">conf</span></span></span></code>

修改配置文件,如下:

  1. <code class="apache"><span class="hljs-section"><Directory /usr/share/phpMyAdmin/>
  2. <span class="hljs-attribute">AddDefaultCharset UTF-8
  3. <span class="hljs-section"><IfModule mod_authz_core.c>
  4. <span class="hljs-comment"># Apache 2.4
  5. <span class="hljs-section"><RequireAny>
  6. <span class="hljs-comment"># Require ip 127.0.0.1 #注释掉
  7. <span class="hljs-comment"># Require ip ::1 #注释掉
  8. <span class="hljs-attribute">Require <span class="hljs-literal">all granted #新添加
  9. <span class="hljs-section"></RequireAny>
  10. <span class="hljs-section"></IfModule>
  11. <span class="hljs-section"><IfModule !mod_authz_core.c>
  12. <span class="hljs-comment"># Apache 2.2
  13. <span class="hljs-attribute"><span class="hljs-nomarkup">Order Deny,Allow
  14. <span class="hljs-attribute"><span class="hljs-nomarkup">Deny from <span class="hljs-literal">All
  15. <span class="hljs-attribute"><span class="hljs-nomarkup">Allow from 127.0.0.1
  16. <span class="hljs-attribute"><span class="hljs-nomarkup">Allow from ::1
  17. <span class="hljs-section"></IfModule>
  18. <span class="hljs-section"></Directory>
  19. <span class="hljs-section"><Directory /usr/share/phpMyAdmin/setup/>
  20. <span class="hljs-section"><IfModule mod_authz_core.c>
  21. <span class="hljs-comment"># Apache 2.4
  22. <span class="hljs-section"><RequireAny>
  23. <span class="hljs-comment">#Require ip 127.0.0.1 #注释掉
  24. <span class="hljs-comment">#Require ip ::1 #注释掉
  25. <span class="hljs-attribute">Require <span class="hljs-literal">all granted #新添加
  26. <span class="hljs-section"></RequireAny>
  27. <span class="hljs-section"></IfModule>
  28. <span class="hljs-section"><IfModule !mod_authz_core.c>
  29. <span class="hljs-comment"># Apache 2.2
  30. <span class="hljs-attribute"><span class="hljs-nomarkup">Order Deny,Allow
  31. <span class="hljs-attribute"><span class="hljs-nomarkup">Deny from <span class="hljs-literal">All
  32. <span class="hljs-attribute"><span class="hljs-nomarkup">Allow from 127.0.0.1
  33. <span class="hljs-attribute"><span class="hljs-nomarkup">Allow from ::1
  34. <span class="hljs-section"></IfModule>
  35. <span class="hljs-section"></Directory></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>

然后重启Apache服务器

  1. <code class="ebnf">systemctl restart httpd</code>

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

技术分享
访问phpmyadmin页面

作者:TyiMan
链接:http://www.jianshu.com/p/bc14ff0ab1c7
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

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

标签:res   table   大小写   data-   nginx   drop   httpd   提示   img   

人气教程排行