Centos下搭建php环境,安装lamp环境

首先使用yum命令安装或者升级所需的程序库

copy以下命令到命令行回车即可。

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-server krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

一、安装apache

[root@AY12122501352213a7156 ~]# yum install httpd httpd-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * centosplus: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com

........................

中途提示是否下载,输入y,回车,没有什么意外的话等待安装完成。

安装完成后,用/etc/init.d/httpd start  启动apache
您也可以设为开机启动:chkconfig httpd on 。

二、安装mysql

1、安装

[root@AY12122501352213a7156 ~]# yum install mysql mysql-server mysql-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * centosplus: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com

.................

中途可能会出现问题如下:

--> Finished Dependency Resolution
mysql-devel-5.0.95-1.el5_7.1.i386 from updates has depsolving problems
  --> Missing Dependency: mysql = 5.0.95-1.el5_7.1 is needed by package mysql-devel-5.0.95-1.el5_7.1.i386 (updates)
Error: Missing Dependency: mysql = 5.0.95-1.el5_7.1 is needed by package mysql-devel-5.0.95-1.el5_7.1.i386 (updates)
 You could try using --skip-broken to work around the problem
 You could try running: package-cleanup --problems
                        package-cleanup --dupes
                        rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.

说有个包mysql = 5.0.95-1.el5_7.1依赖mysql-devel-5.0.95-1.el5_7.1.i386,需要更新,我们这里不需要,直接重新安装,跳过这个问题即可。

[root@AY12122501352213a7156 ~]# yum install mysql mysql-server mysql-devel --skip-broken

中途提示是否下载,输入y,回车,没有什么意外的话等待安装完成。

完成后,用/etc/init.d/mysqld start 启动mysql  ,或者使用 service mysqld start  启动mysql 。

当然你也可以设置开机启动,命令为:chkconfig mysqld on

2、设置初始密码,没有密码,直接输入mysql命令即可

[root@AY12122501352213a7156 ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.58 MySQL Community Server (GPL) by Utter Ramblings

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>USE mysql; #使用mysql数据库
mysql>UPDATE user SET Password=PASSWORD('新密码') WHERE user='root';   #更改数据库密码
mysql>FLUSH PRIVILEGES; #刷新刚才的操作,否则刚才的操作无效。

3、允许mysql远程登录

[root@AY12122501352213a7156 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql>GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; #给‘用户名’授予所有权限,并且设置密码为‘密码’
完成后就能用SQL-Front软件远程管理mysql了。

注意:为了防止sql出错,命令行失效,你可以在输入sql的结尾最好加上“;”,

三、安装php

1、安装

[root@AY12122501352213a7156 ~]# yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

这样也可能会报mysql类似错误,那就跳过吧

[root@AY12122501352213a7156 ~]# yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml  --skip-broken

完成后重新启动apache:/etc/init.d/httpd start。

2、测试

在/var/www/html/新建个test.php文件,将以下内容写入,然后保存。
<?
phpinfo();
?>

输入地址试试:http://serverip/test.php,good,可以显示说明可以成功。

但是有些时候80端口被占用,或者防火墙原因,无法访问,你可以继续往下看。

3.防火墙配置 或者关闭80端口

3.1、80端口被占用

查看一下80端口:关于端口问题可以参考我前面的文章:http://www.cnblogs.com/wanghaosoft/archive/2013/01/11/find80.html

[root@AY12122501352213a7156 lsof_4.76_src]# netstat -apn |grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      25794/httpd        
unix  2      [ ]         DGRAM                    3580   1303/klogd

如果80端口被占,则结束所占80端口进程,然后重新启动apache服务。如上,我的80端口是apache 的服务占用,25794/httpd ,前面是进程号,后面进程名称。

[root@AY12122501352213a7156 lsof_4.76_src]# kill -9 25794 

3.2、防火墙不允许
通过/etc/init.d/iptables status 查看防火墙状态。如果没有可通过两种方式处理:
a、修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
b、关闭防火墙
#/etc/init.d/iptables stop
#/etc/init.d/iptables start 开启
#/etc/init.d/iptables restart 重启
永久性关闭防火墙chkconfig --level 35 iptables off

至此,lamp环境搭建完成。

 

posted @ 2013-01-11 23:22  我在移动  阅读(2195)  评论(1编辑  收藏  举报
http://www.17le.com.cn