CentOS 6.5 下源碼搭建LAMP環境

參考網站:php

http://wenku.baidu.com/link?url=Cvkqss2E9mnxXOZigMWPaCfqwsBxnm0sZ4aKE2oLAgQ888XxeC0DWOChxVqiHztL6DZRo6LqdKR7oJ6DgU4gbQJrqNuvaJY-zdeOMf3tzwShtml

1         搭建前準備工做

1.1         軟件安裝包的獲取

因爲本文搭建LAMP環境使用的是源碼安裝,在安裝過程當中須要使用到許多的軟件安裝包,所以在安裝過程當中應該首先把須要用到的安裝包進行下載,須要使用的軟件安裝包以及下載地址以下所示:node

httpd-2.4.9.tar.gz              mysql

http://httpd.apache.org/linux

mysql-5.7.4.tar.gz            c++

http://dev.mysql.com/downloads/web

php-5.5.14.tar.gz             sql

http://cn2.php.net/downloads.phpshell

phpMyAdmin-4.2.5-all-languages.tar.gz 數據庫

http://www.phpmyadmin.net/home_page/downloads.php

libxml2-2.9.0.tar.gz           

ftp://xmlsoft.org/libxml2/

libmcrypt-2.5.8.tar.gz          

ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/

libgd-2.1.0.tar.gz              

https://bitbucket.org/libgd/gd-libgd/downloads

zlib-1.2.8.tar.gz

http://www.zlib.net

autoconf-2.69.tar.gz

http://ftp.gnu.org/gnu/autoconf/

freetype-2.5.3.tar.gz

http://download.savannah.gnu.org/releases/freetype/

libpng-1.6.12.tar.gz

ftp://ftp.simplesystems.org/pub/libpng/png/src/

jpegsrc.v9a.tar.gz

http://www.ijg.org/files/

ZendGuard-5_5_0.tar.gz

http://www.zend.com/en/products/guard/thank-you-zend-guard?package=415

apr-1.5.1.tar.gz

http://apr.apache.org/download.cgi

apr-util-1.5.3.tar.gz

http://apr.apache.org/download.cgi

pcre-8.35.zip

http://sourceforge.net/projects/pcre

本文搭建的LAMP環境大體須要上述安裝包,若是在搭建過程當中碰到還須要其餘安裝版的狀況能夠下載對應安裝包便可。

1.2         將軟件包放置在Linux系統上

首先須要下載安裝輔助工具XFtp來對本機上下載的軟件包進行移植,下載完成後打開Xshell界面,鏈接須要搭建LAMP的虛擬機,點擊「新建文件傳輸(CTRL+ALT+F)」按鈕打開XFtp工具自動創建與虛擬機的鏈接。鏈接XFtp方式以下圖所示:

 

點擊「新建文件傳輸」按鈕以後進入以下界面極爲成功。

 

在虛擬機上的/usr/local/src目錄下新建LAMP文件夾,將本機上下載的軟件安裝包傳輸到LAMP文件夾之下。

1.3         編譯工具的安裝以及卸載默認LAMP環境

LAMP環境搭建所須要的軟件都使用C語言開發的,因此安裝源代碼文件最少須要配置(configure)、編譯(make)、安裝(make install)三個步驟,在虛擬機上輸入‘gcc -v’命令,若是gcc已安裝,則以下圖所示:

 

不然應該首先安裝編譯工具,使用yum安裝,輸入命令行‘yum -y install make gcc gcc-c++ zlib-devel libaio’。 

檢查系統中是否存在已安裝的LAMP環境,以Apache爲例,輸入‘rpm -qa | grep -i httd’,若是存在已安裝的Apache,則應使用‘rpm –e httpd-xxx -nodeps’卸載Apache(xxx爲版本號),MySql與PHP操做與Apache相同。

1.4         防火牆端口的配置以及SELINUX的關閉

編輯/etc/sysconfig/iptables文件,配置防火牆,命令以下‘vim /etc/sysconfig/iptables’

在‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 22 –j ACCEPT’下添加以下命令

‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 80 –j ACCEPT’

‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 3306 –j ACCEPT’

保存退出。

因爲SELINUX的開啓可能會對MySql形成必定的影響,因此提早關閉SELINUX

輸入命令‘vim /etc/selinux/config’進入編輯界面,修改以下內容:

#SELINUX=enforcing   #將該行註釋

#SELINUXTYPE=targeted   將該行註釋

SELINUX=disabled   #增長內容

完成上述操做後,重啓系統‘shutdown –r now’

1.5         搭建須知

(1)解壓tar.gz爲後綴的壓縮包軟件 

LAMP環境搭建所須要的每一個軟件的源代碼文件,都是以.tar.gz提供給咱們的打包壓縮文件,因此咱們必須將其解壓再解包。可經過命令#tar zxvf xxxx.tar.gz達到目的。

(2)在linux系統中源代碼包安裝過程

進行解壓後的目錄,LAMP環境搭建所須要的軟件都使用C語言開發的,因此安裝源代碼文件最少須要配置(configure)、編譯(make)、安裝(make install)三個步驟。

2         apache的安裝

卸載本機上存在的apr,apr-util,命令爲‘yum removed apr apr-util’

2.1         編譯安裝apr

命令以下

cd /usr/local/src/lamp    #

tar zxvf apr-1.5.1.tar.gz   #解壓縮命令,tar zxvf apr-xxx.tar.gz(xxx爲版本號)

cd apr-1.5.1            #

./configure --prefix=/usr/local/apr-httpd  #配置,制定apr安裝位置以及安裝目錄

make                 #編譯

make install           #安裝

2.2         編譯安裝apr-util

命令以下

[root@centos6 LAMP]#tar zxvf apr-util-1.5.3.tar.gz

[root@centos6 LAMP]#cd apr-util-1.5.1

[root@centos6apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util-httpd/ \

>--with-apr=/usr/local/apr-httpd/

[root@centos6apr-util-1.5.3] # make

[root@centos6apr-util-1.5.3] # make install

2.3         編譯安裝pcre

[root@centos6 LAMP]#unzip –o pcre-8.35.zip

[root@centos6 LAMP]#cd pcre-8.35

[root@centos6 pcre-8.35]#./configure--prefix=/usr/local/pcre

[root@centos6 pcre-8.35]#make

[root@centos6 pcre-8.35]# make install

2.4         編譯安裝apache

[root@centos6 LAMP]# tar zxvf httpd-2.4.9.tar.gz

[root@centos6 LAMP]# cd httpd-2.4.9

[root@centos6 LAMP]#./configure --prefix=/usr/local/apache249 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-rewrite=shared --enable-static-support --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/ --with-pcre=/usr/local/pcre/ --disable-userdir

[root@centos6 LAMP]# make

[root@centos6 LAMP]# make install

安裝完成後進入/usr/local/apache249目錄下,檢查是否有以下文件

bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules

啓動Apache服務器,並查端口是否開啓,啓動Apache服務器的命令行以下:

[root@centos6 httpd-2.4.9]#/usr/local/apache249/bin/apachectl start

若提示信息以下:

AH00558:httpd:Could not reliably determine the server's fully qualified domain name, using::1.Set the ServerName' directive globally to suppress this message

解決方案:

[root@centos6 httpd-2.4.9]#vim/etc/httpd/httpd.conf

加上下面一行使用80端口,重啓apache

ServerName localhost:80

2.5         測試安裝以及設置開機啓動

測試安裝結果,打開瀏覽器,在地址欄中輸入網絡適配器(僅主機模式)的IP地址,本次安裝爲:http://192.168.78.2/若是瀏覽器中出現It works!則代表Apache服務器可使用。

每種服務器軟件都有必要製成開機時自動啓動,Apache服務器開機自動啓動,只要在「/etc/rc.d/rc.local」文件,加上Apache服務器的啓動命令便可。能夠直接打開「/etc/rc.d/rc.local」文件,在最後一行寫入Apache啓動命令,也能夠用echo命令追加進去,以下命令行示:

[root@localhost apache243]#echo "/usr/local/apache243/bin/apachectl start" >> /etc/rc.d/rc.local

[root@centos6 LAMP]# /usr/local/apache/bin/apachectl start

[root@centos6 LAMP]#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[root@centos6 LAMP]#chmod +x /etc/init.d/httpd

[root@centos6~]# chkconfig –add httpd

3         編譯安裝MySql

3.1         編譯安裝cmake,ncurses-devel

1.下載軟件cmake-3.0.0.tar.gz    http://www.cmake.org/

[root@centos6~]# tar zxvf cmake-3.0.0.tar.gz

[root@centos6~]# cd cmake-3.0.0

[root@centos6~]#./bootstrap

[root@centos6~]# gmake

[root@centos6~]# make&&make install

2.安裝ncurses-devel

首先須要使用yum安裝了下ncurses-devel

[root@centos6~]# yum -y install ncurses-devel

3.2         安裝MySql

(1)建立用戶,組和目錄

[root@centos6~] groupadd mysql

[root@centos6~] useradd mysql -g mysql

[root@centos6~]#mkdir /usr/local/mysql //建立安裝目錄

[root@centos6~]#mkdir /usr/local/mysql/data//建立數據倉庫目錄

(2)編譯安裝mysql

[root@centos6~]#tar zxvf mysql-xxxx.tar.gz

[root@centos6~]# cd mysql-VERSION

[root@centos6~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 .

若出現下述錯誤:

CMake Error at cmake/boost.cmake:81 (MESSAGE):

  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

 

  This CMake script will look for boost in <directory>.  If it is not there,

  it will download and unpack it (in that directory) for you.

 

  If you are inside a firewall, you may need to use an http proxy:

 

  export http_proxy=http://example.com:80

 

Call Stack (most recent call first):

  cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)

  CMakeLists.txt:451 (INCLUDE)

則需先如今boost軟件包,將其置於/usr/local/src/Lamp/下並解壓,執行下述命令:

‘cmake –DWITH_BOOST=/usr/local/src/Lamp/boost_VERSION’

注意:若第一次的配置錯誤,須要先刪除當前mysql源碼目錄中的CMakeCache.txt(不是cmake源碼目錄中的),而後再從新進行cmake配置。

 

[root@centos6~]# make

[root@centos6~]# make install

(3)配置mysql

[root@node-2~]# cd /usr/local/mysql

[root@node-2 mysql]# chown -R mysql .

[root@node-2 mysql]# chgrp -R mysql .

 

[root@node-2 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql

--datadir=/usr/local/mysql/data

Installing MySQL system tables...2016-08-18T23:43:37.858543Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

OK

 

Filling help tables...2016-08-18T23:43:39.517872Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'

  /usr/local/mysql/bin/mysqladmin -u root -h node-2 password 'new-password'

 

Alternatively you can run:

  /usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

 

  cd /usr ; /usr/local/mysql/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

 

  cd mysql-test ; perl mysql-test-run.pl

 

Please report any problems at http://bugs.mysql.com/

 

The latest information about MySQL is available on the web at

 

  http://www.mysql.com

 

Support MySQL by buying support/licenses at http://shop.mysql.com

 

WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as /usr/local/mysql/my-new.cnf,

please compare it with your file and take the changes you need.

 

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

datadir參數:該參數指定了MySQL的數據庫文件放在什麼路徑下。數據庫文件即咱們常說的 MySQL data文件

basedir參數:該參數指定了安裝MySQL的安裝路徑,填寫全路徑能夠解決相對路徑所形成的問題。每次執行命令,都要注意這兩個參數的路徑是否正確。

[root@node-2 mysql]# bin/mysqld --initialize --datadir=/data/mysql   # MySQL 5.7.6 and up

生成以下配置參數,這時會生成一個臨時密碼,須要使用這個密碼,配置參數以下:

2016-08-18T06:51:23.713276Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-08-18T06:51:23.713328Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2016-08-18T06:51:23.713332Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

2016-08-18T06:51:23.954081Z 0 [Warning] InnoDB: New log files created, LSN=45790

2016-08-18T06:51:23.992705Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2016-08-18T06:51:24.049838Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2d9c983a-6510-11e6-9485-005056bf19ae.

2016-08-18T06:51:24.050263Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2016-08-18T06:51:24.051129Z 1 [Note] A temporary password is generated for root@localhost: uqhaukpu5L&u

可能出現的問題:

2016-08-18T23:14:58.692187Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-08-18T23:14:58.692231Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2016-08-18T23:14:58.692235Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

2016-08-18T23:14:58.693872Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

2016-08-18T23:14:58.693896Z 0 [ERROR] Aborting

處理方法

cd /usr/local/mysql/data目錄下執行rm–rf *

 [root@node-2 mysql]# bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up

[root@node-2 mysql]# chown -R root .

[root@node-2 mysql]# chown -R mysql data

[root@node-2 mysql]# bin/mysqld_safe --user=mysql&

(4)設置開機啓動

[root@node-2 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

[root@node-2 mysql]# cp support-files/my-default.cnf /usr/local/mysql/my.cnf //拷貝配置文件

[root@node-2 mysql]# vim my.cnf  //編輯配置文件,加入下列內容。

[mysqld]

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

socket = /usr/local/mysql/mysql.sock

user = mysql

port = 3306

[mysqld_safe]

pid-file = /usr/local/mysql/data/node-2.pid   //該路徑須要配置正確,若是不知道該路徑,可以使用命令查看

[root@node-2 mysql]# ps aux | grep mysql

root      9081  0.0  0.0 113120  1516 ?        Ss   15:06   0:00 /bin/bash /usr/bin/mysql-systemd-start post

root     12296  0.0  0.0 113256  1608 pts/2    S    15:14   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/node-2.pid

mysql    12613  0.1  2.1 1822880 168616 pts/2  Sl   15:14   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --usermysql --log-error=/var/log/mysqld.log --pid-file=/usr/local/mysql/data/node-2.pid --socket=/usr/local/mysql/mysql.sock --port=3306

root     13047  0.0  0.0 112664   984 pts/2    S+   15:16   0:00 grep --color=auto mysql

(5)配置環境變量

將mysql的bin目錄加到PATH中,有利於之後管理和維護,在/etc/profile中加入myslq/bin,同時增長兩個別名方便操做。 

注:後面兩個別名不加也能夠,加上之後的操做更方便。

[root@node-2 mysql]# export PATH=/usr/local/mysql/bin:$PATH

[root@node-2 mysql]# alias mysql_start="mysqld_safe&"

[root@node-2 mysql]# alias mysql_stop="mysqladmin -u root –p shutdown"

(6)登陸mysql

[root@node-2 mysql]# /etc/init.d/mysql.server start

出現Starting MySQL SUCCESS!則說明啓動成功

[root@centos6~]#mysql –u root –p   #輸入用戶名密碼顯示以下界面則說明登錄成功

(密碼在root目錄下的.mysql_secret文本中)

 

(7)修改密碼

登錄進去以後:

Mysql>set password = password('xxxxxx');

4         編譯安裝php

4.1         編譯安裝libxml2

注:libxml2是一個xml的c語言版的解析器,不只支持c語言,還支持c++、php、Pascal、Ruby、Tcl等語言的綁定

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]# tar –zxvf libxml2-2.7.8.tar.gz

[root@centos6 LAMP]# cd ./libxml2-2.7.8

[root@centos6 libxml2-2.7.8]# ./configure --prefix=/usr/local/libxml2/

[root@centos6 libxml2-2.7.8]#make

[root@centos6 libxml2-2.7.8]#make install

注:選項--prefix=/usr/local/libxml2做用是將軟件安裝到/usr/local/libxml2 目錄下。 

若是安裝成功之後,在/usr/local/libxml2/目錄下將生成bin,include,lib,share四個目錄。在後面安裝PHP5源代碼的配置時,會經過在configure命令的選項中加上"--with-libxml-dir=/usr/local/libxml2"選項,用於指定安裝libxml2庫文件的位置。

4.2         編譯安裝libmcrypt

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]#tar –zxvf libmcrypt-2.5.8.tar.gz

[root@centos6 LAMP]# cd ./libmcrypt-2.5.8

[root@centos6 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/

[root@centos6 libmcrypt-2.5.8]#make

[root@centos6 libmcrypt-2.5.8]#make install

若是安裝成功就會在/usr/local/libmcrypt/目錄下生成bin,include,lib,man,share五個目錄。而後在安 裝

PHP5源代碼包的配置時,就能夠經過configure命令加上「--with-mcrypt-dir=/usr/local/libmcrypt」選項,指定這個libmcrypt庫文件的位置。

如./configure時報錯:configure:error:C++ compiler cannot create executables。

解決方案:運行下面命令,而後從新configure(配置)

Yum install gcc gcc-c++ gcc-g77

安裝完成libmcrypt庫之後,不一樣的linux系統版本有可能還要安裝一下libltdl庫。安裝方法和前面的步驟相同,能夠進入到解壓縮的目錄/usr/local/src/libmcrypt-2.5.8下,找到libltdl庫源代碼所在的目錄libltdl,進入這個目錄按照下面幾個命令配置、編譯、安裝就能夠了。[root@localhost  libltdl]#pwd /usr/local/src/libmcrypt-2.5.8/libltdl    //進入軟件源代碼目錄 

[root@localhost libltdl]#./configure –enable-ltdl-install            //配置ltdl庫的安裝

[root@localhost libltdl]#make                                  //編譯

[root@localhost libltdl]#make install                            //安裝

4.3         編譯安裝zlib

注:zlib是提供數據壓縮用的函式庫

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]# tar –zxvf zlib-1.2.5.tar.gz

[root@centos6 LAMP]#cd ./zlib-1.2.5

[root@centos6 zlib-1.2.5]#./configure --prefix=/usr/local/zlib/

[root@centos6 zlib-1.2.5]#make

[root@centos6 zlib-1.2.5]#Make install

若是安裝成功將會在/usr/local /zlib目錄下生成include,lib,share三個目錄。在安裝PHP5配置時,在configure命令的選項中加上「--with- zlib-dir=/usr/local/libmcrypt」選項,用於指定zlib庫文件位置。

4.4         編譯安裝libpng

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]# tar –zxvf libpng-1.5.4.tar.gz

[root@centos6 LAMP]#cd ./libpng-1.5.4

[root@centos6 libpng-1.5.4]#

./configure --prefix=/usr/local/libpng/ --enable-shared 

[root@centos6 libpng-1.5.4]#make

[root@centos6 libpng-1.5.4]#make install

在./configure --prefix=/usr/local/libpng這步最後會提示:configure:error:Zlib not installed

解決方法以下: 

1)進入zlib的源文件目錄,執行命令make clean,清除zlib;

2)從新配置./configure,後面不要接--prefix參數;

3)make&&make install;

4)進入libpng目錄,執行命令./configure --prefix=/usr/local/libpng;

5)make&&make install;

6)安裝成功.

若是安裝成功將會在/usr/local/libpng目錄下生成bin,include,lib和share四個目錄。在安裝GD2庫配置時,經過在configure命令選項中加上「--with-png=/usr/local/libpng」選項,指定libpng庫文件的位置。

4.5         編譯安裝jpeg

 注:安裝GD2庫前所需的jpeg8庫文件,須要本身手動建立安裝須要的目錄,它們在安裝時不能自動建立。

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]# tar –zxvf jpegsrc.v8c.tar.gz

[root@centos6 LAMP]# cd ./jpeg-8c/

 [root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/

[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/bin/(建立存放命令的目錄)

[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/lib/(建立jpeg庫文件所在目錄)

[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/include/(建立存放頭文件目錄)

[root@centos6 jpeg-8c]# mkdir –p /usr/local/jpeg/man/man1(創建存放手冊的目錄) 

[root@centos6 jpeg-8c]#./configure --prefix=/usr/local/jpeg/ \

>--enable-shared \

>--enable-static(創建共享庫使用的GNU的libtool和靜態庫使用的GNU的libtool) 

[root@centos6 jpeg-8c]#make &&make install

 在安裝GD2庫配置時,能夠在configure命令的選項中加上「--with-jpeg=/usr/local/jpeg8」選項,指定jpeg8

庫文件的位置。安裝PHP時也要指定該庫文件的位置。

4.6         編譯安裝freetype

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]#tar –zxvf freetype-2.4.6.tar.gz

[root@centos6 LAMP]# cd ./freetype-2.4.6

[root@centos6 freetype-2.4.6]#

./configure --prefix=/usr/local/freetype/ --enable-shared

[root@centos6 freetype-2.4.6]#make&&make install

若是安裝成功將會在/usr/local/freetype目錄下存在bin,include,lib和share四個目錄。並在安裝GD2庫

時,經過configure命令選項中加上「--with-freetype=/usr/local/freetype/」選項,指定freetype庫文件位置。

4.7         編譯安裝autoconf

惟一注意的地方是configure時,不用指定路徑。

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]#tar –zxvf autoconf-2.68.tar.gz

[root@centos6 LAMP]# cd ./autoconf-2.68

[root@centos6 autoconf-2.68]#./configure

[root@centos6 autoconf-2.68]#make&&make install

4.8         編譯安裝GD

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]# tar –zxvf gd-2.0.35.tar.gz

[root@centos6 LAMP]# cd ./gd-2.0.35

[root@centos6 gd-2.0.35]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/

[root@centos6 gd-2.0.35]# make&&make install

若是安裝成功會在/usr/local/gd/目錄下存在bin、include和lib這三個目錄。在安裝PHP5時,經過在

configure命令選項中加上「--with-gd=/usr/local/gd」選項,指定GD庫文件的位置。若是報錯:

gd_png.c中gdMalloc函數的問題

make[2]:***[gd_png.lo]Error1

make[2]:Leaving directory /tmp/gd-2.0.35'

make[1]:***[all-recursive]Error1

make[1]:Leaving directory/tmp/gd-2.0.35'

make:***[all]Error2

解決方案:vi gd_png.c

找到#include "png.h"改爲#include "/usr/local/libpng/include/png.h"

若是報錯:unrecognized option –with-zlib

那就從新安裝一次zlib,注意,須要把原先解壓出來的源碼刪掉,從新解壓進行安裝。

4.9         編譯安裝php

安裝PHP以前,須要先安裝libXpm-devel,不然在安裝php的時候會出現下面的錯誤:/usr/local/src/LAMP/php-5.5.14/ext/gd/gd.c:57:22:error:X11/xpm.h:No such file or directory

make:***[ext/gd/gd.lo]Error1

編譯安裝libXpm-devel:

[root@CentOS6 php-5.5.14]#yum –y install libXpm-devel

 [root@CentOS6 php-5.5.14]#rpm –ql libXpm-devel

/usr/bin/cxpm /usr/bin/sxpm /usr/include/X11/xpm.h /usr/lib64/libXpm.so /usr/lib64/pkgconfig/xpm.pc/usr/share/man/man1/cxpm.1.gz /usr/share/man/man1/sxpm.1.gz

查找到libXpm-devel的安裝位置爲/usr/lib64/libXpm.so,將選項--with-xpm-dir=/usr/lib64添加到php的配置選項中。

編譯安裝php

[root@centos6 LAMP]#pwd

/usr/local/src/LAMP

[root@centos6 LAMP]#tar –zxvf php-5.4.11.tar.gz

[root@centos6 LAMP]#cd./php-5.4.11

[root@localhost php-5.4.11]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2423/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-xpm-dir=/usr/lib64 --enable-soap --enable-mbstring=all --enable-sockets 

4.10     更改apache的配置文件,解析php文件

編輯配置文件/etc/httpd/httpd.conf,在LoadModule最後面添加如下內容

LoadModule php5_module     modules/libphp5.so

##一般正確編譯安裝PHP後會自動增長,若是沒有,須要手工添加。

接下來要檢查apache目錄下生成的php動態鏈接庫文件,在目錄/usr/local/apache/modules,找到是否存在libphp5.so文件。若不存在呢?則說明php安裝不正確。

[root@centos6 ~]#vim /etc/httpd/httpd.conf

在/etc/httpd/conf/httpd.conf文件中添加以下內容:

AddType application/x-compress.Z

AddType application/x-gzip .gz .tgz

Addtype application/x-httpd-php .php .phtml

Addtype application/x-httpd-php-source.phps

將下面一行:

DirectoryIndex index.html修改成

DirectoryIndex index.php index.html index.htm

配置結束後重啓Apache

[root@centos6 ~]#service httpd restart

4.11     驗證

Apache服務器的根目錄默認爲:/usr/local/apache/htdocs/,此目錄下面存放資源:

[root@centos6 ~]#vim /usr/local/apache/htdocs/index.php添加內容爲

<?php

Echo phpinfo();

?>

在客服端驗證,出現下圖說明php搭建成功

相關文章
相關標籤/搜索