您好,登錄后才能下訂單哦!
php的安裝遇到的麻煩比較多,這里將自己安裝的心得分享給大家,希望可以幫到大家。
因為我在編譯php的時候,有指定mysql以及apache的路徑,所以要先安裝mysql和apache,兩者的順序隨意,具體方法可以查看我mysql和apache的安裝方法。關(guān)于PHP版本,我選擇的是5.4版本。
1. php源碼包下載
# cd /usr/local/src ##我習慣將下載的包放到這個路徑
# wget http://cn2.php.net/distributions/php-5.4.44.tar.gz
# tar -zxvf php-5.4.44.tar.gz
2. 配置編譯參數(shù)
# cd ./php-5.4.44
接下來要進行配置編譯參數(shù)的過程,因為中間會一系列的報錯,缺少的庫非常多,所以建議先安裝完所有需要的包,這樣就不會太麻煩了,因為checking的時間會比較長。如果有時間想體驗一下完整的過程,可以按部就班的yum。
先聲明一下,libmcrypt-devel在centos的yum源中是找不到的,需要借助epel的yum源,阿里云的epel源是個不錯的選擇。可以在/etc/yum.repo.d/下新建一個CentOS-Base.repo,將如下內(nèi)容粘貼并保存:
# CentOS-Base.repo
#
# 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 - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
下面是遇到的報錯和解決辦法:
error: xml2-config not found. Please check your libxml2 installation
# yum install -y libxml2-devel
error: Cannot find OpenSSL's <evp.h>
# yum install -y openssl openssl-devel
checking for BZip2 in default path... not found
error: Please reinstall the BZip2 distribution
# yum install -y bzip2 bzip2-devel
error: png.h not found.
# yum install -y libpng libpng-devel
error: freetype.h not found.
# yum install -y freetype freetype-devel
error: mcrypt.h not found. Please reinstall libmcrypt
# yum install -y epel-release
# yum install -y libmcrypt-devel
error: jpeglib.h not found.
# yum install libjpeg-devel
接下來命令行輸入如下配置參數(shù):
#./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc\
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
只要安裝完上面提到的包,一般配置過程是不會報錯的。如果報錯了,根據(jù)錯誤信息,查找相應的包,自行安裝就好了。
配置完畢可以用# echo $?來查看配置過程中有無錯誤,如果返回時0,就說明配置成功了。
3. 接下來就是編譯和安裝了:
# make && make install
經(jīng)過漫長的編譯安裝過程,php就順利安裝完了。別忘啦echo $?來查看過程是否有出錯,不過一般是不會出錯的,返回結(jié)果依然是0!
恭喜你,php順利安裝完了!??!但是,安裝完了還是不能用的,需要進行下面的操作:
# cp php.ini-production /usr/local/php/etc/php.ini
修改apache配置文件# vim /usr/local/apache2/conf/httpd.conf ## 在這里解釋一下,我之前安裝的apache是在/usr/local/apache2下面的。
找到: <Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
將最后一行的Deny改成Allow,如果不修改,以后用瀏覽器訪問我們的服務器的時候,會403禁訪的。
然后找到:AddType application/x-gzip .gz .tgz
在該行下面添加: AddType application/x-httpd-php .php
說明:要想支持php腳本解析,必須要加上對應的類型。
再找到: <IfModule dir_module>
DirectoryIndex index.html
</IfModule>
將中間參數(shù)修改為:DirectoryIndexindex.html index.htm index.php
修改的目的是增加針對php的索引,如果一個站點默認頁為index.php,那么就得加上這個index.php的支持。比如我們要在服務器上安裝一個php論壇,沒有上面的php解析,我們在瀏覽器上面打開配置好的虛擬主機地址的時候,顯示的不是安裝的圖形界面,而是一片源碼?。。?/span>
再找到: #ServerName www.example.com:80
修改為: ServerName localhost:80,將注釋的#去掉,如果不去掉,在啟動apache時,會有警告信息“httpd: Could not reliably determine the server'sfully qualified domain name, using localhost.localdomain for ServerName”,看起來像是錯誤,其實沒有影響。
查看配置文件是否有語法問題:
# /usr/local/apache2/bin/apachectl -t;如果顯示Syntax OK,說明配置沒問題了。
然后啟動服務: # /usr/local/apache2/bin/apachectl start
查看一下httpd的進程: # ps aux |grep httpd,可以看到已經(jīng)在進程表里面出現(xiàn)了httpd,說明已經(jīng)成功完成了配置安裝和最后的參數(shù)配置。
順便說一下,apachectl的路徑太長了,可以在PATH里面增加一個目錄來實現(xiàn)快速執(zhí)行apachectl的命令,具體操作如下:
# vim /etc/init.d/path.sh
#! /bin/bash
export PATH=$PATH:/usr/local/apache2/bin/ -->:wq
# source /etc/init.d/path.sh
這樣,在命令行下面直接輸入apachectl的時候,就可以直接執(zhí)行命令了。
完了,喝口水!如果發(fā)現(xiàn)有錯誤,請留言,
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。