買了主機(jī)挺久的,一直想寫一篇文章,記錄下在CentOS7.2 下配置Apache 和 php 以及 mysql。使用版本為centos7.2版本。在服務(wù)器上比較推薦centos,此版本生命周期較長(zhǎng),而且網(wǎng)上有關(guān)centos的教程很多,方便學(xué)習(xí)。
【版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載時(shí)需注明出處,尊重互聯(lián)網(wǎng)共享精神,尊重自己?!?br>
安裝Apache、PHP、Mysql、連接Mysql數(shù)據(jù)庫(kù)的包:
一鍵安裝 : yum -y install httpd php mysql php-mysql mariadb-server mariadb
安裝phpMyAdmin :? yum install phpmyadmin php-mcrypt
安裝apache擴(kuò)展 : yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
安裝php的擴(kuò)展 : yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc
【為什么要安裝MariaDB ?】
MariaDB是MySQL的一個(gè)分支,由開源社區(qū)維護(hù),采用GPL許可;甲骨文公司收購(gòu)MySQL后有將MySQL閉源的風(fēng)險(xiǎn),因此社區(qū)采用分支的方式來(lái)規(guī)避風(fēng)險(xiǎn)。
配置Apache、mysql開機(jī)啟動(dòng)
chkconfig httpd on
chkconfig mysqld on
沒有error,成功
重啟Apache、mysql服務(wù)(注意這里和centos6有區(qū)別,7不能使用6的方式)
service mysqld restart
service php-fpm start
service httpd restart
配置MariaDB(MySQL)
啟動(dòng) MariaDB : systemctl start mariadb
一些相關(guān)命令?
?systemctl start mariadb? #啟動(dòng)MariaDB
systemctl?stop?mariadb??#停止MariaDB
systemctl?restart?mariadb??#重啟MariaDB
systemctl?enable?mariadb??#設(shè)置開機(jī)啟動(dòng)
數(shù)據(jù)庫(kù)簡(jiǎn)單配置
打開數(shù)據(jù)庫(kù)
mysql -u root -p??
mysql_secure_installation(一開始是沒有密碼的)
首先設(shè)置密碼,會(huì)提示先輸入密碼
Enter current passwordforroot (enterfornone):? ?# 初次運(yùn)行直接回車
設(shè)置密碼
Set root password? [Y/n]? ? ? ? ? # 是否設(shè)置root用戶密碼,輸入y并回車
New?password:? ? ? ? ? ?#?設(shè)置root用戶的密碼
Re-enternewpassword:? ? ? ? ? #?再輸入一次你設(shè)置的密碼
其他配置
Remove anonymous users? [Y/n] # 是否刪除匿名用戶,輸入y并回車
Disallow?root?login?remotely??[Y/n]?#?是否禁止root遠(yuǎn)程登錄,輸入y并回車
Remove?test?database?and?access?to?it??[Y/n]?#?是否刪除test數(shù)據(jù)庫(kù),輸入y并回車
Reload?privilege?tables?now??[Y/n]?#?是否重新加載權(quán)限表,輸入y并回車
接下來(lái)就可以登錄了
mysql -u root -p password
退出數(shù)據(jù)庫(kù)使用 exit
修改配置文件
找文件路徑請(qǐng)用文件查找命令 find / -name +文件名
注意大小寫??!大小寫錯(cuò)誤是不會(huì)找到的??!
找打phpMyAdmin.conf 文件?
輸入命令行 : find / -name phpMyAdmin.conf
修改phpMyAdmin.conf(配置phpMyAdmin)

按照?qǐng)D中的說(shuō)明,將該注釋的和添加的都加改了
修改之后重啟Apache我們就能通過(guò)瀏覽器http://服務(wù)器外網(wǎng)ip地址/phpmyadmin來(lái)訪問phpMyAdmin
用戶名是 root? 密碼是你在mysql中修改的密碼