Moke|墨客

 找回密码
 立即注册
搜索
查看: 8819|回复: 0

百度bae搭建wordpress

[复制链接]

3636

主题

0

回帖

3681

积分

超级版主

Rank: 8Rank: 8

积分
3681
发表于 2016-5-12 18:15:03 | 显示全部楼层 |阅读模式






                wordpress下载:http://cn.wordpress.org/
SVN下载:http://tortoisesvn.net/downloads.html

第一步: 注册百度帐号。如果您还没有百度账号,点击这里注册
第二步:完成注册后进入百度开发者平台,注册成为百度开发者,获得邀请码。具体方法见如何获得邀请码        
   


第三步:激活账号。登录百度开发者中心,点击“百度应用引擎 BAE”下的“开始使用”:



第四步:在新页面的右上角点击 “创建应用”,注意要选择”Web应用“,”不接入,仅托管到BAE“,”PHP“三项。


创建成功后,点击页面左下角的”我的云服务(BAE)“:

在新页面点击左下角的”我的应用“,出现下图的页面,在右侧列表中找到刚刚创建的名为的应用,点击右侧操作栏中的“管理”


点击“管理” —>“创建新版本”按钮,获得SVN地址:

第五步:使用SVN管理代码,关于SVN管理和上传代码,在百度开发者中心上有详细的讲解,地址:
SVN管理和上传 ,我checkout的目录 ”E:SVNtest”


第六步:配置mysql数据库
点击“云数据库”,再点击创建数据库,完成数据库的配置,并得到数据库的名称。

点击“phpMyadmin”后,点击“操作”,修改数据库字符集,界面如下:

第七步:在云存储中创建bucket,用于存储wordpress上传的资源。

第八步:下载wordpress,并解压后得到的所有文件复制到”E:SVNnodejsblog”(替换成你自己checkout文件夹), 然后使用SVN上传代码到BAE。

点击“Add”后一直点击“ok”,等待完成后开始上传文件:

点击“SNV Commit”后一直“ok”,直到上传完成。
第九步:等到上传成功,在安装wordpress之前需要配置wp-config.php文件,(只需修改$dbname和$bcs_bucket),具体配置如下:
            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48
            49
            50
            51
            52
            53
            54
            55
            56
            57
            58
            59
            60
            61
            62
            63
            64
            65
            66
            67
            68
            69
            70
            71
            72
            73
            74
            75
            76
            77
            78
            79
            80
            81
            82
            83
            84
            85
            86
            87
            88
            89
            90
            91
            92
            93
            94
            95
            
                        <?php
              //创建的云数据库名称和申请的bucket
            $dbname = &quot;NmbmJnwQDieJRxUDBmiJ&quot;;
            $table_prefix  = 'wp';
            $bcs_bukect = 'baeueditor';
            ?>
            <?php
              //从环境变量中获得数据库的主机地址、用户名和密码
            $ip = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
            $port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
            $host = $ip.&quot;:&quot;.$port;
            $user = getenv('HTTP_BAE_ENV_AK');
            $pass = getenv('HTTP_BAE_ENV_SK');
            // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
            /** WordPress 数据库的名称 */
            define('DB_NAME', $dbname);
            /** MySQL 数据库用户名 */
            define('DB_USER', $user);
            /** MySQL 数据库密码 */
            define('DB_PASSWORD', $pass);
            /** MySQL 主机 */
            define('DB_HOST', $host);
            define('BCS_BUCKET', $bcs_bukect);
            /** 创建数据表时默认的文字编码 */
            define('DB_CHARSET', 'utf8');
            /** 数据库整理类型。如不确定请勿更改 */
            define('DB_COLLATE', '');
            /**#@+
             * 身份认证密匙设定。
             *
             * 您可以随意写一些字符
             * 或者直接访问 {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org 私钥生成服务},
             * 任何修改都会导致 cookie 失效,所有用户必须重新登录。
             *
             * @since 2.6.0
             */
            define('AUTH_KEY',         '$%^&*');
            define('SECURE_AUTH_KEY',  '123231');
            define('LOGGED_IN_KEY',    '21');
            define('NONCE_KEY',        '212');
            define('AUTH_SALT',        '21332');
            define('SECURE_AUTH_SALT', '324');
            define('LOGGED_IN_SALT',   '3234');
            define('NONCE_SALT',       '24');
            /**#@-*/
            /**
             * WordPress 数据表前缀。
             *
             * 如果您有在同一数据库内安装多个 WordPress 的需求,请为每个 WordPress 设置不同的数据表前缀。
             * 前缀名只能为数字、字母加下划线。
             */
            /**
             * WordPress 语言设置,中文版本默认为中文。
             *
             * 本项设定能够让 WordPress 显示您需要的语言。
             * wp-content/languages 内应放置同名的 .mo 语言文件。
             * 要使用 WordPress 简体中文界面,只需填入 zh_CN。
             */
            define('WPLANG', 'zh_CN');
            /**
             * 开发者专用:WordPress 调试模式。
             *
             * 将这个值改为&ldquo;true&rdquo;,WordPress 将显示所有用于开发的提示。
             * 强烈建议插件开发者在开发环境中启用本功能。
             */
            define('WP_DEBUG', false);
            /* 好了!请不要再继续编辑。请保存本文件。使用愉快! */
            /** WordPress 目录的绝对路径。 */
            /****************************************
            *use proxy to visit network
            ****************************************/
            define('WP_PROXY_HOST', getenv('HTTP_BAE_ENV_ADDR_FETCHURL'));
            define('WP_PROXY_USERNAME', getenv('HTTP_BAE_ENV_AK'));
            define('WP_PROXY_PASSWORD', getenv('HTTP_BAE_ENV_SK'));
            if( !defined('ABSPATH') )
                define('ABSPATH', dirname(__FILE__) . '/');
            /** 设置 WordPress 变量和包含文件。 */
            require_once(ABSPATH . 'wp-settings.php');
            ?>
            

            


配 置wp-config.php完成后,打开wp-admin/includes/file.php,改成使用BAE提供的Mysql服务,在文件中找 到 function wp_handle_upload( &$file, $overrides = false, $time =  null )函数,在该函数中找到$filename = wp_unique_filename( $uploads['path'],  $file['name'], $unique_filename_callback ); 删除下面的代码:
            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            
                        // Move the file to the uploads dir
                $new_file = $uploads['path'] . &quot;/$filename&quot;;
                if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
                    return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
                // Set correct file permissions
                $stat = stat( dirname( $new_file ));
                $perms = $stat['mode'] & 0000666;
                @ chmod( $new_file, $perms );
                // Compute the URL
                $url = $uploads['url'] . &quot;/$filename&quot;;
                if ( is_multisite() )
                    delete_transient( 'dirsize_cache' );
                return apply_filters( 'wp_handle_upload', array( 'file' => $new_file,'url' => $url, 'type' => $type ), 'upload' );
            

            


然后在该行下添加如下代码:
            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            
                        $tmp_file = wp_tempnam($filename);
            // Move the file to the uploads dir
             if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) )
                    return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
             // If a resize was requested, perform the resize.
             $image_resize = isset( $_POST['image_resize'] ) && 'true' == $_POST['image_resize'];
             $do_resize = apply_filters( 'wp_upload_resize', $image_resize );
             $size = @getimagesize( $tmp_file );
             if ( $do_resize && $size ) {
                    $old_temp = $tmp_file;
                    $tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized');
                    if ( ! is_wp_error($tmp_file) ) {
                        unlink($old_temp);
                    } else {
                        $tmp_file = $old_temp;
                    }
                }
                //新版采用百度云存储
                //上传到云存储
                $bucket = constant('BCS_BUCKET');
                $opt = array();
                $baidu_bcs = new BaiduBCS();
                $object =  &quot;/$filename&quot;;
                $fileUpload = $tmp_file;
                if( !file_exists($fileUpload) )
                {
                    die('file is not existed!!!!!!!!!!!!!');
                }
                $re = $baidu_bcs->create_object ( $bucket, $object, $fileUpload, $opt);
                trigger_error( print_r($re, true) );
                unlink($tmp_file);
                $url = $baidu_bcs->generate_get_object_url($bucket, $object);
                //echo '??????'; exit;
                if ( is_multisite() )
                    delete_transient( 'dirsize_cache' );
                //exit(&quot;$new_file     !!</br>      $url&quot;);
                return apply_filters( 'wp_handle_upload', array( 'file' => $new_file,'url' => $url, 'type' => $type ), 'upload' );
            

            


配置完成后,在打开浏览器中输入第四步中申请的域名,开始安装wordpress,配置blog:

配置完成后,(在安装界面如果没有跳转,请点击&ldquo;刷新&rdquo;,刷新当前页面)你就可以使用百度的BAE+wordpress玩自己的博客了。

如果博客上出现中文乱码的情况,可以采用下面的方法解决:
在 wp-includes文件夹下找到wp-db.php文件,使用文字编辑器打开,在文件第1063行 $this->select(  $this->dbname,$this->dbh ); 后面加上:$this->query(&ldquo;set names  utf8&Prime;);  然后重新上传到云服务上,使用。(如果您已创建了数据库,请先删除原来创建的数据库,如果不删除,官方文字依然是乱码)请一定注意。
百 度在wordpress开发了一个非常强大的编辑软件,附件wp-ueditor.zip,具体操作方法,将文件解压到wp- contentplugins目录下,在打开wordpress,仪表盘&mdash;-插件&mdash;&ndash;UEditor(点击下方的启用),即可在文章编辑页面中使用,用 用你就知道它有多么的强大了,很轻松搞定图片上传和插入到文章中的问题。(推荐使用,因为默认编辑器上传的图片会变成超链接)

wp-ueditor.zip
附件中wordpress+bae.zip是我配置好的,只需修改wp-config.php文件中的$dbname和$bcs_bucket,上传到bea上即可运行(建议使用本版本,已经加入UEditor插件)
wordpress+BAE.zip
原创文章,转载请注明: 转载自岳
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 

 

快速回复 返回顶部 返回列表