PHP之——CentOS 65下搭建LAMP環境詳細步驟

來源:互聯網
上載者:User
轉載請註明出處: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
安裝mysql時需要bison、ncurses-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)解壓tar.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、編譯安裝zlib

[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

7、編譯安裝libpng

[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

8、編譯安裝jpeg

[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/include      (建立存放標頭檔目錄)[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
執行make時如果出現如下錯誤:
./libtool --mode=compile gcc-O2 -I. -c ./jcapimin.c
make: ./libtool: Command notfound
make: *** [jcapimin.lo] Error 127
解決方案:
預設已安裝libtool及libtool-ltdl-devel(如需協助請看過程2)
[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 .
也就是把libtool裡面的兩個設定檔拿來覆蓋掉jpeg-6b目錄下的對應檔案
make clean 再重新configure

9、編譯安裝freetype

[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

10、編譯安裝autoconf

[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

11、編譯安裝GD

[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
執行make時如果出現如下錯誤:
make[2]: *** [gd_png.lo] Error 1
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@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/include/png.h[root@localhostgd-2.0.35]# vi /usr/src/linux/gd-2.0.35/gd_png.c將#include "png.h"    改為#include "/usr/local/libpng/include/png.h"

12、編譯安裝Apache

[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/Apache \> --enable-so \       (以動態共用對象編譯)>--enable-rewrite  (基於規則的URL操控)[root@localhosthttpd-2.2.9]# make[root@localhosthttpd-2.2.9]# make install將Apache加入開機啟動↓[root@localhosthttpd-2.2.9]# cp -vRp /usr/local/Apache/bin/Apachectl /etc/init.d/httpd[root@localhosthttpd-2.2.9]# chmod +x /etc/init.d/httpd 添加Apache服務↓[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
啟動服務時,如果出現如下錯誤:
httpd: Could not reliablydetermine the server's fully qualified domain name, using localhost.localdomainfor ServerName
解決方案:
[root@localhosthttpd-2.2.9]# vi /usr/local/Apache/conf/httpd.conf
添加上:ServerName localhost:80
執行chkconfig時,如果出現如下錯誤:
service httpd does not supportchkconfig

解決方案:

[root@localhosthttpd-2.2.9]# vi /etc/rc.d/init.d/httpd
在檔案第二行加入
#chkconfig:2345 10 90#description:Activates/DeactivatesApache Web Server
儲存後再執行chkconfig

13、編譯安裝mysql(最新版本都需要cmake編譯安裝)

編譯安裝 cmake
[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
編譯安裝 MySQL5.5.20
[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
修改設定檔↓
[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
初始化資料庫檔案↓
[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
使用權限設定↓
[root@localhostmysql]# chown -R root .[root@localhostmysql]# chown -R mysql data[root@localhostmysql]# chgrp -R mysql .
將mysql加入開機啟動↓
[root@localhostmysql]# cp -vRp support-files/mysql.server /etc/init.d/mysqld[root@localhostmysql]# chmod +x /etc/init.d/mysqld
添加mysql服務↓
[root@localhostmysql]# chkconfig --add mysqld[root@localhostmysql]# chkconfig --level 345 mysqld on[root@localhostmysql]# service mysqld start
配置mysql↓
[root@localhostmysql]# bin/mysqlmysql> 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)

14、編譯安裝php

[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/Apache/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/Apache/conf/httpd.conf
添加上:
AddType application/x-httpd-php .php
[root@localhostphp-5.3.19]# service httpd stop[root@localhostphp-5.3.19]# service httpd start
[root@localhostphp-5.3.19]# vi /usr/local/Apache/htdocs/phpinfo.php
新增內容為:
開啟瀏覽器進行訪問,如果出現PHP版本介面,及安裝成功。

以上就介紹了PHP之——CentOS 65下搭建LAMP環境詳細步驟,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.