CentOS裝LAMP服務(wù)器(Apache2+PHP5+MySQL)
1.重要提示:
在本教程中使用的主機(jī)名為server1.example.com,IP 地址為 192.168.0.100 。這些設(shè)置會(huì)與具體安裝的設(shè)置有所不同,所以你必須在你的安裝過(guò)程中進(jìn)行替代。
2.安裝MySQL 5.0
打開(kāi)終端,輸入:
yum install mysql mysql-server |
然后為MySQL創(chuàng)建系統(tǒng)啟動(dòng)鏈接(這樣在系統(tǒng)啟動(dòng)時(shí),MySQL會(huì)自動(dòng)啟動(dòng)),在終端輸入命令:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start |
為MySQL root帳戶(hù)設(shè)置密碼:
mysql_secure_installation |
終端顯示,按照提示操作:
[root@server1 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS IS RECOMMENDED FOR ALL MySQL In order to log into MySQL to secure it, we’ll need the current Enter current password for root (enter for none): Setting the root password ensures that nobody can log into the MySQL Set root password? [Y/n] <– 回車(chē) By default, a MySQL installation has an anonymous user, allowing anyone Remove anonymous users? [Y/n] <– 回車(chē) Normally, root should only be allowed to connect from ’localhost’. This Disallow root login remotely? [Y/n] <–回車(chē) By default, MySQL comes with a database named ’test’ that anyone can Remove test database and access to it? [Y/n] <– 回車(chē) Reloading the privilege tables will ensure that all changes made so far Reload privilege tables now? [Y/n] <– 回車(chē) Cleaning up… All done! If you’ve completed all of the above steps, your MySQL Thanks for using MySQL! [root@server1 ~]# |
yum install httpd |
配置系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng)apache
chkconfig --levels 235 httpd on |
重啟apache:
/etc/init.d/httpd start |
在您的瀏覽器直接http://192.168.0.100,你應(yīng)該看到apache2的頁(yè)面:
在CentOS中Apache的默認(rèn)文檔的根目錄是/var/www/html,配置文件/etc/httpd/conf/httpd.conf。其他配置存儲(chǔ)在/etc/httpd/conf.d/目錄里。
4.Installing PHP5
我們可以安裝PHP5和Apache PHP5模塊,命令如下:
yum install php |
安裝完成后必須重新啟動(dòng)Apache
/etc/init.d/httpd restart |
5.測(cè)試PHP5 /獲取PHP5安裝的詳細(xì)信息
默認(rèn)的Web站點(diǎn)的文檔根目錄/var/www/html 。現(xiàn)在,我們將在該目錄中創(chuàng)建PHP探針文件((info.php),在瀏覽器中調(diào)用它 。該文件將顯示很多有用的細(xì)節(jié),看看我們安裝的php模塊安裝時(shí)候完成。
vi /var/www/html/info.php |
現(xiàn)在,在瀏覽器打開(kāi)(如文件http://192.168.0.100/info.php):
正如您所看到的,PHP5工作正常,如果繼續(xù)向下滾動(dòng),你會(huì)看到所有在PHP5中已經(jīng)啟用的模塊 。沒(méi)有MySQL,這意味著我們php5中還沒(méi)有MySQL支持模塊。
6.在PHP5中添加MySQL支持
yum search php |
挑選那些你需要的模塊,安裝:
yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc |
現(xiàn)在重新啟動(dòng)Apache2
/etc/init.d/httpd restart |
7.安裝phpMyAdmin管理數(shù)據(jù)庫(kù)
phpMyAdmin是一個(gè)Web界面,通過(guò)它可以管理你的MySQL數(shù)據(jù)庫(kù)。
首先,我們使我們的CentOS 系統(tǒng)的RPMForge軟件庫(kù)phpMyAdmin是不是官方的CentOS 6.0庫(kù):
導(dǎo)入rpmforge的GPG密鑰:
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt |
x86_64 系統(tǒng)安裝命令:
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm |
i386 系統(tǒng)安裝命令:
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm |
現(xiàn)在可以安裝phpMyAdmin如下:
yum install phpmyadmin |
現(xiàn)在,我們配置phpMyAdmin。改變Apache的配置,使phpMyAdmin連接,而不僅僅是從localhost(注釋掉允許) :
vi /etc/httpd/conf.d/phpmyadmin.conf
|
下一步,我們改變?cè)趐hpMyAdmin的身份驗(yàn)證 cookie ,HTTP:
vi /usr/share/phpmyadmin/config.inc.php [...]/* Authentication type */ $cfg['Servers'][$i]['auth_type'] = ‘http’; [...] |
重新啟動(dòng)Apache:
/etc/init.d/httpd restart |
之后,您可以根據(jù)訪(fǎng)問(wèn)phpMyAdmin http://192.168.0.100/phpmyadmin/管理數(shù)據(jù)庫(kù):
8.相關(guān)鏈接
Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
CentOS: http://www.centos.org/
phpMyAdmin: http://www.phpmyadmin.net/
關(guān)鍵字:LAMP 服務(wù)器、數(shù)據(jù)庫(kù)
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶(hù)
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶(hù)的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無(wú)AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解