CentOS 6.0 上安裝LAMP服務器

   CentOS 6.0才發佈不久,如今咱們來共同窗習一下如何在CentOS 6.0上安裝Apache2 + PHP5 + MySQL的web服務器。 php

  CentOS 6.0才發佈不久,如今咱們來共同窗習一下如何在CentOS 6.0上安裝Apache2 + PHP5 + MySQL的web服務器。
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 SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user.  If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 回車
New password: <– 設置一個用戶密碼
Re-enter new password: <– 再輸入一次你設置的密碼
Password updated successfully!
Reloading privilege tables
…Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <– 回車
…Success!
Normally, root should only be allowed to connect from ’localhost’。  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <–回車
…Success!
By default, MySQL comes with a database named ’test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <– 回車
- Dropping test database…
…Success!
- Removing privileges on test database…
…Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 回車
…Success!
Cleaning up…
All done!  If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server1 ~]#
3.安裝的Apache2
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
#
# Web application to manage MySQL
#
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin
下一步,咱們改變在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/
相關文章
相關標籤/搜索