1.安裝Apache
yum install httpd #根據提示,輸入Y安裝即可成功安裝
systemctl start httpd.service #啓動apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重啓apache
systemctl enable httpd.service #設置apache開機啓動
2.安裝Mariadb
yum install mariadb mariadb-server #詢問是否要安裝,輸入Y即可自動安裝,直到安裝完成
systemctl start mariadb.service #啓動MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重啓MariaDB
systemctl enable mariadb.service #設置開機啓動
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆 蓋即可)
2.1 初始化數據庫
mysql_secure_installation
回車,根據提示輸入Y
輸入2次密碼,回車
根據提示一路輸入Y
最後出現:Thanks for using MySQL!
MySql密碼設置完成,重新啓動 MySQL:
systemctl restart mariadb.service #重啓MariaDB
3.安裝PHP
yum install php #根據提示輸入Y直到安裝完成
3.1 安裝PHP組件,使PHP支持 MariaDB
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash #這裏選擇以上安裝包進行安裝,根據提示輸入Y回車
systemctl restart mariadb.service #重啓MariaDB
systemctl restart httpd.service #重啓apache
4.安裝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> :wq
systemctl restart httpd
瀏覽器訪問地址http://ip/phpmyadmin