CentOS 安裝 PHP
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
1.獲取PHP安裝檔案: downloads 或直接下載 php-5.5.9.tar.gz
獲取安裝php需要的支援檔案: libxml2
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) 預安裝