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


首先我是安裝了Nginx,但是不熟悉,所以在安裝了Nginx的基礎上有安裝了apach

查找Mysql數據庫的root密碼:

grep 'temporary password' /var/log/mysqld.log

  

一、安裝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 //設置開機啟動
或者
service mysql start

設置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
鏈接:https://www.jianshu.com/p/bc14ff0ab1c7
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM