声明:部署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’用来反向引用第一个分组捕获的文本。

可是,如果我们在正则表达式中,仅仅需要表示“反斜线”字符本身,该如何做呢?

其实,正则表达式对这个问题的处理,与字符串的处理是一样的,也就是说,在正则表达式中,必须用转义序列‘//’来表示单个反斜线。

这个规定会带来一个有趣的问题:正则表达式中单独出现的反斜线字符,在正则表达式的层面,必须以转义序列‘//’来表示,然而,每个反斜线,在表示正则表达 式的字符串中,又必须以转义序列‘//’来表示。所以,在字符串中,必须写出四个反斜线‘’,才能对应到正则表达式中单独出现的一个反斜线字符: 在字符串处理层面,它们会被识别为两个反斜线‘//’,在正则表达式的层面,它们会被识别为单个反斜线字符‘/’。