DedeCMS部署--怎樣去部署Apache+Mysql+PHP(LAMP)?

 聲明:部署DedeCMS,在網上搜了很多資料,包括這個論壇,幾乎沒有發現在linux下部署的現成資料可以參考。

             遂,自己把整個部署過程中一些重要的點記錄下來,一是算做自己的勞動成果,同時,期望對曾經和我一樣迷茫,不知如何部署                的XDJM們一個參考。謝謝

DedeCMS部署--怎樣去部署Apache+Mysql+PHP(LAMP)

1. Linux OS

Linux OSRed Hat Enterprise Linux AS release 4 (Nahant Update 6)


2.Deploy Apache

2.1  下載Apache

下載Apache2 source from http://httpd.apache.org/  ,直接下載在/root下,解壓tarphp-5.2.13

2.2  編譯 apache

cd httpd-2.2.15,進行編譯,生成Makefile

./configure --prefix=/usr/local/apache /  --指定apache安裝目錄

               --enable-so                    /

                 --enable-cgi                   /

                 --enable-info                 /

                 --enable-rewrite          /

                 --enable-speling           /

                 --enable-usertrack      /

                 --enable-deflate /

                 --enable-ssl                   /

--enable-mime-magic

2.3  make & make install

Make過程中可能會有一些問題,具體可以參考第5節。

Apache部署參考:http://dan.drydog.com/apache2php.html

3. Deploy Mysql

3.1下載mysql

下載mysql source from http://dev.mysql.com/ ,在Downloads頁面選擇 MySQL Community Server 進入下載頁面。選擇 Red Hat Enterprise Linux。因爲我的OSREHL4.6 ,且爲64位,則下載三個包:

MySQL-server-community-5.1.47-1.rhel4.x86_64.rpm MySQL-devel-community-5.1.47-1.rhel4.x86_64.rpm –必須,否則apache編譯的時候會出錯MySQL-client-community-5.1.47-1.rhel4.x86_64.rpm

3.2 安裝mysql server

rpm –ivh MySQL-server-community-5.1.47-1.rhel4.x86_64.rpm

server安裝完畢後,測試是否成功可運行netstatMysql端口是否打開,如打開表示服務已經啓動,安裝成功。

Mysql默認的端口是3306。命令如下: netstat –nap |grep 3306

3.3 安裝mysql client

rpm –ivh MySQL-client-community-5.1.47-1.rhel4.x86_64.rpm

3.4 安裝 mysql devel

rpm –ivh MySQL-devel-community-5.1.47-1.rhel4.x86_64.rpm

3.5 登錄Mysql

    [root@test1 local]# mysql

   Welcome to the MySQL monitor. Commands end with ; or /g.

   Your MySQL connection id is 1 to server version: 4.0.16-standard

   Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

   mysql>

   出現了“mysql>”提示符,恭喜你,安裝成功!

   增加了密碼後的登錄格式如下:

   mysql -u root -p

   Enter password: (輸入密碼)

   其中-u後跟的是用戶名,-p要求輸入密碼,回車後在輸入密碼處輸入密碼。

   注意:這個mysql文件在/usr/bin目錄下,與後面講的啓動文件/etc/init.d/mysql不是一個文件。

3.6 修改mysql 密碼

 MySQL默認沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。

   1、命令

   usr/bin/mysqladmin -u root password 'new-password'

   格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼

   2、例子

   例1:給root加個密碼123456

   鍵入以下命令 :

   [root@test1 local]# /usr/bin/mysqladmin -u root password 123456

  注:因爲開始時root沒有密碼,所以-p舊密碼一項就可以省略了。

   3、測試是否修改成功

   1)不用密碼登錄

   [root@test1 local]# mysql

   ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

   顯示錯誤,說明密碼已經修改。

   2)用修改後的密碼登錄

   [root@test1 local]# mysql -u root -p

   Enter password: (輸入修改後的密碼123456)

   Welcome to the MySQL monitor. Commands end with ; or /g.

   Your MySQL connection id is 4 to server version: 4.0.16-standard

   Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

   mysql>

   成功!

   這是通過mysqladmin命令修改口令,也可通過修改庫來更改口令。

3.7 啓動和停止

1、啓動

   MySQL安裝完成後啓動文件mysql/etc/init.d目錄下,在需要啓動時運行下面命令即可。

   [root@test1 init.d]# /etc/init.d/mysql start

   2、停止

   /usr/bin/mysqladmin -u root -p shutdown

   3、自動啓動

   1)察看mysql是否在自動啓動列表中

   [root@test1 local]# /sbin/chkconfig --list

   2)把MySQL添加到你係統的啓動服務組裏面去

   [root@test1 local]# /sbin/chkconfig –- add mysql

   3)把MySQL從啓動服務組裏面刪除。

   [root@test1 local]# /sbin/chkconfig –-del mysql

Mysql部署 參考:http://www.linuxidc.com/Linux/2007-12/9962p3.htm

3.8 使用mysql

(對於我們LAMP環境部署來說,可選擇性的使用本節)

MySQL默認的數據文件存儲目錄爲/var/lib/mysql。假如要把目錄移到/home/data下需要進行下面幾步:

   1home目錄下建立data目錄

   cd /home

   mkdir data

   2、把MySQL服務進程停掉

   mysqladmin -u root -p shutdown

 

   3、把/var/lib/mysql整個目錄移到/home/data

   mv /var/lib/mysql /home/data/

   這樣就把MySQL的數據文件移動到了/home/data/mysql

   4、找到my.cnf配置文件

  如果/etc/目錄下沒有my.cnf配置文件,請到/usr/share/mysql/下找到*.cnf文件,拷貝其中一個到/etc/並改名爲my.cnf)中。命令如下:

   [root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

   5、編輯MySQL的配置文件/etc/my.cnf

  爲保證MySQL能夠正常工作,需要指明mysql.sock文件的產生位置。修改socket=/var/lib/mysql/mysql.sock一行中等號右邊的值爲:/home/mysql/mysql.sock 。操作如下:

   vi  my.cnf    (vi工具編輯my.cnf文件,找到下列數據修改之)

   # The MySQL server

    [mysqld]

    port   = 3306

    #socket  = /var/lib/mysql/mysql.sock(原內容,爲了更穩妥用“#”註釋此行)

    socket  = /home/data/mysql/mysql.sock   (加上此行)

   6、修改MySQL啓動腳本/etc/rc.d/init.d/mysql

  最後,需要修改MySQL啓動腳本/etc/rc.d/init.d/mysql,把其中datadir=/var/lib/mysql一行中,等號右邊的路徑改成你現在的實際存放路徑:home/data/mysql

   [root@test1 etc]# vi /etc/rc.d/init.d/mysql

   #datadir=/var/lib/mysql    (註釋此行)

   datadir=/home/data/mysql   (加上此行)

   7、重新啓動MySQL服務

   /etc/rc.d/init.d/mysql start

   或用reboot命令重啓Linux

   如果工作正常移動就成功了,否則對照前面的7步再檢查一下。

 

4. Deploy PHP

PHP的部署是整個部署最困難的一個環節,這個環節也是讓我耗時,在網絡上查找答案最長的部分。

4.1 下載PHP

下載 PHP source from http://www.php.net/

注意:dedecms 5.6以上版本對php5.3支持有瑕疵!如果用php5.3版本,在安裝cms安裝成功後,系統後臺頁面會提示“針對於安裝完成後出現安裝完出現Deprecated: Function ereg_replace() is deprecated ....”。

解決有兩種方法,見第5節。

4.2 編譯PHP

cd php-5.2.13,進行編譯,生成Makefile。注意:這個地方的配置項需要根據自己的需要選擇。

./configure /

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

     --with-mysql /

     --prefix=/usr/local/apache/php /

     --with-config-file-path=/usr/local/apache/php /

     --enable-force-cgi-redirect /

     --disable-cgi /

     --with-zlib /

     --with-gettext /

     --with-gdbm  /

  --with-gd

4.3 make & make install

4.4 cp -p .libs/libphp5.so /usr/local/apache/modules

4.5 cp php.ini

命令如下:  cp -p php.ini-recommended /usr/local/apache/php/php.ini

4.6 修改httpd.conf

修改 /usr/local/apache/conf/httpd.conf,加入以下內容:

1

# Example:

# LoadModule foo_module modules/mod_foo.so

#

LoadModule php5_module        modules/libphp5.so

AddHandler php5-script php

2

# DirectoryIndex: sets the file that Apache will serve if a directory

# is requested.

<IfModule dir_module>

    #DirectoryIndex index.html

     DirectoryIndex index.php index.html index.shtml index.cgi

</IfModule>

 

3.

    # If the AddEncoding directives above are commented-out, then you

    # probably should define those extensions to indicate media types:

    #

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

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

AddType application/x-httpd-php-source .phps

4.7 修改完成後重新啓動apache

PHP安裝參考:http://dan.drydog.com/apache2php.html

 

5.遇到的問題以及解決辦法

5.1 error: libpng.(a|so) not found.

現象描述:

編譯apache的時候提示:

checking for floorf... yes

If configure fails try --with-jpeg-dir=<DIR>

configure: error: libpng.(a|so) not found.

解決辦法:

通過上面的搜索其實就知道一些原因了,configure一般的搜索編譯路徑爲/usr/lib/,因爲php默認就在/usr/lib/下找相關庫文件,x64機器上是在:/usr/lib64.這時你就可以直接把需要的庫文件從/usr/lib64中拷貝到/usr/lib/中去就可以了.

那麼記得要在configure前執行如下的命令:

cp -frp /usr/lib64/libjpeg.* /usr/lib/

 

5.2  error: Cannot find MySQL header files under yes

現象描述:

編譯apache的時候提示:

checking for specified location of the MySQL UNIX socket... no

configure: error: Cannot find MySQL header files under yes.

Note that the MySQL client library is not bundled anymore!

解決辦法:

這個是缺少了 mysql-devel 安裝包,rpm –ivh 安裝devel包,前面提到過。

5.3 mysql-server,mysql-develmysql-client的異同

英文原版:

In most cases, you only need to install the MySQL-server and MySQL-client packages to get a functional MySQL installation. The other packages are not required for a standard installation. If you want to run a MySQL-Max server that has additional capabilities, you should also install the MySQL-Max RPM. However, you should do so only after installing the MySQL-server RPM.

 

If you get a dependency failure when trying to install the MySQL 4.0 packages (for example, ``error: removing these packages would break dependencies: libmysqlclient.so.10 is needed by ...''), you should also install the package MySQL-shared-compat, which includes both the shared libraries for backward compatibility (libmysqlclient.so.12 for MySQL 4.0 and libmysqlclient.so.10 for MySQL 3.23).

 

The following RPM packages are available:

MySQL-server-VERSION.i386.rpm The MySQL server. You will need this unless you only want to connect to a MySQL server running on another machine. Note: Server RPM files were called MySQL-VERSION.i386.rpm before MySQL 4.0.10. That is, they did not have -server in the name.

MySQL-Max-VERSION.i386.rpm The MySQL-Max server. This server has additional capabilities that the one provided in the MySQL-server RPM does not. You must install the MySQL-server RPM first, because the MySQL-Max RPM depends on it.

MySQL-client-VERSION.i386.rpm The standard MySQL client programs. You probably always want to install this package.

MySQL-bench-VERSION.i386.rpm Tests and benchmarks. Requires Perl and the DBD::mysql module.

MySQL-devel-VERSION.i386.rpm The libraries and include files that are needed if you want to compile other MySQL clients, such as the Perl modules.

MySQL-shared-VERSION.i386.rpm This package contains the shared libraries (libmysqlclient.so*) that certain languages and applications need to dynamically load and use MySQL.

MySQL-shared-compat-VERSION.i386.rpm This package includes the shared libraries for both MySQL 3.23 and MySQL 4.0. Install this package instead of MySQL-shared if you have applications installed that are dynamically linked against MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking the library dependencies. This package has been available since MySQL 4.0.13.

MySQL-embedded-VERSION.i386.rpm The embedded MySQL server library (from MySQL 4.0).

MySQL-VERSION.src.rpm This contains the source code for all of the previous packages. It can also be used to rebuild the RPMs on other architectures (for example, Alpha or SPARC).

 

中文翻譯:

MySQL-VERSION.i386.rpm MySQL服務器。除非你只是想要與運行在其他機器上MySQL服務器連接,否則你將需要它。

MySQL-client-VERSION.i386.rpm 標準MySQL客戶程序。你可能總是需要安裝這個包。

MySQL-bench-VERSION.i386.rpm 測試和基準程序。需要Perlmsql-mysql-modules RPM

MySQL-devel-VERSION.i386.rpm 所需的庫和包含文件。如果你想要編譯其他MySQL客戶程序, 例如Perl模塊。

MySQL-VERSION.src.rpm 包含上述所有包的源代碼。它也能被用來嘗試爲其他硬件平臺構造RPM(例如,AlphaSPARC)

查看一個RPM包中的所有文件:

shell>; rpm - qpl  MySQL-VERSION.i386.rpm

實施一個標準的最小安裝,運行這個命令:

shell>; rpm -i MySQL-VERSION.i386.rpm  MySQL-client-VERSION.i386.rpm

 

5.4 error: Cannot find libmysqlclient under /usr

現象描述:

error: Cannot find libmysqlclient under /usr

解決辦法:

其實,和5.1解決辦法相同。把/usr/lib64/mysql copy to /usr/lib/

 

5.5 CMS目錄權限問題

現象描述:

進入install頁面後,提示有些目錄沒有讀寫權限,如下:

/usr/local/apache/htdocs/uploads

目錄名           讀取權限       寫入權限

/      []       [X]    ----指的是 /usr/local/apache/htdocs/uploads

/plus/*    []       [X]

/dede/* []       [X]

/data/*   []       []

/a/*         []       []

/install    []       []

/special   []       []

/uploads/*      []       []

解決辦法:

安裝CMS時候,提示權限不夠,需要修改uploads目錄權限

 Chmod 777 uploads -R

5.6 Deprecated: Function ereg_replace() is deprecated

注意:dedecms 5.6以上版本對php5.3支持有瑕疵!如果用php5.3版本,在安裝cms安裝成功後,系統後臺頁面會提示“針對於安裝完成後出現安裝完出現Deprecated: Function ereg_replace() is deprecated ....”。

解決有兩種方法,見第5節。

第一種:

dedecms由於技術人員的習慣問題可能針對php5.3甚至更高版本的php支持會有些錯誤,大家可以打開文件dede/config.php

找到define('DEDEADMIN', ereg_replace("[///]{1,}", '/', dirname(__FILE__) ) );

沒有必要刪除,只要在這句前面加入"//"將其隱掉就好了,然後在下面加一句

define('DEDEADMIN',strtr(dirname(__FILE__),'///','//'));

就可以了!上傳覆蓋,然後更新下在看看,應該解決問題!

第二種:

重新下載php5.2的包。其實這樣使用也不麻煩,就是重新編譯罷了,但是解決問題最直接的方法。爲了防止後續再有什麼問題,我就使用了php5.2重新編譯了一遍。

 

對以上操作正則表達式的解釋如下:

在正則表達式中,反斜線通常與其它字符一起構成特殊的結構,譬如‘/d’用來匹配數字字符,‘/s’用來匹配空白字符,‘/1’用來反向引用第一個分組捕獲的文本。

可是,如果我們在正則表達式中,僅僅需要表示“反斜線”字符本身,該如何做呢?

其實,正則表達式對這個問題的處理,與字符串的處理是一樣的,也就是說,在正則表達式中,必須用轉義序列‘//’來表示單個反斜線。

這個規定會帶來一個有趣的問題:正則表達式中單獨出現的反斜線字符,在正則表達式的層面,必須以轉義序列‘//’來表示,然而,每個反斜線,在表示正則表達 式的字符串中,又必須以轉義序列‘//’來表示。所以,在字符串中,必須寫出四個反斜線‘////’,才能對應到正則表達式中單獨出現的一個反斜線字符: 在字符串處理層面,它們會被識別爲兩個反斜線‘//’,在正則表達式的層面,它們會被識別爲單個反斜線字符‘/’。

 

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