LAMP源碼安裝

系統CentOS5.5,LAMP架設全部用源碼包
源碼包存放位置:/home/lamp
軟件:

libxml2-2.6.30.tar.gz:ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.30.tar.gz

libmcrypt-2.5.8.tar.gz:

http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download

zlib-1.2.5.tar.gz:

http://zlib.net/zlib-1.2.5.tar.gz

(需要***才能下載)


libpng-1.2.44.tar.gz:

ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.2.tar.gz

jpegsrc.v8b.tar.gz:

http://ijg.org/files/jpegsrc.v8c.tar.gz

freetype-2.4.3.tar.gz:

http://mirror.yongbok.net/nongnu/freetype/freetype-2.4.4.tar.gz

autoconf-2.68.tar.gz:

ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz

gd-2.0.35.tar.gz



httpd-2.2.17.tar.gz:

http://labs.renren.com/apache-mirror//httpd/httpd-2.2.17.tar.gz

mysql-5.1.52.tar.gz:

http://mysql.easynet.be/Downloads/MySQL-5.5/mysql-5.5.11.tar.gz

php-5.2.14.tar.gz:http://cn.php.net/get/php-5.2.17.tar.gz/from/this/mirror

ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz:

http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

phpMyAdmin-3.3.8-all-languages.tar.gz:



安裝:


1)


#tar zxvf libxml2-2.6.30.tar.gz


#cd libxml2-2.6.30


#

./configure --prefix=/usr/local/libxml2

    //--prefix=/usr/local/libxml2:在安裝時軟件安裝到/usr/local/libxml2


#make


#make install


2)


#cd ..


#tar zxvf libmcrypt-2.5.8.tar.gz


# cd libmcrypt-2.5.8


#

./configure --prefix=/usr/local/libmcrypt

#make


#make install


不同版本linux有可能還要安裝libltdl庫


#cd /home/lamp/libmcrypt-2.5.8/libltdl


#

./configure --enable-ltdl-install 

  //--enable-ltdl-install:配置ltdl庫的安裝


#make


#make install


3)


#cd ..


#cd ..


#tar zxvf zlib-1.2.5.tar.gz


#cd zlib-1.2.5


#

./configure --prefix=/usr/local/zlib

#make


#make install


4)


#cd ..


#tar zxvf libpng-1.2.44.tar.gz


#cd libpng-1.2.44


#

./configure --prefix=/usr/local/libpng

#make


#make install


5)


#mkdir /usr/local/jpeg8


#mkdir /usr/local/jpeg8/bin


#mkdir /usr/local/jpeg8/lib


#mkdir /usr/local/jpeg8/include


#mkdir -p /usr/local/jpeg8/man/man1


#cd ..


#tar zxvf jpegsrc.v8b.tar.gz


# cd jpeg-8b/


#

./configure --prefix=/usr/local/jpeg8/ --enable-shared --enable-static

     //--enable-shared:建立共享庫使用的GNU的libtool;--enable-static:建立靜態庫使用的GNU的libtool


#make


#make install


6)


#cd ..


#tar zxvf freetype-2.4.3.tar.gz


#cd freetype-2.4.3


#

./configure --prefix=/usr/local/freetype

#make


#make install


7)


#cd ..


#tar zxvf autoconf-2.68.tar.gz


#cd autoconf-2.68


#

./configure

#make


#make install


8)


#cd ..


#tar zxvf gd-2.0.35.tar.gz


#cd gd-2.0.35


#

./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg8/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ 

       //--with-zlib=/usr/local/zlib/:指定zlib庫文件的位置;//--with-jpeg=/usr/local /jpeg8/ :指定jpeg庫文件的位置;--with-png=/usr/local/libpng/:指定png庫文件的位置;--with-freetype= /usr/local/freetype/:指定freetype 2.x字體庫的位置


#make


#make install



9)


#cd ..


#tar zxvf httpd-2.2.17.tar.gz


#cd httpd-2.2.17


#

./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support 

    //--sysconfdir=/etc/httpd:指定Apache服務器的配置文件存放位置;--with-z=/usr/local/zlib /:指定zlib庫文件的位置;--with-included-apr使用捆綁APR/APR-Util的副本;--disable-userdir: 請求的映像到用戶特定目錄;--enable-so:以動態共享對象(DSO,*.so的文件,可以使用動態加載模塊功能)編譯;--enable- deflate=shared縮小傳輸編碼的支持;--enable-expires=shared:期滿頭控制;--enable- rewrite=shared:基於規則的URL操控(Apache服務器具有rewrite功能:修改網頁的url路徑);--enable- static-support:建立一個靜態鏈接版本的支持


#make


#make install


#/usr/local/apache2/bin/apachectl start          //啓動apache

若出現:

httpd: apr_sockaddr_info_get() failed for server

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

 

這個錯誤:修改/etc/hosts

127.0.0.1               localhost.localdomain localhost server(添加server,server是主機名)

設置apache服務開機自啓動

#cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
#vim /etc/rc.d/init.d/httpd
在第一行#!/bin/sh下增加兩行文字如下(不加這兩行就無法使用chkconfig --add命令)
# chkconfig: 35 70 30
# description: Apache

#chkconfig --add httpd
#service httpd start      //啓動apache服務
#chkconfig --level 3 httpd on
#chkconfig --level 5 httpd on

/etc/httpd/httpd.conf         //apache主配置文件


#/usr/local/apache2/bin/apachectl configtest        //檢查配置文件中的錯誤


Syntax OK                              //表示沒有錯誤


#/usr/local/apache2/bin/apachectl -t                    //檢查配置文件中的錯誤


Syntax OK                              //表示沒有錯誤


#/usr/local/apache2/bin/apachectl -l                  //查看已經編譯到Apache服務器中的模塊



10)


#groupadd mysql


#useradd -g mysql mysql


#cd ..


#tar zxvf mysql-5.1.52.tar.gz


#cd mysql-5.1.52


#

./configure --prefix=/usr/local/mysql --with-extra-charsets=all

    // --with-extra-charsets=all:安裝mysql時安裝所有的字符集


#make


#make install


#cp support-files/my-medium.cnf /etc/my.cnf


#cd /usr/local/mysql/


#bin/mysql_install_db --user=mysql     //創建授權表


#chown -R root .                //將安裝目錄以及以下的文件和目錄的所屬用戶改爲root


#chown -R mysql var/        //將安裝目錄下的var目錄的所屬用戶改爲mysql


#chgrp -R mysql .              //將安裝目錄以及以下的文件和目錄的所屬組改爲mysql


#/usr/local/mysql/bin/mysqld_safe --user=mysql&         //啓動mysql服務


#bin/mysql -u root           //啓動mysql客戶端控制檯


若無法啓動提示:


bin/mysql: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

解決方法:#cp /usr/local/mysql/lib/mysql/

libmysqlclient.so.16

/usr/lib/      即可


#bin/mysqladmin version       //查看MySQL版本


#bin/mysqladmin variables         //查看所有mysql參數


如果有匿名賬戶存在,它擁有全部的權限,一次刪掉它可以提高安全:


>DELETE FROM mysql.user WHERE Host='localhost' AND User='';
>FLUSH PRIVILEGES;

>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); 

     //設置修改密碼


#bin/mysqladmin -u root -p shutdown         //關閉mysql數據庫


設置mysql開機啓動


#cp /home/lamp/mysql-5.1.52/support-files/mysql.server /etc/rc.d/init.d/mysqld
#chown root.root /etc/rc.d/init.d/mysqld
#chmod 755 /etc/rc.d/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --level 3 mysqld on
#chkconfig --level 5 mysqld on

#service mysqld restart           //重啓mysql服務器

10)mysql-5.5.11編譯安裝

下載:cmake-2.8.4.tar.gz:http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

#tar zxvf cmake-2.8.4.tar.gz

#./bootstrap

#gmake

#make install

編譯安裝mysql-5.5.11

#tar zxvf mysql-5.5.11

#groupadd mysql

#useradd -g mysql mysql

#mkdir -p /data/mysql           //存放數據庫

#chown -R mysql.mysql /data

#mkdir /usr/local/mysql       //mysql安裝位置

#chmod +x /usr/local/mysql

#chown mysql.mysql /usr/local/mysql

#cd mysql-5.5.11

#

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -

 

DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -

 

DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -

 

DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -

 

DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql

 

#cp support-files/my-medium.cnf /etc/my.cnf

 

#

cp support-files/mysql.server /etc/rc.d/init.d/mysqld

#vim /etc/rc.d/init.d/mysqld

添加:

basedir=/usr/local/mysql

datadir=/data/mysql

#chkconfig --add mysqld

 

11)

#cd ..


#tar zxvf php-5.2.14.tar.gz


#cd php-5.2.14


#

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2/ --with-png-dir=/usr/local/libpng/ --with-jpeg-dir=/usr/local/jpeg8/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-zlib-dir=/usr/local/zlib/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets

            //--with-config-file-path=/usr/local/php/etc:php5配置文件存入路徑;--with-apxs2= /usr/local/apache2/bin/apxs:告訴php查找Apaache2的地方;--with-mysql=/usr/local /mysql:指定mysql安裝目錄;--with-libxml-dir=/usr/local/libxml2/:告訴php放置libxml2庫 的地方;--with-png-dir=/usr/local/libpng/:告訴php放置libpng庫的地方;--with-jpeg-dir= /usr/local/jpeg8/:告訴php放置jpeg庫的地方;--with-freetype-dir=/usr/local /freetype/:告訴php放置freetype庫的地方;--with-gd=/usr/local/gd2/:告訴php放置gd庫的地 方;--with-zlib-dir=/usr/local/zlib/:告訴php放置zlib庫的地方;--with-mcrypt=/usr /local/libmcrypt/:告訴php放置libmcrypt庫的地方;--with-mysqli=/usr/local/mysql /bin/mysql_config:變量激活新增加的mysqli功能;--enable-soap:變量激活SOAP和Web services支持;--enable-mbstring=all:使多字節字符串支持;--enable-sockets:變量激活socket通信 特性


#make


#make install


#cp php.ini-dist /usr/local/php/etc/php.ini


#vim /etc/httpd/httpd.conf


把所有

/usr/local/apache2/htdocs

都改爲

/var/www/

     //修改WEB文檔根目錄


AddType application/........


AddType application/........


AddType application/x-httpd-php .php .phtml

       //可以將任何後綴的文件解析爲PHP


AddType application/x-httpd-source .phps

           //爲了將作爲.phps作爲PHP的源文件進行語法高亮顯示


#service httpd restart


#vim /var/www/html/test.php


<?php
phpinfo();
?>

測試是否test.php是否可運行:http://IP/test.php


12)


#cd ..


#tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz


#cd ZendOptimizer-3.3.9-linux-glibc23-i386


#mkdir /usr/local/zend


#cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/


#vim /usr/local/php/etc/php.ini


在結尾增加:


zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend/ZendOptimizer.so

#service httpd restart


然後測試:http://IP/test.php



13)
#cd ..
#tar zxvf

phpMyAdmin-3.3.8-all-languages.tar.gz


#cp -a phpMyAdmin-3.3.8-all-languages /var/www/phpmyadmin


#cp /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php


#vim /var/www/phpmyadmin/config.inc.php


1、$cfg['Servers'][$i]['auth_type'] = '

http'

;          //原先的改爲http:HTTP身份驗證模式


改用http,登錄phpmyadmin會提示如下



2、$cfg['Servers'][$i]['auth_type'] = 'cookie';          //原先的改爲cookie:cookie身份驗證模式


$cfg['blowfish_secret']="xxxxxx";                   //這裏需要一個任意的字符串


3、$cfg['Servers'][$i]['auth_type'] = 'config';          //原先的改爲config:config身份驗證模式


$cfg['Servers'][$i]['user']='root';                              //使用你MySQL數據庫的用戶名


$cfg['Servers'][$i]['password']='123456';                //使用你MySQL數據庫的密碼



再此處選擇HTTP身份驗證模式


登錄phpmyadmin:http://IP/phpmyadmin/index.php


輸入用戶名,密碼


若登錄後提示錯誤:


#vim /var/www/phpmyadmin/libraries/

config.default.php
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';                                         

//新增phpmyadmin


$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';  

                       //新增pma_bookmark


$cfg['Servers'][$i]['relation'] = 'pma_relation';   

                                     //新增pma_relation


$cfg['Servers'][$i]['table_info'] = 'pma_table_info';    

                             //新增pma_table_info


$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';  

                    //新增pma_table_coords


$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';    

                         //新增pma_pdf_pages


$cfg['Servers'][$i]['column_info'] = 'pma_column_info';   

                      //新增pma_column_info


$cfg['Servers'][$i]['history'] = 'pma_history'; 

                                         //新增pma_history


$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';

          //新增pma_designer_coords


$cfg['Servers'][$i]['tracking'] = 'pma_tracking'; 

                                     //新增pma_tracking


#

/usr/local/mysql/bin/mysql -h localhost -u root -p < /var/www/phpmyadmin/scripts/create_tables.sql

             //導入表後會生成一個phpmyadmin數據庫


然後重啓瀏覽器,若登錄後還是不行,刪除瀏覽器歷史記錄在重啓瀏覽器

 

Apache設置

1)httpd.conf中的全局配置

設置項                                            說明

ServerRoot                                       設置Apache服務器的根(Root)目錄

ServerAdmin                                    設置Apache服務器管理員的E-mail地址

ServerName                                     設置Apache服務器的主機名(服務器監聽的域名,後可跟域名或IP)

DocumentRoot                                 設置Apache服務器網頁(文檔)根目錄(默認主頁的目錄)

Listen                                              設置Apache服務器監聽的網絡端口號

PidFile                                             設置保存httpd服務器程序進程號(PID)的文件

ErrorLog                                          設置Apache服務器中錯誤日誌文件的路徑和文件名

CustomLog                                      設置Apache服務器中訪問日誌文件的路徑和文件名

KeepAlive                                       設置爲Off時服務器不使用保持連接功能,傳輸的效率比較低;設置爲On時,可以提高服務器傳輸文件的效率,建議設置保持連接功能有效

MaxKeepAliveRequests                 當KeepAlive爲On時,設置客戶端每次連接允許請求響應的最大文件數,默認設置爲100個文件

httpd.conf的區域設置

KeepAliveTimeout                          設置Web服務器與瀏覽器之間網絡連接的超時秒數

2)除全局設置外,httpd.conf文件中的大多數設置都包括在“區域”中的

<Directory />

    options FollowSymlinks

    AllowOverride None

</ Directory>

3)httpd.conf文件配置

在httpd.conf文件中需要進行UserDir設置

<IfModule mod_userdir.c>

UserDir public_html          //原來的UserDir disable註釋掉

</IfModule>

用戶目錄設置

以user用戶登錄,然後進行下列操作

用戶user宿主目錄需要設置爲其他用戶可以進入

$chown o+rwx /home/user

用戶宿主目錄中需要建立public_html目錄

$mkdir public_html

public_html目錄中需要建立index.html文件

訪問用戶個人主頁

http://192.168.1.1/~user

4)DirectoryIndex index.html index.html.var index.php         訪問網站主頁自動找的文件

5)httpd.conf文件添加虛擬主機

NameVirtualHost 192.168.1.2

<VirtualHost 192.168.1.2:80 >

    ServerName www.test.com          //虛擬主機的域名

    DocumentRoot /home/test.com        //虛擬主機的網頁(文檔)的存放目錄

</ VirtualHost>

6)Apache的兩類日誌文件

httpd.conf中對日誌文件的設置      //到ServerRoot 下的目錄下找文件

ErrorLog log/error_log

CustomLog log/access_log common

訪問日誌文件

用於記錄對Apache服務器的訪問事件

/usr/local/apache2/logs/access_log

錯誤日誌文件

用於記錄Apache服務器中的錯誤事件

/usr/local/apache2/logs/error_log

7)爲防止太多人訪問服務器,而使客戶端無法訪問服務器修改的設置之一

<IfModule prefork.c>

StartServers                        8          //啓動服務的數量爲8(不能當服務就是8個進程)

MinSpaceServers                5          //最少5個空閒的進程

MaxSpaceServers               20         //最多20個空閒的進程

ServerLimit                          256       //開啓進程最多256個

MaxClients                           256       //最多響應客戶端256的請求

MaxRequestsPerChild         4000      //每個客戶多打開頁面的子進程最多不能超過4000

<IfModule>

8)設置Apache服務器網頁(文檔)根目錄(默認主頁的目錄)

DocumentRoot /var/www/html

<Directory "/var/www/html">        //默認主頁的設置

Option Indexes FollowSymlinks             //Indexes:尋找索引文件,FollowSymlinks:尋找跟着的鏈接

..........

allow from all                           //允許所有客戶端訪問

..........

</ Directory>

 

9)做虛擬主機(功能是:同一個IP,能用兩個不同的域名{www.ex.com,www.ex1.com}訪問不同的網站)

1)首先要做DNS服務器,使www.ex.com,www.ex1.com解析出來的結果都是同一個IP

2)#vim /etc/httpd/httpd.conf

新增如下:

NameVirtualHost 192.168.2.101:80

<VirtualHost 192.168.2.101:80>

    ServerAdmin [email protected]          //該段可不要

    DocumentRoot /var/www/html/ex.com

    ServerName www.ex.com

    ErrorLog logs/dummy-host.ex.com-error_log

    CustomLog logs/dummy-host.ex.com-access_log common

</VirtualHost>

<VirtualHost 192.168.2.101:80>

    ServerAdmin [email protected]          //該段可不要

    DocumentRoot /var/www/html/ex1.com

    ServerName www.ex1.com

    ErrorLog logs/dummy-host.ex1.com-error_log

    CustomLog logs/dummy-host.ex1.com-access_log common

</VirtualHost>

#mkdir -p /var/www/html/ex.com          //分別在兩個目錄(ex.com,ex1.com)下建立index.html文件,內容分別爲ex,ex1;爲了測試

 #mkdir -p /var/www/html/ex1.com

 #service httpd restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章