---恢復內容開始---php
- 1、系統環境
- 系統平臺:CentOS 6.5 (Final)
- Apache版本:httpd-2.2.31.tar.gz(最新版本2015-07-16)
- Mysql 版本:mysql-5.0.41.tar.gz
- Php版本:php-5.2.6.tar.gz
- 2、安裝前準備
- 一、庫文件準備
- 在安裝PHP以前,應先安裝PHP5須要的最新版本庫文件,例如libxml二、libmcrypt以及GD2庫等文件。安裝GD2庫是爲了讓PHP5支 持GIF、PNG和JPEG圖片格式,因此在安裝GD2庫以前還要先安裝最新的zlib、libpng、freetype和jpegsrc等庫文件。並且中間還會穿插安裝一些軟件,讀者能夠按照本節提供的順序安裝。
- autoconf-2.61.tar.gz
- freetype-2.3.5.tar.gz
- gd-2.0.35.tar.gz
- jpegsrc.v6b.tar.gz
- libmcrypt-2.5.8.tar.gz
- libpng-1.5.27.tar
- libxml2-2.6.30.tar.gz
- zlib-1.2.8.tar.gz
- ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
- phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
- 二、安裝gcc、gcc-c++編譯器
- 用gcc -v 命令檢查安裝時使用的編譯工做是否存在
- 如系統未安裝,在系統聯網的狀況下使用yum install gcc和yum install gcc-c++安裝
![](http://static.javashuo.com/static/loading.gif)
- 三、卸載默認的低版本環境
- 目前發行的Linux操做系統版本中,若是選擇默認所有安裝,就已經安裝了LAMP環境,可是版本相對都比較低。咱們能夠再安裝一個LAMP環境和原來的並存,可是這樣作沒有必要,由於同時只能開啓一個LAMP環境。所要咱們要在安裝以前,先應檢查一下系統中是否已經安裝了低版本的環境,若是已經安裝過了,中止原來的服務運行,或者把原來的環境卸載掉。
- a. 卸載Apache
# rpm -qa | grep httpdnode
說明:檢查是否安裝了httpd軟件包mysql
![](http://static.javashuo.com/static/loading.gif)
若是有,就使用 rpm -e httpd-2.2.3-63.el5.centos --nodepslinux
說明:卸載軟件包, --nodeps 若是有連帶關係,也強制卸載c++
# cd /etc/httpd/sql
# rm -rf *數據庫
說明:到原來的apache安裝目錄下,將其全部的安裝目錄和文件都刪掉apache
b. 卸載Mysqlbootstrap
# rpm -qa | grep mysqlcentos
# rpm -e mysql-5.0.77-4.el5_4.2 --nodeps
說明:卸載mysql
![](http://static.javashuo.com/static/loading.gif)
c. 卸載Php
# rpm -qa | grep php
# rpm -e php-common-5.1.6-27.el5 --nodeps
# rpm -e php-ldap-5.1.6-27.el5 --nodeps
# rpm -e php-cli-5.1.6-27.el5 --nodeps
# rpm -e php-5.1.6-27.el5 --nodeps
說明:卸載PHP
![](http://static.javashuo.com/static/loading.gif)
四、清空防火牆規則
![](http://static.javashuo.com/static/loading.gif)
四、關閉selinux
vi /etc/selinux/config
![](http://static.javashuo.com/static/loading.gif)
3、安裝LAMP
一、安裝zlib
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
![](http://static.javashuo.com/static/loading.gif)
make && make install
![](http://static.javashuo.com/static/loading.gif)
zlib指定安裝目錄可能形成libpng安裝失敗,故不指定,爲卸載方便,建議make install執行結果輸出到安裝日誌文件,便於往後卸載。
二、安裝libxml2
tar zxvf libxm2-2.6.32.tar.gz
cd libxml2-2.6.32
./configure --prefix=/usr/local/libxml2
make && make install
![](http://static.javashuo.com/static/loading.gif)
三、安裝libmcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcryp
make && make install
![](http://static.javashuo.com/static/loading.gif)
4.安裝libpng
tar zxvf libpng-1.5.27.tar
cd libpng-1.5.27.tar
./configure --prefix=/usr/local/libpng
make && make install
五、安裝jpeg庫
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make && make install
--enable-shared 與--enable-static參數分別爲創建共享庫和靜態庫使用的libtool
六、安裝freetype 字體
tar zxvf freetype-2.6.1.tar
cd freetype-2.6.1
./configure --prefix=/usr/local/freetype
make && make install
七、安裝autoconf
tar zxvf autoconf-2.69.tar
cd autoconf-2.69
./configure && make && make install
報錯提示缺乏perl,使用yum -y install perl
而後在進行編譯安裝(下面是成功以後的)
![](http://static.javashuo.com/static/loading.gif)
八、安裝GD庫
tar zxvf
libgd-2.1.1.tar.gz
cd ibgd-2.1.1
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpep6/ --with-freetype=/usr/local/freetype --with-png=/usr/local/libpng
make && make install
九、安裝cmake(mysql從5.5開始編譯要用cmkae編譯,因此要安裝cmake)
tar zxvf cmake-2.8.12.2.tar
cd cmake-2.8.12.2
./bootstrap
![](http://static.javashuo.com/static/loading.gif)
gmake
gmake install
十、安裝Apache
./configure --prefix=/usr/local/apache2 \
--sysconfdir=/usr/local/apache2/etc/ \
--with-included-apr \
--enable-dav \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared
make && make install
測試apache2是否安裝成功
/usr/local/bin/apachetcl start 啓動apache2
![](http://static.javashuo.com/static/loading.gif)
若是不想看見底下那一行,進入/etc/httpd.conf文件
![](http://static.javashuo.com/static/loading.gif)
查看80端口是否開啓
# netstat -tnl|grep 80
![](http://static.javashuo.com/static/loading.gif)
訪問Apache服務器
![](http://static.javashuo.com/static/loading.gif)
添加自啓動
# echo "/usr/local/apache2/bin/apachectl start &>/dev/null" >> /etc/rc.d/rc.local
11、安裝Mysql
1.安裝ncur
yum -y install ncur* bison
二、添加mysql用戶並加到mysql組中
useradd -r -s /sbin/nologin mysql
mkdir -pv /usr/local/mysql/data
3.下載mysql並進行編譯安裝
tar zxvf mysql-5.6.32.tar.gz
cd mysql-5.7.14
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/usr/local/mysql/etc/my.cnf \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=1 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
make && make install
rm -rf /etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chown -R mysql.mysql /usr/local/mysql/
##初始化數據庫
chmod +x scripts/mysql_install_db
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
ln -s /usr/local/mysql/bin/* /usr/bin/
ln -s /usr/local/mysql/lib/* /usr/lib/
ln -s /usr/local/mysql/man/man1/* /usr/share/man/man1
ln -s /usr/local/mysql/man/man8/* /usr/share/man/man8
ln -s /usr/local/mysql/libexec/* /usr/local/libexec
四、啓動mysql服務並加入開機自啓動
service mysqld start
chkconfig mysqld on
五、驗證mysql服務是否啓動
netstat -tulnp | grep 3306
mysql
12、安裝PHP
1.安裝libtool以及libtool-ltdl*
wget
tar zxvf
cd
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/lib/mysql --enable-fpm --with-mcrypt --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir
make && make install