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

1、安裝Apachephp

yum install httpd
安裝成功後,Apache操做命令:html

systemctl start httpd //啓動apache
systemctl stop httpd //中止apache
systemctl restart httpd //重啓apache
systemctl enable httpd //設置apache開機啓動
異常處理
我再阿里雲上配置並出現啓動Apache後沒法訪問的問題,可是通常服務器訪問Apache可能須要以下操做:
(1)在防火牆中開放80端口
如今須要將 http 服務加入防火牆以容許外部訪問,mysql

firewall-cmd --add-service=http --permanent
–permanent 參數表示這是一條永久防火牆規則,若是不加則重啓系統後就沒有這條規則了。linux

而對於自定義的端口(如81),也須要添加防火牆規則,sql

firewall-cmd --zone=public --add-port=81/tcp --permanent
重啓 Firewalld 使該規則生效,數據庫

systemctl restart firewalld
(2)關閉SELINUXapache

vi /etc/selinux/config
註釋掉以下兩句,添加最後一項瀏覽器

#SELINUX=enforcing #註釋掉
#SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增長
:wq! 保存退出服務器

輸入以下命令markdown

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來源:簡書著做權歸做者全部。商業轉載請聯繫做者得到受權,非商業轉載請註明出處。

相關文章
相關標籤/搜索