轉載自:http://blog.csdn.net/buutterfly/article/details/5630203
DedeCMS部署--怎樣去部署Apache+Mysql+PHP(LAMP)?
1. Linux OS:
Linux OS:Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
2.Deploy Apache 2.1 下載Apache
下載Apache2 source from http://httpd.apache.org/ ,直接下載在/root下,解壓tar包php-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。因為我的OS是REHL4.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安裝完畢後,測試是否成功可運行netstat看Mysql連接埠是否開啟,如開啟表示服務已經啟動,安裝成功。
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下需要進行下面幾步:
1、home目錄下建立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.
#DirectoryIndex index.html
DirectoryIndex index.php index.html index.shtml index.cgi
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=
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-devel,mysql-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 測試和基準程式。需要Perl和msql-mysql-modules RPM。
MySQL-devel-VERSION.i386.rpm 所需的庫和包含檔案。如果你想要編譯其他MySQL客戶程式, 例如Perl模組。
MySQL-VERSION.src.rpm 包含上述所有包的原始碼。它也能被用來嘗試為其他硬體平台構造RPM(例如,Alpha或SPARC)。
查看一個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重新編譯了一遍。
對以上操作Regex的解釋如下:
在Regex中,反斜線通常與其它字元一起構成特殊的結構,譬如‘/d’用來匹配數字字元,‘/s’用來匹配空白字元,‘/1’用來反向引用第一個分組捕獲的文本。
可是,如果我們在Regex中,僅僅需要表示“反斜線”字元本身,該如何做呢?
其實,Regex對這個問題的處理,與字串的處理是一樣的,也就是說,在Regex中,必須用逸出序列‘//’來表示單個反斜線。
這個規定會帶來一個有趣的問題:Regex中單獨出現的反斜線字元,在Regex的層面,必須以逸出序列‘//’來表示,然而,每個反斜線,在表示正則表達 式的字串中,又必須以逸出序列‘//’來表示。所以,在字串中,必須寫出四個反斜線‘////’,才能對應到Regex中單獨出現的一個反斜線字元: 在字串處理層面,它們會被識別為兩個反斜線‘//’,在Regex的層面,它們會被識別為單個反斜線字元‘/’。