apache category
CentOS 5.x yum安装LAMP(Apache+MySQL+PHP)
发表于:2012年07月24日  分类:Apache  添加评论  113 次浏览 

LAMPLinux,Apache,MySQL,PHP的缩写。这个教程主要是讲在centos安装有php和mysql支持的apache web服务器。在这个教程我使用主机名server1.example.com对应IP地址192.168.0.100。这些设置可能不同于你,你必须替换成你正确的。

添加外部源,保证MySQL和PHP最新

因为系统基本的源的MySQL和PHP程序比较旧,所以我们添加比较新的外部源。

    # rpm –import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

  1. # vi /etc/yum.repos.d/CentOS-Base.repo

在底部增加下面信息

    [utterramblings]

  1. name=Jason’s Utter Ramblings Repo
  2. baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
  3. enabled=1
  4. gpgcheck=1
  5. gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

安装MySQL

执行yum程序安装MySQL

    yum install mysql mysql-server

添加MySQL进启动项(这样系统启动时会自动启动MySQL),并立即启动MySQL服务器:

    chkconfig –levels 235 mysqld on

  1. /etc/init.d/mysqld start

设置MySQL root帐号密码:

    mysql_secure_installation
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

  1.       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
  2.  
  3.  
  4. In order to log into MySQL to secure it, we’ll need the current
  5. password for the root user.  If you’ve just installed MySQL, and
  6. you haven’t set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8.  
  9. Enter current password for root (enter for none):
  10. OK, successfully used password, moving on…
  11.  
  12. Setting the root password ensures that nobody can log into the MySQL
  13. root user without the proper authorisation.
  14.  
  15. Set root password? [Y/n] <– ENTER
  16. New password: <– 你的MySQL root密码
  17. Re-enter new password: <– 你的MySQL root密码
  18. Password updated successfully!
  19. Reloading privilege tables..
  20.  … Success!
  21.  
  22.  
  23. By default, a MySQL installation has an anonymous user, allowing anyone
  24. to log into MySQL without having to have a user account created for
  25. them.  This is intended only for testing, and to make the installation
  26. go a bit smoother.  You should remove them before moving into a
  27. production environment.
  28.  
  29. Remove anonymous users? [Y/n] <– ENTER
  30.  … Success!
  31.  
  32. Normally, root should only be allowed to connect from ‘localhost’.  This
  33. ensures that someone cannot guess at the root password from the network.
  34.  
  35. Disallow root login remotely? [Y/n] <– ENTER
  36.  … Success!
  37.  
  38. By default, MySQL comes with a database named ‘test’ that anyone can
  39. access.  This is also intended only for testing, and should be removed
  40. before moving into a production environment.
  41.  
  42. Remove test database and access to it? [Y/n] <– ENTER
  43.  - Dropping test database…
  44.  … Success!
  45.  - Removing privileges on test database…
  46.  … Success!
  47.  
  48. Reloading the privilege tables will ensure that all changes made so far
  49. will take effect immediately.
  50.  
  51. Reload privilege tables now? [Y/n] <– ENTER
  52.  … Success!
  53.  
  54. Cleaning up…
  55.  
  56.  
  57.  
  58. All done!  If you’ve completed all of the above steps, your MySQL
  59. installation should now be secure.
  60.  
  61. Thanks for using MySQL!

安装Apache

Apache在CentOS软件包可用,因此我们可以使用yum安装:

    yum install httpd

设置系统启动时自启动Apache

    chkconfig –levels 235 httpd on

并启动Apache

    /etc/init.d/httpd start

现在你直接在你的浏览器键入http://192.168.0.100,你就应该会看到Apache的测试页面。

安装PHP

我们可以按照下面的命令安装PHP和Apache PHP模块:

    yum install php

然后重启Apache服务器:

    /etc/init.d/httpd restart

安装相关模块使用PHP支持MySQL

为了让PHP支持MySQL,我们可以安装php-mysql软件包。你也可以安装其它的php模块。可以使用以下命令搜索可用的php模块:

    yum search php

选择一些你需要的模块进行安装:

    yum install php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

现在重启Apache:

    /etc/init.d/httpd restart

安装phpMyAdmin

phpMyAdmin是一个可视化管理你的MySQL数据库的软件。
安装很简单,下载解压到根目录即可.
下载地址:http://www.phpmyadmin.net/home_page/downloads.php
接着我们配置phpMyAdmin,为了使用phpMyAdmin不仅仅只允许localhost连接,我们修改一下apache的配置。

    vi /etc/httpd/conf.d/phpmyadmin.conf

填入如下内容:

    #

  1. #  Web application to manage MySQL
  2. #
  3.  
  4. #<Directory “/usr/share/phpmyadmin”>
  5. #  Order Deny,Allow
  6. #  Deny from all
  7. #  Allow from 127.0.0.1
  8. #</Directory>
  9.  
  10. Alias /phpmyadmin /usr/share/phpmyadmin
  11. Alias /phpMyAdmin /usr/share/phpmyadmin
  12. Alias /mysqladmin /usr/share/phpmyadmin

重启apache:
/etc/init.d/httpd restart
然后你就可以通过http://192.168.0.100/phpmyadmin/进入phpMyAdmin了。

转载请注明文章来源:http://www.centos.bz/2011/04/centos-yum-install-lamp-apache-mysql-php/

固定链接: http://anywang.vicp.net:8180/wp/?p=238 | 网邻's Blog

给我留言


/ 快捷键:Ctrl+Enter

留言没头像?这里教你设置头像!