Linux下安裝配置Apache+PHP+MariaDB


一、安裝apache

1、下載並安裝apache 

yum install httpd

2、啟動apache

systemctl start httpd.service

3、停止apache

systemctl stop httpd.service

4、重啟apache

systemctl restart httpd.service

5、將apache設置為開機啟動

systemctl enable httpd.service

 

二、安裝php

1、下載php

yum install php

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

 

三、安裝MariaDB
1、下載並安裝MariaDB

yum install mariadb mariadb-serve

2、啟動MariaDB

systemctl start mariadb.service

3、停止MariaDB

systemctl stop mariadb.service 

4、重啟MariaDB

systemctl restart mariadb.service

5、將MariaDB設置為開機啟動

systemctl enable mariadb.service 

6、拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆蓋即可)

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf 

7、為root用戶設置密碼

mysql_secure_installation

設置完密碼后根據提示一直輸入y就好

最后出現:Thanks for using MySQL!

最后再重啟一下mariadb

 

四、配置Apache

vim /etc/httpd/conf/httpd.conf #編輯文件

 

ServerSignature off  #添加這一項,禁止在錯誤頁中顯示Apache的版本,on為顯示

 

Options Indexes FollowSymLinks  #修改為:Options Includes ExecCGI FollowSymLinks(允許服務器執行CGI及SSI,禁止列出目錄)

 

#Options Indexes FollowSymLinks   #修改為 Options FollowSymLinks(不在瀏覽器上顯示樹狀目錄結構)

 

:wq! #保存退出

 

systemctl restart httpd.service #重啟apache

 

五、配置php

vi /etc/php.ini #編輯

 

date.timezone = PRC #找到date.timezone,把前面的分號去掉,改為date.timezone = PRC

 

expose_php = Off #禁止顯示php版本的信息

 

short_open_tag = ON #支持php短標簽

 

:wq! #保存退出

 

systemctl restart mariadb.service #重啟MariaDB

systemctl restart httpd.service #重啟apache

 

測試:到/var/www/html里寫一個php文件試試

 

六、配置MariaDB

mysql> grant all privileges on *.* TO root@'%' identified by 'root' with grant option;      //開啟遠程

 

如果要遠程調試數據庫,則
mysql> grant all privileges on *.* to 連接用戶名@客戶機ip identified by "遠程登錄mysql的密碼";
(root 為要連接的用戶名 @后面是你所要連接mysql服務器的客戶機ip,“不是mysql服務器ip”, "1234" 是登錄mysql的密碼)(這相當於你創建了個新用戶,這個用戶可以通過你指定的客戶機ip連接數據庫)

 

此時應再創建一個用戶用於后面的開發,因為后面后台開發不能直接使用root用戶登錄數據庫(root權限太大),創建另一個新用戶,只賦予其基本權限,步驟如下:

MariaDB>create user '用戶名'@'localhost' identified by '用戶密碼';     //創建用戶

MariaDB>grant select,insert,update,delete on 數據庫名.* to 用戶名@'localhost' identified by '用戶密碼';  //為指定用戶賦予“增刪改查”的權限。

MariaDB>flush privileges;  //刷新系統權限表 


免責聲明!

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



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