CentOS 安装 PHP

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

1.获取PHP安装文件: downloads  或直接下载 php-5.5.9.tar.gz

  获取安装php需要的支持文件: libxml2  或直接下载 libxml2-2.9.1.tar.gz

2.安装libxml2

 tar zxvf libxml2-2.9.1.tar.gz cd libxml2-2.6.32 ./configure --prefix=/usr/local/libxml2  make make install

如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib、man和share五个目录。在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/ local/libxml2"选项,用于指定安装libxml2库文件的位置

3.安装php5

#tar zvxf php-5.3.8.tar.gz
#cd php-5.3.8#./configure \ --prefix=/usr/local/php \ --with-mysql=/usr/local/mysql \  --with-apxs=/usr/local/apache2/bin/apxs \--with-libxml-dir=/usr/local/libxml2#make #make install 

4.重新配置apache2让他支持php

  • 配置 httpd.conf 让apache支持PHP:

  # vi /usr/local/apache/conf/httpd.conf

  找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容

  AddType application/x-httpd-php .php      (.前面有空格)

  AddType application/x-httpd-php-source .phps        (.前面有空格)

  • 然后CPOPY PHP的配置文件

  cp php-5.3.8/php.ini.dist /usr/local/php/lib/php.ini 

    (如果没有php.ini.dist 则把php.ini-development php.ini-production中的任何一个重命名为php.ini.dist即可。)

  修改php.ini文件 register_globals = On

  • 重启apache

  service apache restart

5.测试php是否成功安装

写一个php测试页info.php,放到apache2/htdocs中。

 phpinfo(); 

?>; 

在浏览器中输入:服务器地址/info.php

如果能正常显示出php的信息,则说明Apche+Mysql+PHP安装成功!


------------------------------


CentOS 5.5使用yum来安装LAMP


1. 换源,使用sohu安装源
1.1 备份CentOS-Base.repo 
cd /etc/yum.repos.d/ 
cp CentOS-Base.repo CentOS-Base.repo.bak 
1.2 替换源 
用vi打开CentOS-Base.repo,并将内容清空,然后将下面的内容复制进去,并保存。 
# CentOS-Base.repo 

# This file uses a new mirrorlist system developed by Lance Davis for CentOS. 
# The mirror system uses the connecting IP address of the client and the 
# update status of each mirror to pick mirrors that are updated to and 
# geographically close to the client. You should use this for CentOS updates 
# unless you are manually picking other mirrors. 

# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead. 


[base] 
name=CentOS-$releasever - Base 
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#released updates 
[updates] 
name=CentOS-$releasever - Updates 
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#packages used/produced in the build but not released 
[addons] 
name=CentOS-$releasever - Addons 
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#additional packages that may be useful 
[extras] 
name=CentOS-$releasever - Extras 
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#additional packages that extend functionality of existing packages 
[centosplus] 
name=CentOS-$releasever - Plus 
baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/ 
gpgcheck=1 
enabled=0 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 

1.3更新一下 yum -y update 


2. 用yum安装Apache、Mysql、PHP
2.1 安装Apache 
yum install httpd httpd-devel 
安装完成后,启动apache 

/etc/init.d/httpd start 
设为开机启动:chkconfig httpd on 
2.2 安装mysql 
yum install mysql mysql-server mysql-devel 
完成后,启动mysql 

/etc/init.d/mysqld start 
2.2.2 设置mysql密码 

mysql -uroot
mysql> USE mysql; 
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root'; FLUSH PRIVILEGES; 
2.2.3 允许远程登录 
mysql -u root -p 
Enter Password:  
mysql>GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;  FLUSH PRIVILEGES; 
完成后就能用mysql-front远程管理mysql了。 
2.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. 测试一下 
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,若能成功显示,则表示安装成功。 
至此,安装完毕。感慨,yum真是太好用了。



PHP 升级

1.先查看当前php版本
#php -v

2.升级php版本
rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy

wget -P /etc/yum.repos.d/ http://repo.webtatic.com/yum/webtatic.repo

yum --enablerepo=webtatic update php mysql
升级php最好是连mysql一起升级,好了可以看到php已经升级成5.3.28

3、查看升级后的php版本

#php -v

PHP 5.3.28 (cli) (built: Dec 15 2013 17:43:05) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

可以看到php的版本已经更新到5.3.X

重启 /etc/init.d/httpd restart 或 apache  service httpd restart


----------------------

升级 2(推荐)

1) 预安装

你可能感兴趣的:(CentOS 安装 PHP)