红联Linux门户
Linux帮助

用yum安装Apache,Mysql,PHP,phpMyAdmin搭建LAMP环境

发布时间:2011-04-26 17:58:15来源:红联作者:halazi100
[i=s] 本帖最后由 halazi100 于 2011-5-22 19:42 编辑 [/i]

用yum安装Apache,Mysql,PHP,phpMyAdmin搭建LAMP环境

1、安装Apache
yum install httpd httpd-devel
安装完成后,用/etc/init.d/httpd start 启动apache
设为开机启动:chkconfig httpd on

2、 安装mysql
2.1 yum install mysql mysql-server mysql-devel
同样,完成后,用/etc/init.d/mysqld start 启动mysql
2.2 设置mysql密码
#mysqladmin -u root -p password(设置mysql的root密码)
安装后mysql到root密码默认为空,需要重新设置。
2.3 允许远程登录
mysql -u root -p
Enter Password:
mysql>GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
完成后就能用mysql-front远程管理mysql了。
2.4 设为开机启动
chkconfig mysqld on

3、 安装php
yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
启动服务/etc/init.d/httpd start

4、测试
注意打开防火墙设置,勾选http服务,允许访问80端口,然后应用。
4.1在/var/www/html/新建个test.php文件,将以下内容写入,然后保存。
phpinfo();
?>
4.2 防火墙配置
a.添加.允许访问端口{21: ftp, 80: http}.
iptables -I RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 21 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT
b.关闭防火墙{不推荐}.
service iptables stop
c.重置加载防火墙
service iptables restart
4.3然后在客户端浏览器里打开http://serverip/test.php,若能成功显示,则表示安装成功。
详细出处参考:http://www.jb51.net/article/24775.htm



5、安装phpMyAdmin


phpMyAdmin是一种MySQL的管理工具,它直接从web上去管理MySQL。

  假设你的web(网页存放)根目录是 /var/www/ 假设你的主机web访问是这样的 http://10.108.1.86/
  你可以把他安装到 /var/www/phpmyadmin 当然也可是/var/www/的任意下级目录;注意这个目录名字最好只有管理员知道.因此我们假设为 /var/www/onlyyouknow

  A.先到 phpMyAdmin的官方站上下载最近的 phpMyAdmin程序
  http://www.phpmyadmin.net/home_page/

  把 phpMyAdmin-3.3.10-all-languages.tar.gz 下载到 /var/www/
  #cd /var/www/
  #wget http://cdnetworks-kr-1.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.10/phpMyAdmin-3.3.10-all-languages.tar.gz
  当然也可到你自己的windows机器,等以后编辑好了再上传到web服务器上

  B.将此档解压缩

  # tar -zxvf phpMyAdmin-3.3.10-all-languages.tar.gz

  此时路径 /var/www/phpMyAdmin-3.3.10-all-languages

  C. 修改目录名为 /var/www/onlyyoukown

  # mv /var/www/phpMyAdmin-3.3.10-all-languages /var/www/onlyyoukown

  D.修改设定文档

  1.进入到刚解压文件所放位置,如: /var/www/onlyyoukown找到 /libraries/config.default.php文件(config.default.php复制到phpmyadmin目录下,然后更名为 config.inc.php),该文件有如下项目(2-8)须自行配置,windows用写字板(不要用记事本,这是UTF8编码)进行编辑,在 linux下直接用vim编辑.

  2.打开config.default.php文件,查找 $cfg['PmaAbsoluteUri'] 修改为你将上传到空间的phpMyAdmin的网址

  如:$cfg['PmaAbsoluteUri'] = 'http://127.0.0.1/onlyyouknow/';

  3.查找 $cfg['Servers'][$i]['host'] = 'localhost';(通常用默认,也有例外,可以不用修改)

  4.查找 $cfg['Servers'][$i]['auth_type'] = 'config';

  在自己的机子里调试用config;如果在网络上的空间用cookie,这里我们既然在前面已经添加了网址,就修改成cookie ,这里建议使用cookie.

  5.查找 $cfg['Servers'][$i]['user'] = 'root'; // MySQL user(mysql用户名,自己机里用root;)

  6.查找 $cfg['Servers'][$i]['password'] = ''; // MySQL password (mysql用户的密码,自己的服务器一般都是mysql用户root的密码)

  7.查找 $cfg['Servers'][$i]['only_db'] = ''; // If set to a db-name, only(你只有一个数据就设置一下;如果你在本机或想架设服务器,那么建议留空)

  8.查找 $cfg['DefaultLang'] = 'zh'; (这里是选择语言,zh代表简体中文的意思,这里不知道填gbk对否)

  9.设置完毕后保存

  如果出现“配置文件现在需要绝密的短语密码(blowfish_secret)”那么请在$cfg['blowfish_secret'] = ' ';的等号里面设置你网站的cookie,例如:$cfg['blowfish_secret'] = '任意字符';这是因为你的“$cfg['Servers'][$i]['auth_type'] = 'cookie'的原因。

  E.测试

  开启浏览器,http://127.0.0.1/onlyyoukown/

  我们认为从web上可以通过mysql的root用户控制mysql并非一种非常安全的方式.因此我的建议是如果是自己的服务器,当你用完了可以把phpadmin目录放到web不能访问的目录,当要用时把整个目录用mv命令移回原来位置.

推荐linux技术交流QQ群52240781
文章评论

共有 16 条评论

  1. 于 2012-12-11 13:50:55发表:

    配置好了phpMyAdmin后,在网页访问的时候,页面出来 主机名称是空的! 错误。原因是什么呢?配置都正确配置了。

  2. gky2009514 于 2012-12-07 13:28:55发表:

    新手完成任务,求下书籍~

  3. qizhi2026 于 2012-11-28 18:57:23发表:

    Yangtze Evening News (reporter Zhang Lingfei) 6 days morning at seven forty, a young man from Lianyungang through irrigation road bridge, suddenly dived into the tail of the river.An old man saw, down the tricycle, took off his clothes he jumped into the water to save.
    The old man has three times into the river to save, in to the police and fire officers and soldiers help, will young man from three meters deep in water rescue ashore.On the same day at around 8 a.m., the Yangtze Evening News received a public report expected that someone in the bridge river road through irrigation.
    After receiving the 5 minutes reporter rushed to the scene.Qualcomm irrigation road bridge head now gathered hundreds of onlookers people, the police have cordoned off the shore, a bald old man wearing only a big underpants, police and fire officers and soldiers are to help him line safety rope, smelly river floating a lifebuoy.
    The subsequent "splash", the old man jumped into the river, seize the buoy to the bridge opening stroke forward.A resident told reporters, this is the old man third in the water, before two because people do not match, failed to rescue the success.
    The aperture is very deep, standing on the shore to see inside, all carers worried.After about 10 minutes, just listen to the bridge opening within a shout "rope", police and fire safety rope to recover quickly.
    In one point one, finally saw the old in front of leaning, with one hand on the ring, with one hand on the suicide kid, he tried to pull the shore.Reporter notes, his body has been old man tied with string.
    On arriving at the shore, the police and the fire brigade to pull, the boy was a direct pull ashore.Then, they will save the old man pulled up on the shore.Shore, old man vomited after slobber it collapsed on the floor, his hands and feet and multiple body is pierced, is bleeding.
    Several police immediately will elder onto the police, sent to nearby hospitals.According to the police of Lianyungang City East police station, police officer introduction, they are seven fifty alarm, then rest in the home of Tang's director also passed the house rushed to the scene, and immediately jump into the river, the river is about 3 meters deep, and no rescue tools, 48 year old Tang director Tilibuzhi, he lived in stable suicide guy mood, and swam back to the shore to find a rope.
    But we find the rope is not long enough, at that time, a member of the public third jumped into the river, will ultimately save ashore.It is understood, three into the old man named Chen Junlai, this year 56 years old, usually on the pedal tricycle soliciting for students.
    In hospital Chen Junlai accepts reporter when the interview said that day, he happened to pass by the local riding a tricycle, heard a man overboard, didn't come and I just thought, the important thing is to save lives, so he took off his clothes and jumped.
    Start the lad did not willing to accept relief, he said to the young man: "you look at my this age's sake, come ashore."Young man may be the three time he tried to move, so to rope him ashore.In the interview, Chen Junlai told reporters, when 33 years old he also because life setback drink pesticide Dutch act, neighborhood and surrounding the public timely sent him to hospital for emergency treatment, which today have him, from then on, he wanted to help others.

  4. HYT461020145 于 2012-11-15 10:05:23发表:

    没成功!

  5. hisonz 于 2012-11-02 05:24:31发表:

    楼主的分享非常不错哦!!支持持续更新!!

  6. eddyshwzl 于 2012-09-05 21:31:51发表:

  7. yangzhi527 于 2011-08-31 15:25:30发表:

    正想学习呢

  8. chaipeng 于 2011-08-18 12:21:21发表:

    好?西!!!!太犀利啦

  9. fengye607 于 2011-06-08 10:26:29发表:

    楼主厉害

  10. dqwit 于 2011-05-31 21:28:35发表:

    牛B啊,谢谢楼主

  11. q7262395 于 2011-05-20 15:01:47发表:

    lz确实强人

  12. xianzai009 于 2011-04-29 21:26:12发表:

    看上去还是蛮牛逼的,先支持

  13. halazi100 于 2011-04-27 17:34:20发表:

    [i=s] 本帖最后由 halazi100 于 2014-4-4 10:48 编辑 [/i]

    4# linuxcui


    很荣幸,多谢支持!!!

  14. linuxcui 于 2011-04-27 16:27:47发表:

    最近产出真多啊,多谢兄弟捧场~~~

  15. Growth兆 于 2011-04-27 09:42:54发表:

    感谢halazi100的分享,本贴加入到论坛顶置的Linux应用贴中

  16. aacble 于 2011-04-26 21:00:02发表:

    学习了