CentOS 安装 PHP

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中。

<?php

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: <your new 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文件,将以下内容写入,然后保存。
<?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) 预安装

yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

2) 升级php

yum --enablerepo=remi,remi-php55 install php-opcache


Unable to load dynamic library '/usr/lib64/php/modules/gd.so

[root@ithomer ~]# php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/gd.so' - libvpx.so.0: cannot map zero-fill pages: Cannot allocate memory in Unknown on line 0
PHP 5.5.9 (cli) (built: Feb 18 2014 14:51:49)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

解决:

How To Add Swap on CentOS 6

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

libcurl.so.3

Error: Package: php-common-5.3.28-2.w5.x86_64 (webtatic)
Requires: libcurl.so.3()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest


yum install libcurl libcurl-devel


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


MySQL 升级

CentOS 5.5的源mysql目前还停留在5.0.19上,要做数据库主从的时候,必须升级到5.1以上,索性直接到5.5.36

1、安装MySQL 5.5.x的yum源:

rpm -Uvhhttp://repo.webtatic.com/yum/centos/5/latest.rpm

2、安装MySQL客户端的支持包:

yum install libmysqlclient15 --enablerepo=webtatic

3、卸载MySQL老版本的软件包:

yum remove mysql mysql-*

4、安装MySQL 5.5的客户端和服务端:

yum install mysql55 mysql55-server --enablerepo=webtatic

5、启动MySQL系统服务,更新数据库:

/etc/init.d/mysqld restart

mysql_upgrade -uroot -proot

升级完毕

/etc/init.d/mysqld restart


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

升级 1(推荐)

To list Old MySql
yum list installed | grep -i mysql


To remove Old MySql
yum remove mysql mysql-*


Remi Dependency on CentOS 6 and Red Hat (RHEL) 6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


Install MySQL server
yum --enablerepo=remi,remi-test install mysql mysql-server


To list New MySql
yum list installed | grep -i mysql
start MySql server


/etc/init.d/mysqld start ## use restart after update
OR
service mysqld start ## use restart after update

chkconfig --levels 235 mysqld on


Last
mysql_upgrade -u root -p
Now my MySql version is 5.5.32

Ref:
http://www.webtatic.com/packages/mysql55/
http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/

update MySQL version from 5.1 to 5.5 in CentOS 6.2



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


ERROR 1045 (28000): Access denied for user 'ithomer'@'localhost' (using password: YES)

/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables &
mysql -u root
mysql> use mysql;

mysql>grant all privileges on *.* to "root"@"%" identified by "password" with grant option; flush privileges; # 添加用户

mysql>grant Select on your_dbname.* to "username"@"%" identified by "password" with grant option; flush privileges; # 赋值只读权限(Select)
mysql> update user set password=PASSWORD("newrootpassword") where User='root';flush privileges; # 修改密码
mysql> quit
/etc/init.d/mysqld restart

/etc/init.d/mysqld stop
/etc/init.d/mysqld start

CentOS 安装 PHP_第1张图片


rpm安装

1.安装命令
rpm -ivh filename.rpm
参数解释
-i安装
-h 解压rpm的时候打印50个斜条 (#)
-v 显示详细信息

2.升级命令
rpm -Uvhfilename.rpm
参数解释
-U 升级
-h 解压rpm的时候打印50个斜条 (#)
-v 显示详细信息


rzsz安装

ubuntu:sudo apt-get install lrzsz

centos:yum -y install lrzsz


hostname修改

需修改两处:

1)vim /etc/sysconfig/network 修改 HOSTNAME=your_hostname

2)vim /etc/hosts 修改 12.160.134.168 your_hostname


Python 安装

1) 下载Python, 直接下载Python-2.7.6.tar.xz

2) 安装.tar.xz 解压工具:yum -y install xz

3) 解压.tar.xz文件:unxz Python-2.7.6.tar.xz 和 tar xvf Python-2.7.6.tar

4) cdPython-2.7.6

5)./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

make && make altinstall


pip 安装

1)wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

2)python2.7 ez_setup.py

3)easy_install-2.7 pip

4)pip2.7 install [packagename]

pip2 . 7 install -- upgrade [ packagename ]
pip2 . 7 uninstall [ packagename ]

LAMP 配置截图

CentOS 安装 PHP_第2张图片


升级 3 —— httpd(apache server)

$ vi /etc/yum.repos.d/centalt.repo
[CentALT]
name=CentALT Packages for Enterprise Linux 6 - $basearch
baseurl=http://centos.alt.ru/repository/centos/6/$basearch/
enabled=1
gpgcheck=0

yum update httpd

参考:Upgrade apache/httpd to 2.2.23 in CentOS



安装 Git

通过命令 yum install git 安装的是老版本(1.7.1)

想安装最新的git,步骤如下:

1)yum install perl-DBI -y

2)wget http://pkgs.repoforge.org/git/git-1.7.10-1.el6.rfx.x86_64.rpm

wget http://pkgs.repoforge.org/git/perl-Git-1.7.10-1.el6.rfx.x86_64.rpm

3)rpm -i git-1.7.10-1.el6.rfx.x86_64.rpm perl-Git-1.7.10-1.el6.rfx.x86_64.rpm

4) git --version

git version 1.7.10

参考: 参考1参考2, github要求git在版本 1.7.6以上


安装 Subversion

1) 安装客户端, 命令: yum install subversion

Install SVN server in Centos 6.x



参考推荐:

Linux安装配置php

Ubuntu安装配置MySQL

CentOS 5.5使用yum来安装LAMP

Win7下安装Apache+PHP+MySQL

MySQL赋值用户权限GRANT用法(推荐)


WordPress的安装过程

WordPress数据库及各表结构


2)wget http://pkgs.repoforge.org/git/git-1.7.10-1.el6.rfx.x86_64.rpm

你可能感兴趣的:(centos)