转载请注明出处:http://blog.csdn.net/l1028386804/article/details/48551221
登入後複製
1、確認搭建LAMP所需的環境是否已安裝:
[root@localhost ~]#rpm -q make gcc gcc-c++ zlib-devel libtool libtool-ltdl libtool-ltdl-devel bisonncurses-devel
登入後複製
備註:安裝libpng時需要zlib-devel
安裝php時需要libtool、libtool-ltdl、libtool-ltdl-devel
表-devel
2、如果沒安裝則yum安裝:
[root@localhost~]#yum -y install make gcc gcc-c++ zlib-devel libtool libtool-ltdllibtool-ltdl-devel bison ncurses-devel
登入後複製
3、由於要使用編譯安裝,所以請查看httpd、mysql、php是否安裝:
[root@localhost ~]#rpm -q httpd mysql php
登入後複製
如果安裝則卸載:
[root@localhost ~]#rpm -e httpd --nodeps
[root@localhost ~]#rpm -e mysql --nodeps
[root@localhost ~]#rpm -e php --nodeps
登入後複製
編譯安裝過程介紹:
1)解壓 1)解壓 1)解壓 .gz為後綴的壓縮軟體包:LAMP環境搭建所需的每個軟體的軟代碼文件,都是以tar.gz或.tgz提供給我們的打包壓縮文件,所以我們必須將其解壓縮再解包。指令如下:
tar–zxvf *.tar.gz
2)在linux系統中原始碼套件安裝過程:LAMP環境搭建所需的軟體都是使用C語言開發的,所以安裝原始碼檔案最少需要設定、編譯和安裝三個步驟
設定(configure)、編譯(make)、安裝(makeinstall)
4、編譯安裝libxml2
[root@localhostlinux]# tar -zxvf libxml2-2.6.30.tar.gz
[root@localhostlinux]# cd libxml2-2.6.30
[root@localhostlibxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2
[root@localhostlibxml2-2.6.30]# make
[root@localhostlibxml2-2.6.30]# make install
登入後複製
5、編譯安裝libmcrypt
[root@localhostlinux]# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@localhostlinux]# cd libmcrypt-2.5.8
[root@localhostlibmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@localhostlibmcrypt-2.5.8]# make
[root@localhostlibmcrypt-2.5.8]# make install
登入後複製
6、安裝安裝、安裝libpng
[root@localhostlinux]# tar -zxvf zlib-1.2.3.tar.gz
[root@localhostlinux]# cd zlib-1.2.3
[root@localhostzlib-1.2.3]# CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/zlib/
(用64位元的方法进行编译)
[root@localhostzlib-1.2.3]# make
[root@localhostzlib-1.2.3]# make install
登入後複製
8、編譯安裝jpeg
[root@localhostlinux]# tar -zxvf libpng-1.2.31.tar.gz
[root@localhostlinux]# cd libpng-1.2.31
[root@localhostlibpng-1.2.31]# ./configure --prefix=/usr/local/libpng \
>--enable-shared (建立共享库使用的GNU的libtool)
[root@localhostlibpng-1.2.31]# make
[root@localhostlibpng-1.2.31]# make install
登入後複製
執行make時如果出現以下錯誤:
./libtool --mode=compile gcc-O2 -I. -c ./jcapimin.c
make: ./libt notfound
make: *** [jcapimin.lo] Error 127
解決方法:預設已安裝libtool及libtool-ltdl-devel(如需幫忙請看過程2)
[root@localhostlinux]# tar -zxvf jpegsrc.v6b.tar.gz
[root@localhostlinux]# cd jpeg-6b
[root@localhostjpeg-6b]# mkdir /usr/local/jpeg (创建jpeg软件的安装目录)
[root@localhostjpeg-6b]# mkdir /usr/local/jpeg/bin (创建存放命令的目录)
[root@localhostjpeg-6b]# mkdir /usr/local/jpeg/lib (创建jpeg库文件所在目录)
[root@localhostjpeg-6b]# mkdir /usr/local/jpeg/<strong>include</strong> (创建存放头文件目录)
[root@localhostjpeg-6b]# mkdir -p /usr/local/jpeg/man/man1 (建立存放手册的目录)
[root@localhostjpeg-6b]# ./configure --prefix=/usr/local/jpeg \
>--enable-shared \ (建立共享库使用的GUN的libtool)
>--enable-static (建立静态库使用的GUN的libtool)
[root@localhostjpeg-6b]# make
[root@localhostjpeg-6b]# make install
登入後複製
也就是把libtool裡面的兩個配置檔案拿來覆寫jpeg-6b目錄下的對應檔案
make clean 再重新configure
9、編譯安裝freetype
[root@localhostjpeg-6b]# find / -name config.sub
/usr/share/libtool/config/config.sub
[root@localhostjpeg-6b]# find / -name config.guess
/usr/share/libtool/config/config.guess
[root@localhostjpeg-6b]# cp -vRp /usr/share/libtool/config/config.sub .
[root@localhostjpeg-6b]# cp -vRp /usr/share/libtool/config/config.guess .
登入後複製
10、編譯安裝autoconf
[root@localhostlinux]# tar -zxvf freetype-2.3.5.tar.gz
[root@localhostlinux]# cd freetype-2.3.5
[root@localhostfreetype-2.3.5]# ./configure --prefix=/usr/local/freetype \
>--enable-shared (建立共享库使用的GUN的libtool)
[root@localhostfreetype-2.3.5]# make
[root@localhostfreetype-2.3.5]# make install
登入後複製
11、編譯安裝GD
[root@localhostlinux]# tar -zxvf autoconf-2.61.tar.gz
[root@localhostlinux]# cd autoconf-2.61
[root@localhostautoconf-2.61]# ./configure
[root@localhostautoconf-2.61]# make
[root@localhostautoconf-2.61]# make install
登入後複製
執行make時若出現下列錯誤:
make[2]: 7/L/gdd
make[2]: Leaving directory`/usr/src/linux/gd-2.0.35'
make[1]: *** [all-recursive]Error 1
make[1]: Leaving directory`/usr/ src/linux/gd-2.0.35'
make: *** [all] Error 2
解決方法:
[root@localhostlinux]# tar -zxvf gd-2.0.35.tar.gz
[root@localhostlinux]# cd gd-2.0.35
[root@localhostgd-2.0.35]# ./configure --prefix=/usr/local/gd \
>--with-zlib=/usr/local/zlib/ \ (指定zlib库文件的位置)
>--with-jpeg=/usr/local/jpeg/ \ (指定jpeg库文件的位置)
>--with-png=/usr/local/libpng/ \ (指定png库文件的位置)
>--with-freetype=/usr/local/freetype/ (指定freetype字体库的位置)
[root@localhostgd-2.0.35]# make
[root@localhostgd-2.0.35]# make install
登入後複製
12、編譯安裝
Apache
[root@localhostgd-2.0.35]# find / -name gd_png.c
/usr/src/linux/gd-2.0.35/gd_png.c
[root@localhostgd-2.0.35]# find / -name png.h
/usr/local/libpng/<strong>include</strong>/png.h
[root@localhostgd-2.0.35]# vi /usr/src/linux/gd-2.0.35/gd_png.c
将#<strong>include</strong> "png.h"
改为#<strong>include</strong> "/usr/local/libpng/<strong>include</strong>/png.h"
登入後複製
啟動服務時,如果出現如下錯誤:
httpd: Could not reliablydetermine the server's f falfalo doully name,ifiedusing local.localc生活localhost:80
執行chkconfig時,如果出現以下錯誤:
service httpd does not supportchkconfig
解決方法:
[root@localhostlinux]# tar -zxvf httpd-2.2.9.tar.gz
[root@localhostlinux]# cd httpd-2.2.9
[root@localhosthttpd-2.2.9]# ./configure --prefix=/usr/local/<strong>Apache</strong> \
> --enable-so \ (以动态共享<strong>对象</strong>编译)
>--enable-rewrite (基于规则的URL操控)
[root@localhosthttpd-2.2.9]# make
[root@localhosthttpd-2.2.9]# make install
将<strong>Apache</strong>加入开机启动↓
[root@localhosthttpd-2.2.9]# cp -vRp /usr/local/<strong>Apache</strong>/bin/<strong>Apache</strong>ctl /etc/init.d/httpd
[root@localhosthttpd-2.2.9]# <strong>chmod</strong> +x /etc/init.d/httpd
添加<strong>Apache</strong>服务↓
[root@localhosthttpd-2.2.9]# chkconfig --add httpd
[root@localhosthttpd-2.2.9]# chkconfig --level 2345 httpd on
[root@localhosthttpd-2.2.9]# service httpd start
登入後複製
在檔案第二行加入chkreee儲存後再執行chk版本都需要cmake編譯安裝)
編譯安裝cmake
[root@localhosthttpd-2.2.9]# vi /usr/local/<strong>Apache</strong>/conf/httpd.conf
登入後複製
編譯安裝 MySQL5.5.20[root@localhosthttpd-2.2.9]# vi /etc/rc.d/init.d/httpd
登入後複製
修改設定檔↓
#chkconfig:2345 10 90
#description:Activates/Deactivates<strong>Apache</strong> Web Server
登入後複製
初始化資料庫檔案↓
[root@localhostlinux]# tar -zxvf cmake-2.8.7.tar.gz
[root@localhostlinux]# cd cmake-2.8.7
[root@localhostcmake-2.8.7]# ./bootstrap
[root@localhostcmake-2.8.7]# gmake
[root@localhostcmake-2.8.7]# gmake install
登入後複製
權限設定↓
[root@localhostcmake-2.8.7]# groupadd mysql
[root@localhostcmake-2.8.7]# useradd -g mysql mysql
[root@localhostlinux]# tar -zxvf mysql-5.5.15.tar.gz
[root@localhostlinux]# cd mysql-5.5.15
[root@localhostmysql-5.5.15]#
cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ (安装根目录)
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ (UNIX socket文件)
>-DDEFAULT_CHARSET=utf8 \ (默认字符集)
>-DDEFAULT_COLLATION=utf8_general_ci \ (默认编码)
>-DWITH_EXTRA_CHARSETS=utf8,gbk \ (额外的编码)
>-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \(启用PERFSCHEMA引擎支持)
>-DWITH_FEDERATED_STORAGE_ENGINE=1 \ (启用FEDERATED引擎支持)
> -DWITH_PARTITI (启用PARTITION引擎支持)
>-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ (启用ARCHIVE引擎支持)
>-DWITH_READLINE=1 \(使用readline功能)
>-DMYSQL_DATADIR=/usr/local/mysql/data \ (数据库数据目录)
>-DMYSQL_TCP_PORT=3306 (TCP/IP端口)
[root@localhostmysql-5.5.15]# make
[root@localhostmysql-5.5.15]# make install
[root@localhostmysql-5.5.15]# cp -vRp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
登入後複製
將mysql加入開機啟動↓
[root@localhostmysql-5.5.15]# vi /etc/my.cnf
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
登入後複製
新增mysql服務↓
[root@localhostmysql-5.5.15]# /usr/local/mysql/scripts/mysql_install_db \
>--defaults-flie=/etc/my.cnf \
> --basedir=/usr/local/mysql/\
>--datadir=/usr/local/mysql/data \
>--pid-file=/usr/local/mysql/data/mysql.pid \
> --user=mysql
登入後複製
設定mysql↓
[root@localhostmysql]# chown -R root .
[root@localhostmysql]# chown -R mysql data
[root@localhostmysql]# chgrp -R mysql .
登入後複製
14、編譯安裝php
[root@localhostmysql]# cp -vRp support-files/mysql.server /etc/init.d/mysqld
[root@localhostmysql]# <strong>chmod</strong> +x /etc/init.d/mysqld
登入後複製
新增上:
AddType application/x-httpd-php .php
[root@localhostmysql]# chkconfig --add mysqld
[root@localhostmysql]# chkconfig --level 345 mysqld on
[root@localhostmysql]# service mysqld start
登入後複製
[root@localhostmysql]# bin/mysql
mysql> deletefrom mysql.user where Host!='localhost'; (只留允许本机登录的帐号)
mysql> flushprivileges; (刷新授权表)
mysql> setpassword for 'root'@'localhost'=password('123456'); (设置用户密码)
mysql> exit
[root@localhostmysql]# bin/mysql -h localhost -u root -p123456 (登录mysql)
登入後複製
新增內容為:
[root@localhostlinux]# tar -zxvf php-5.3.19.tar.gz
[root@localhostlinux]# cd php-5.3.19
[root@localhostphp-5.3.19]# ./configure --prefix=/usr/local/php \
>--with-apxs2=/usr/local/<strong>Apache</strong>/bin/apxs \
>--with-mysql=/usr/local/mysql/ \
>--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-mcrypt=/usr/local/libmcrypt/ \
>--with-mysqli=/usr/local/mysql/bin/mysql_config \
> --enable-soap\ (变量激活SOAP和web services支持)
>--enable-mbstring=all \ (使多字节字符串支持)
>--enable-sockets (变量激活socket通讯特性)
[root@localhostphp-5.3.19]# make
[root@localhostphp-5.3.19]# make install
[root@localhostphp-5.3.19]# cp -vRp php.ini-development /etc/php.ini
[root@localhostphp-5.3.19]# vi /usr/local/<strong>Apache</strong>/conf/httpd.conf
登入後複製
開啟瀏覽器進行存取,如果出現PHP版本介面,及安裝成功。
以上就介紹了PHP之——CentOS 65下搭建LAMP環境詳細步驟,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。