LAMP是一个免费、开源的解决方案,代表了Linux、Apache、MySQL、PHP,主要用作建立可行的通用的web服务器。那么如何在CentOS6下实现安装Apache+php+Mysql的快速安装?其具体安装配置步骤可以如下进行:
1.准备工作
使用yum进行安装,为了提高速度,最好先是修改为中国CentOS镜像服务器。目前国内有三个镜像可以选择,分别是:中国科学技术大学、163和Sohu的镜像,建议教育网用户选择中科大,电信用户选择163,他们的repo文件本博客作了备份如下:
http://yupengyan.com/wp-content/uploads/2012/02/CentOS6-Base-163.repo_.txt
http://yupengyan.com/wp-content/uploads/2012/02/CentOS6-Base-sohu.repo_.txt
http://yupengyan.com/wp-content/uploads/2012/02/CentOS6-Base-ustc.repo_.txt
下面命令是备份CentOS-Base.repo文件,并修改使用163镜像作为yum源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.save wget http://mirrors.163.com/.help/CentOS6-Base-163.repo mv CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
2.更新系统内核
yum -y update
3.安装Apahce、Mysql、PHP
yum -y install httpd php mysql mysql-server
4.安装相关组件:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
5.安装MySQL管理工具phpMyAdmin
yum -y install phpMyAdmin
6.配置Apache随系统启动
chkconfig --levels 235 httpd on /etc/init.d/httpd start
7.配置MySQL随系统启动
chkconfig --levels 235 mysqld on /etc/init.d/mysqld start
8.设置数据库root密码
/usr/bin/mysqladmin -u root password 'New+Password#www.yupengyan.com'
9.测试PHP是否安装成功
在 CentOS 中 Apache 的默认根目录是 /var/www/html,配置文件 /etc/httpd/conf/httpd.conf。其他配置存储在 /etc/httpd/conf.d/ 目录。
vi /var/www/html/info.php
按i进入编辑状态,并键入以下内容:
< ?php phpinfo(); ?>
按Esc退出编辑状态,输入:wq ,保存并退出。
重启Apache:
/etc/init.d/httpd restart
浏览器输入服务器的地址,如本地测试:http://localhost/info.php
10.配置phpMyAdmin
phpMyAdmin的三种认证方式:phpmyadmin的三种认证方式config,cookie和http。config认证是在配置文件中直接写 好访问数据库的用户名和密码,访问者可以直接访问到数据库。cookie认证是在用户访问时需要手动输入用户名和密码。另外一种方式是http认证。这种 方式给访问者感觉上看类似cookie。 但是它实际上利用了php的http认证机制,这种机制只有php以Apache方式模块运行时才有效。
cp /etc/phpMyAdmin/config.inc.php /etc/phpMyAdmin/config.inc.php.bak vi /etc/phpMyAdmin/config.inc.php
当认证方式为config时,配置如下:
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL地址,位于相同机器不用改 $cfg['Servers'][$i]['auth_type'] = 'config'; //config认证方法 $cfg['Servers'][$i]['user'] = 'root'; // MySQL user $cfg['Servers'][$i]['password'] = 'sqlRootPwd';// 只有config认证才需要
当认证方式为cookie时,配置如下:
$cfg['blowfish_secret'] = 'myphpcookies';/* COOKIE认证,必须不能为空,可以是任意字符 */ $cfg['Servers'][$i]['host'] = 'localhost'; // MySQL地址,位于相同机器不用改 $cfg['Servers'][$i]['auth_type'] = 'cookie'; //config认证方法,(config)?
当认证方式为http时,配置如下:(本例子就是http认证,要登陆,使用mySql的用户和密码)
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL地址,位于相同机器不用改 $cfg['Servers'][$i]['auth_type'] = 'http';
修改phpMyAdmin的访问控制文件,保证远程访问:
vi /etc/httpd/conf.d/phpMyAdmin.conf
注释掉拒绝访问控制,添加为Allow from All(具体请根据自己应用与安全需要来配置)。
#为了安全,改变默认的目录,通过: http://ip/my-private-phpmyadmin 访问。 Alias /my-private-phpmyadmin /usr/share/phpMyAdmin <Directory /usr/share/phpMyAdmin/> # Order Deny,Allow # Deny from All # Allow from 127.0.0.1 Allow from All </Directory> <Directory /usr/share/phpMyAdmin/setup/> # Order Deny,Allow # Deny from All # Allow from 127.0.0.1 Allow from All </Directory>
重启Apache
service httpd restart
浏览器访问
输入http://localhost/my-private-phpmyadmin (或者http://ip/my-private-phpmyadmin),键入数据库的用户和密码就可以访问了…
11.开通防火墙端口
如果防火墙端口没有开通,还需要增加开放端口:
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT /etc/init.d/iptables save /etc/init.d/iptables restart
如果需要修改Apache的默认端口,在CentOS6环境下,可能还会产生一个Permission denied的错误,他是由SELinux的安全性引起的,具体解决方法,请参考连接:http://blog.csdn.net/dolphinsimon/article/details/7847276
12.参考文献
LAMP (software bundle).http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29