天天看點

centos 6.5 lamp環境搭建

centos 6.5 lamp環境搭建

cnetos 6.5 64

apache 2.*

mysql 5.5.30 

php 5.4.10 

說明:

文章如果在你搭建中有什麼問題,我的部落格中都有,帶着問題去搜尋吧!

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 

[[email protected]]# ./configure --prefix=/usr/local/libxml2

[[email protected]]# make

[[email protected]]# make install

5、編譯安裝libmcrypt

[root@localhostlinux]# tar -zxvf libmcrypt-2.5.8.tar.gz

[root@localhostlinux]# cd libmcrypt-2.5.8

[[email protected]]# ./configure --prefix=/usr/local/libmcrypt 

[[email protected]]# make

[[email protected]]# make install

6、編譯安裝zlib

[root@localhostlinux]# tar -zxvf zlib-1.2.3.tar.gz

[root@localhostlinux]# cd zlib-1.2.3

[[email protected]]# cflags="-o3 -fpic" ./configure --prefix=/usr/local/zlib/

(用64位元的方法進行編譯)

[[email protected]]# make

[[email protected]]# make install

7、編譯安裝libpng

[root@localhostlinux]# tar -zxvf libpng-1.2.31.tar.gz

[root@localhostlinux]# cd libpng-1.2.31

[[email protected]]# ./configure --prefix=/usr/local/libpng  --enable-shared 

(建立共享庫使用的gnu的libtool)

[[email protected]]# make

[[email protected]]# 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  (建立存放手冊的目錄)

按照這個步驟走:

預設已安裝libtool及libtool-ltdl-devel

[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

[root@localhostjpeg-6b]# ./configure --prefix=/usr/local/jpeg  --enable-shared  --enable-static     

(建立共享庫使用的gun的libtool)     

(建立靜态庫使用的gun的libtool)

[root@localhostjpeg-6b]# make

[root@localhostjpeg-6b]# make install

9、編譯安裝freetype

[root@localhostlinux]# tar -zxvf freetype-2.3.5.tar.gz

[root@localhostlinux]# cd freetype-2.3.5

[[email protected]]# ./configure --prefix=/usr/local/freetype  --enable-shared    

(建立共享庫使用的gun的libtool)

[[email protected]]# make

[[email protected]]# make install

10、編譯安裝autoconf

[root@localhostlinux]# tar -zxvf autoconf-2.61.tar.gz

[root@localhostlinux]# cd autoconf-2.61

[[email protected]]# ./configure

[[email protected]]# make

[[email protected]]# make install

[root@localhostlinux]# tar -zxvf gd-2.0.35.tar.gz

[root@localhostlinux]# cd gd-2.0.35

[[email protected]]# find / -name gd_png.c

/usr/src/linux/gd-2.0.35/gd_png.c

[[email protected]]# find / -name png.h

/usr/local/libpng/include/png.h

[[email protected]]# vi /usr/src/linux/gd-2.0.35/gd_png.c

将#include "png.h"    

改為#include "/usr/local/libpng/include/png.h"   

[[email protected]]# ./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字型庫的位置)

[[email protected]]# make

[[email protected]]# make install

12、編譯安裝apache

[root@localhostlinux]# tar -zxvf httpd-2.2.9.tar.gz

[root@localhostlinux]# cd httpd-2.2.9

[[email protected]]# ./configure --prefix=/usr/local/apache 

 --enable-so (以動态共享對象編譯)

--enable-rewrite (基于規則的url操控)

[[email protected]]# make

[[email protected]]# make install

将apache加入開機啟動↓

[[email protected]]# cp -vrp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[[email protected]]# chmod +x /etc/init.d/httpd 

[[email protected]]# vi /usr/local/apache/conf/httpd.conf

添加上:servername localhost:80

 [[email protected]]# vi /etc/rc.d/init.d/httpd

在檔案第二行加入

#chkconfig:2345 10 90

#description:activates/deactivatesapache web server

儲存後再執行chkconfig

添加apache服務↓

[[email protected]]# chkconfig --add httpd

[[email protected]]# chkconfig --level 2345 httpd on

[[email protected]]# service httpd start

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

編譯安裝 cmake

[root@localhostlinux]# tar -zxvf cmake-2.8.7.tar.gz

[root@localhostlinux]# cd cmake-2.8.7

[[email protected]]# ./bootstrap

[[email protected]]# gmake

[[email protected]]# gmake install

編譯安裝 mysql5.5.20

[[email protected]]# groupadd mysql

[[email protected]]# useradd -g mysql mysql

[root@localhostlinux]# tar -zxvf mysql-5.5.15.tar.gz

[root@localhostlinux]# cd mysql-5.5.15

[[email protected]]#

cmake -dcmake_install_prefix=/usr/local/mysql -dmysql_unix_addr=/usr/local/mysql/data/mysql.sock -ddefault_charset=utf8 -ddefault_collation=utf8_general_ci -dwith_extra_charsets=utf8,gbk -dwith_perfschema_storage_engine=1 -dwith_federated_storage_engine=1 -dwith_partition_storage_engine=1 -dwith_archive_storage_engine=1 -dwith_readline=1 -dmysql_datadir=/usr/local/mysql/data -dmysql_tcp_port=3306  

[[email protected]]# make

[[email protected]]# make install

[[email protected]]# cp -vrp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

chmod 644 /etc/my.cnf

修改配置檔案↓

在port後面添加如下

[email protected]]# vi /etc/my.cnf

【mysqld】     

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

初始化資料庫檔案↓

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/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/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)

14、編譯安裝php

1

[root@localhostlinux]# tar -zxvf php-5.3.19.tar.gz

[root@localhostlinux]# cd php-5.3.19

[[email protected]]#

如下報錯:

./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 --enable-mbstring=all --enable-sockets                

若報錯:請将 --with-gd=/usr/local/gd/  換成 --with-gd (php 5.5.25)

修改php-5.3.6/ext/gd/libgd/gd_compat.c 把png.h 改成絕對路徑(這個在編譯gd庫的時候應該就碰到了,同樣的路徑即可)

并在# include <jpeglib.h> 前面增加一行 #include <stdio.h>  

find / -name gd_compat.c 

find / -name png.h

3

find / -name gd_io.h

vim 你的gd_od.h檔案增加void (*data);     #添加這行

vim <gd_dir>/include/gd_io.h

gdioctx結構中增加void *data;

格式如下

typedef struct gdioctx

{

int (*getc) (struct gdioctx *);

int (*getbuf) (struct gdioctx *, void *, int);

void (*putc) (struct gdioctx *, int);

int (*putbuf) (struct gdioctx *, const void *, int);

/* seek must return 1 on success, 0 on failure. unlike fseek! */

int (*seek) (struct gdioctx *, const int);

long (*tell) (struct gdioctx *);

void (*gd_free) (struct gdioctx *);

void (*data);     #添加這行

}

gdioctx;

[[email protected]]# make

[[email protected]]# make install

[[email protected]]# cp -vrp php.ini-development /etc/php.ini

[[email protected]]# vi /usr/local/apache/conf/httpd.conf

添加上:

  addtype application/x-httpd-php .php

[[email protected]]# service httpd stop

[[email protected]]# service httpd start

[[email protected]]# vi /usr/local/apache/htdocs/phpinfo.php

添加内容為:

<?php

       phpinfo();

?>

祝你成功!

打開浏覽器進行通路,出現php版本界面.

請多指教!

 參考:

http://www.centoscn.com/centosserver/www/2015/0806/5966.html

不要看他的,問題很多,基本搭建不出來!