从0到1搭建wordpress

推荐一个很棒的网站腾讯云的开发者实验室

作者就是跟着开发者实验室的教程搭的第一个wordpress,教程很棒不过有些小坑,根据其教程略作修改如下,另外由于价格原因最终选了阿里云搭建本博客= =!


本实验用centos 6.8 64位系统,其他系统可能在linux命令有点差别


  • 安装Nginx

    • 用yum安装Nginx
      yum install nginx -y
    • 修改/etc/nginx/default.conf(nginx的默认配置,没啥用,后面会被代替),去除对IPv6的监听,示例如下:

    CentOS 6 不支持 IPv6,需要取消对 IPv6 地址的监听,否则 Nginx 不能成功启动。

    server {
        listen       80 default_server;
        # listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
    
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
    
        location / {
        }
    
        error_page 404 /404.html;
            location = /40x.html {
        }
    
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    
    }
    
    • 修改完成后启动nginx:
      nginx
    • 此时,可访问本机外网ip 来确认是否已经安装成功。
      *将nginx设为开机启动:
      chkconfig nginx on
  • 安装Mysql

    • 使用yum安装Mysql:
      yum install mysql-server -y
    • 安装完成后,启动Mysql服务:
      service mysqld restart
    • 设置Mysql账户root密码:
      /usr/bin/mysqladmin -u root password 'yourPassword'
    • 将Mysql设置为开机启动:
      chkconfig mysqld on
    • 安装PHP
    • 使用 yum 安装PHP:
      yum install php-fpm php-mysql php-gd -y

    腾讯教程上未安装php-gd包会导致,在wordpress上传图片裁剪时报错

    • 启动php-fpm 进程(默认监听9000):
      service php-fpm start
    • 设置PHP-FPM 为开机启动
      chkconfig php-fpm on
    • 至此LNMP环境安装完成
  • 安装WordPress

    • 使用yum 安装WordPress
      yum install wordpress -y

    在/usr/share/press 可以看到wordpress的源码

    默认安装了最新版英文包,会导致在wordpress后台选网站语言选中文没反应,因为缺少中文语言包。
    解决方案:到网上下载一个中文版,将wordpress-content中的lanuages文件夹加入到服务器相同目录下(wordpress-content文件夹下)

  • 配置wordpress数据库

    • 进入Mysql,创建 wordpress 数据库
    mysql -uroot --password='yourPassword';
    CREATE DATABASE wordpress;
    exit
    
    • 在wordpress配置文件(/etc/wordpress/wp-config.php)中配置数据库,配置文件如下:
<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'yourPassword');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';

/**
 * See http://make.wordpress.org/core/2013/10/25/the-definitive-guide-to-disabling-auto-updates-in-wordpress-3-7
 */

/* Disable all file change, as RPM base installation are read-only */
define('DISALLOW_FILE_MODS', true);

/* Disable automatic updater, in case you want to allow
   above FILE_MODS for plugins, themes, ... */
define('AUTOMATIC_UPDATER_DISABLED', true);

/* Core update is always disabled, WP_AUTO_UPDATE_CORE value is ignore */

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', '/usr/share/wordpress');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');


  • 配置nginx

    • 配置nginx 将请求转发给php
    • 删掉default.conf 文件, 在/etc/nginx/conf.d 创建wordpress.conf,文件内容如下:
    server {
        listen 80;
        root /usr/share/wordpress;
        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php index.php;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    
    • 重启nginx,加载配置
      nginx -s reload

    如果有域名的话可以在wordpress 文件中配置,配置项 server_name www.yourdomain.com;

部署完成,通过ip访问地址: http://<您的域名>/wp-admin/install.php

域名购买,解析后续再说~
最后附上我搭建的博客,羞耻的域名~
网站没备案= =!被封了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容