歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> LAMP環境的搭建實例

LAMP環境的搭建實例

日期:2017/3/3 16:25:27   编辑:關於Linux

apache版本:httpd-2.2.20

mysql版本:mysql-5.1.58

PHP版本:php-5.3.6

其它要用到的相關軟件:

freetype-2.4.6

jpegsrc.v6b

libpng-1.2.8-config

gd-2.0.35

PS:在安裝之前最好把httpd、mysql、php等RPM包安裝的軟件卸載掉!!

yum remove php php-devel httpd httpd-devel mysql mysql-server

一、apache安裝

1、安裝:

[root@centos5 httpd-2.2.20]# ./configure --prefix=/usr/local/apache \

> enable-so --enable-rewrite --with-pmp=worker

[root@centos5 httpd-2.2.20]# make;make install

2、驗證相關定義的功能模塊是否被正確安裝

靜態模塊查看:

[root@centos5 ~]# /usr/local/apache/bin/apachectl -l

Compiled in modules:

core.c

mod_authn_file.c

mod_authn_default.c

mod_authz_host.c

mod_authz_groupfile.c

mod_authz_user.c

mod_authz_default.c

mod_auth_basic.c

mod_include.c

mod_filter.c

mod_log_config.c

mod_env.c

mod_setenvif.c

mod_version.c

worker.c

http_core.c

mod_mime.c

mod_status.c

mod_autoindex.c

mod_asis.c

mod_cgid.c

mod_negotiation.c

mod_dir.c

mod_actions.c

mod_userdir.c

mod_alias.c

mod_rewrite.c

mod_so.c

查看動態模塊:

[root@centos5 httpd-2.2.20]# ll /usr/local/apache/modules/

總計 12

-rw-r--r-- 1 root root 9063 09-07 05:09 httpd.exp

3、驗證apache是否安裝成功:

[root@centos5 httpd-2.2.20]# /usr/local/apache/bin/apachectl -t

Syntax OK

二、mysql安裝

1、在安裝之前先創建一個用戶和組,專門用於啟動mysql。

[root@centos5 mysql-5.1.58]# groupadd mysql

[root@centos5 mysql-5.1.58]# useradd -g mysql -M -s /sbin/nologin mysql

2、創建安裝目錄和數據庫目錄

[root@centos5 mysql-5.1.58]# mkdir -p /data/mysql

[root@centos5 mysql-5.1.58]# chown mysql:mysql /data/mysql -R

3、安裝

[root@centos5 mysql-5.1.58]# ./configure --prefix=/usr/local/mysql \

--localstatedir=/data/mysql_db \

--with-extra-charsets=gbk,gb2312,utf8 \

--with-pthread --enable-thread-safe-client

PS: --enable-thread-safe-client

[root@centos5 mysql-5.1.58]# make && make install

4、編輯my.cnf配置文件,設置mysql數據存放目錄,在[mysqld]標簽外添加高亮處!!

先復制一份配置文件到安裝目錄下:

[root@centos5 mysql-5.1.58]# cd /usr/local/mysql

[root@centos5 mysql]# cp ./share/mysql/my-medium.cnf my.cnf

[root@centos5 mysql]# vi my.cnf

[mysqld]

port = 3306

socket = /tmp/mysql3306.sock

skip-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

read_buffer_size = 256K

sort_buffer_size = 64K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 128k

basedir = /data/mysql/

datadir = /data/mysql/data

5、初使化數據庫,所用工具在安裝目錄中的 /usr/local/mysql/bin/mysql_install_db

[root@centos5 mysql]# /usr/local/mysql/bin/mysql_install_db --defaults-

file=./my.cnf --user=mysql

6.修改環境變量PATH路徑,把mysql的命令路徑加入到PATH變量中

[root@centos5 mysql]# vi /etc/profile

在適當位置添加 PATH=$PATH:/usr/local/mysql/bin(注意:= 即等號兩邊不能有任何空

格)

保存後執行:source /etc/profile 讓配置立即生效!!

7、為了文便啟動mysql服務,我們把它加到系統服務當中

[root@centos5 mysql]# cp /usr/local/mysql/share/mysql/mysql.server

/etc/rc.d/init.d/mysqld

把mysql 添加到服務項,並隨開機啟動

[root@centos5 mysql]# chkconfig --add mysqld

[root@centos5 mysql]# chkconfig mysqld on

這樣我們就可以方便的用 service mysqld start 來啟動mysqld服務了!!

三、PHP安裝

在安裝PHP之前,先把一些必備的組件安裝好,要注意安裝順序!反正GD一般要最後安裝。

1、freetype安裝

[root@centos5 freetype-2.4.6]# ./configure --prefix=/usr/local/freetype

[root@centos5 freetype-2.4.6]# make;make install

2、jpeg安裝

[root@centos5 jpeg-6b]# ./configure --prefix=/usr/local/jpeg

[root@centos5 jpeg-6b]# make

[root@centos5 jpeg-6b]# make install

....

....

/usr/bin/install: cannot create regular file `/usr/local/jpeg/bin/cjpeg.1': No

such file or directory

make: *** [install] Error 1

安裝時候出現了錯誤,這個錯誤是比較明顯的,根據上面的提示可以知道,找不到jpeg/bin

這個目錄,既然沒有,我們就自己創建:

[root@centos5 jpeg-6b]# make -p /usr/local/jpeg/bin

下面我們繼續安裝:

[root@centos5 jpeg-6b]# make install

....

....

/usr/bin/install: cannot create regular file `/usr/local/jpeg/man/man1/cjpeg.1':

No such file or directory

make: *** [install] Error 1

與上面一樣:

[root@centos5 jpeg-6b]# make -p /usr/local/jpeg/man/man1

下面我們繼續安裝就OK了!!

[root@centos5 jpeg-6b]# make install

3、libpng安裝

[root@centos5 libpng-1.2.8-config]# ./configure --prefix=/usr/local/libpng

[root@centos5 libpng-1.2.8-config]# make

[root@centos5 libpng-1.2.8-config]# make install

4、GD2安裝,這個安裝相對前面幾個組件要復雜些

在安裝前做頭文件的軟鏈接

[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/

[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/png.h /usr/include/

[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/

創建指向“/usr/local/libpng/include/pngconf.h”的符號鏈接

“/usr/include/pngconf.h”

ln: 正在創建指向“/usr/local/libpng/include/pngconf.h”的符號鏈接

“/usr/include/pngconf.h”: 文件已存在

[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/png.h /usr/include/

創建指向“/usr/local/libpng/include/png.h”的符號鏈接“/usr/include/png.h”

ln: 正在創建指向“/usr/local/libpng/include/png.h”的符號鏈接

“/usr/include/png.h”: 文件已存在

可以看到,我這個以經存在了!!!這是RPM安裝時安裝的,我們要刪除掉再做鏈接!不然

make時會出錯!

[root@centos5 gd-2.0.35]# rm -rf /usr/include/pngconf.h

[root@centos5 gd-2.0.35]# rm -rf /usr/include/png.h

再做鏈接:

[root@centos5 gd-2.0.33]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/

[root@centos5 gd-2.0.33]# ln -sv /usr/local/libpng/include/png.h /usr/include/

安裝gd

[root@centos5 gd-2.0.35]# ./configure --prefix=/usr/local/gd2 \

--with-freetype=/usr/local/freetype \

--with-png=/usr/local/libpng \

--with-jpeg=/usr/local/jpeg

[root@centos5 gd-2.0.35]# make;make install

前期的工作基本上完成了。。。一切就緒,下面開始安裝PHP!

1、安裝

[root@centos5 php-5.3.6]# ./configure --prefix=/usr/local/php \

--with-gd=/usr/local/gd2 \

--with-apxs2=/usr/local/apache/bin/apxs \

--enable-mbregex --enable-bcmath \

--with-mysql=/usr/local/mysql \

--with-zlib-dir --enable-mbstring=all \

--with-pdo-mysql=/usr/local/mysql \

--with-freetype-dir=/usr/local/freetype \

--with-mysqli=/usr/local/mysql/bin/mysql_config

configure: error: GD build test failed. Please check the config.log for details.

[root@centos5 php-5.3.6]# make

[root@centos5 php-5.3.6]# make install

2、驗證安裝

在安裝完PHP之後,會在apache安裝目錄的modules目錄下生成數據庫文件libphp5.so,同時

會在apache主配置文件httpd.conf下插入:Load Module php5_module modules/libphp5.so

[root@centos5 apache]# ll /usr/local/apache/modules/

總計 20096

-rw-r--r-- 1 root root 9063 09-07 05:09 httpd.exp

-rwxr-xr-x 1 root root 20538740 09-07 12:13 libphp5.so

3、apache與PHP的整合

在apache主配置文件httpd.conf中的適當位置插入以下語句(查找AddType):

AddType application/x-httpd-php .php

[root@centos5 wordpress]# vi /usr/local/apache/conf/httpd.conf

在如下位置:

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

AddType application/x-httpd-php .php

4、驗證

啟動apache服務

[root@centos5 wordpress]# /usr/local/apache/bin/apachectl start

[root@centos5 wordpress]# vi /usr/local/apache/htdocs/index.php

輸入以下內容:

<?

phpinfo();

?>

在浏覽器地址欄中輸入服務器的IP地址或域名進行測試!!

四、LAMP實例(wordpress/disscz)

略。。。。

可以參照:http://oldboy.blog.51cto.com/2561410/587414

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Copyright © Linux教程網 All Rights Reserved