第一步:安装apache mysql php
#yum install httpd httpd-devel mysql mysql-server mysql-devel php -y
//安装apacher服务器、apacher所需的库和包含文件、MySQL服务器、MySQL所需的库和包含文件、PHP
系统提示:
Installing
httpd-devel、mysql-server、mysql、mysql-devel、php
installing for dependencies:
apr-devel、apr-util-devel、cyrus-sasl-devl、db4-devel、e2fsprogs-devel、expat-devel、gcc、glibc-debel、glibc-headers、kernel-headers、keyutils-libs-devel、krb5-devel、libselinux-devel、libsepol-devel、openldap-devel、openssl-devel、perl-DBD-MySQL、perl-DBI、php-cli、php-common、zlib-devel、
第二步:配置MySQL
创建mysql启动链接
chkconfig --levels 235 mysqld on //这样mysql会随着系统启动而启动
启动mysql
#etc/init.d/mysqld start
给root设置密码:
# mysql_secure_installation
系统提示:
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): (一般刚装上mysql,root没有密码,在此直接Enter)
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y
New password: 12345678 //设定新密码
Re-enter new password:12345678 //再次确认密码
之后一路Enter就可以了
第三步:测试apache和php
修改vi /etc/httpd/conf/httpd.conf
把ServerName 注释去掉,后面的内容改成 localhost:80
创建httpd启动链接
chkconfig --levels 235 httpd on
启动apache
/etc/init.d/httpd start
apache测试:在浏览器里输入服务器IP,打开后看到apache那经典的页面,OK!apache正常运行了(如开了防火墙,不要忘记在防火墙放行www)。
PHP测试:创建个php.info
vim /var/www/html/info.php
<?php
phpinfo();
?>
然后在浏览器里输入http://IP/info.php应该能看到测试页面
第四步:让PHP支持mysql
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring
系统提示:(安装以下软件包)
Installed:
php-gd.i386 0:5.1.6-27.el5_5.3 php-imap.i386 0:5.1.6-27.el5_5.3 php-ldap.i386 0:5.1.6-27.el5_5.3
php-mbstring.i386 0:5.1.6-27.el5_5.3 php-mysql.i386 0:5.1.6-27.el5_5.3 php-odbc.i386 0:5.1.6-27.el5_5.3
php-pear.noarch 1:1.4.9-6.el5 php-xml.i386 0:5.1.6-27.el5_5.3 php-xmlrpc.i386 0:5.1.6-27.el5_5.3
安装好后再重启httpd
#/etc/init.d/httpd restart
再在浏览器里输入http://IP/info.php应能看到mysql的模块
第五步:安装phpmyadmin
在centos里phpmyadmin无法用yum install来安装,先要加入
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
然后再
yum install phpmyadmin
系统提示将装安装下列程序包
Installed:
phpmyadmin.noarch 0:2.11.11.3-2.el5.rf
Dependency Installed:
libmcrypt.i386 0:2.5.8-4.el5.centos php-mcrypt.i386 0:5.1.6-15.el5.centos.1
修改phpmyadmin.conf让用户可以远程登录
vim /etc/httpd/conf.d/phpmyadmin.conf
将下面的语句全部注释掉
<Directory "/usr/share/phpmyadmin">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
再在浏览器里输入:http://IP/phpmyadmin这时能看到phpmyadmin的管理页面,不过会提示:“配置文件现在需要绝密的短密码(blowfish_secret)。”
解决办法有两种:(建议用第二种)
1、配置phpmyadmin下的config.inc.php 将cookie改为http
vi /usr/share/phpmyadmin/config.inc.php
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = ‘cookie’;
[...]
再打开浏览器输入管理地址,这时会弹出登录窗口,输入用户名及密码及可。
不过很不习惯,而且在进入管理界面后,选择登出时会再次弹出,让人感觉登出也要密码似的。
2、对比了一下ubuntu的phpmyadmin的配置,在ubuntu的config.inc.php里有这样一段配置
// Load secret generated on postinst
include('/var/lib/phpmyadmin/blowfish_secret.inc.php');
再查看一下/var/lib/phpmyadmin/blowfish_secret.inc.php,只有一句
<?php
$cfg['blowfish_secret'] = 'w1HM7AxcX5aQvutjVOyGdepy';
那么CentOS下安装的phpmyadmin中的“$cfg['blowfish_secret'] =”语句在config.inc.php里
vim /usr/share/phpmyadmin/config.inc.php
找到
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
在=后面加上任意字符
$cfg['blowfish_secret'] = centos''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
centos是我随意加上的字符
重启httpd再打开管理页面
还是这个看着习惯点,不过再输入root及密码,系统提示我root@localhost密码错误:error 'Access denied for user 'root'@'localhost' (using password: NO),总是进不去,于是清理了一下浏览器的cookie,再进就正常进入了。