1. 程式人生 > >Centos7安裝配置Apache+PHP+Mysql+phpmyadmin

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

css isa roo awk perm mha pack 操作 req

轉載自:

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

一、安裝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

輸入如下內容

<?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安裝配置Apache+PHP+Mysql+phpmyadmin