


CentOS裝LAMP服務器(Apache2+PHP5+MySQL)
1.重要提示:
在本教程中使用的主機名為server1.example.com,IP 地址為 192.168.0.100 。這些設置會與具體安裝的設置有所不同,所以你必須在你的安裝過程中進行替代。
2.安裝MySQL 5.0
打開終端,輸入:
yum install mysql mysql-server |
然后為MySQL創建系統啟動鏈接(這樣在系統啟動時,MySQL會自動啟動),在終端輸入命令:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start |
為MySQL root帳戶設置密碼:
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] <– 回車 By default, a MySQL installation has an anonymous user, allowing anyone Remove anonymous users? [Y/n] <– 回車 Normally, root should only be allowed to connect from ’localhost’. This Disallow root login remotely? [Y/n] <–回車 By default, MySQL comes with a database named ’test’ that anyone can Remove test database and access to it? [Y/n] <– 回車 Reloading the privilege tables will ensure that all changes made so far Reload privilege tables now? [Y/n] <– 回車 Cleaning up… All done! If you’ve completed all of the above steps, your MySQL Thanks for using MySQL! [root@server1 ~]# |
yum install httpd |
配置系統啟動時自動啟動apache
chkconfig --levels 235 httpd on |
重啟apache:
/etc/init.d/httpd start |
在您的瀏覽器直接http://192.168.0.100,你應該看到apache2的頁面:

在CentOS中Apache的默認文檔的根目錄是/var/www/html,配置文件/etc/httpd/conf/httpd.conf。其他配置存儲在/etc/httpd/conf.d/目錄里。
4.Installing PHP5
我們可以安裝PHP5和Apache PHP5模塊,命令如下:
yum install php |
安裝完成后必須重新啟動Apache
/etc/init.d/httpd restart |
5.測試PHP5 /獲取PHP5安裝的詳細信息
默認的Web站點的文檔根目錄/var/www/html 。現在,我們將在該目錄中創建PHP探針文件((info.php),在瀏覽器中調用它 。該文件將顯示很多有用的細節,看看我們安裝的php模塊安裝時候完成。
vi /var/www/html/info.php |
現在,在瀏覽器打開(如文件http://192.168.0.100/info.php):

正如您所看到的,PHP5工作正常,如果繼續向下滾動,你會看到所有在PHP5中已經啟用的模塊 。沒有MySQL,這意味著我們php5中還沒有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 |
現在重新啟動Apache2
/etc/init.d/httpd restart |
7.安裝phpMyAdmin管理數據庫
phpMyAdmin是一個Web界面,通過它可以管理你的MySQL數據庫。
首先,我們使我們的CentOS 系統的RPMForge軟件庫phpMyAdmin是不是官方的CentOS 6.0庫:
導入rpmforge的GPG密鑰:
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt |
x86_64 系統安裝命令:
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm |
i386 系統安裝命令:
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm |
現在可以安裝phpMyAdmin如下:
yum install phpmyadmin |
現在,我們配置phpMyAdmin。改變Apache的配置,使phpMyAdmin連接,而不僅僅是從localhost(注釋掉允許) :
vi /etc/httpd/conf.d/phpmyadmin.conf
|
下一步,我們改變在phpMyAdmin的身份驗證 cookie ,HTTP:
vi /usr/share/phpmyadmin/config.inc.php [...]/* Authentication type */ $cfg['Servers'][$i]['auth_type'] = ‘http’; [...] |
重新啟動Apache:
/etc/init.d/httpd restart |
之后,您可以根據訪問phpMyAdmin http://192.168.0.100/phpmyadmin/管理數據庫:
8.相關鏈接
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/
關鍵字:LAMP 服務器、數據庫
新文章:
- CentOS7下圖形配置網絡的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統后丟失windows啟動項
- CentOS單網卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網打印機IP講解
- CentOS7使用hostapd實現無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網絡重啟出錯
- 解決Centos7雙系統后丟失windows啟動項
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統有什么不同呢
- Centos 6.6默認iptable規則詳解