從0到1搭建wordpress

推薦一個很棒的網站騰訊云的開發(fā)者實驗室

作者就是跟著開發(fā)者實驗室的教程搭的第一個wordpress,教程很棒不過有些小坑,根據其教程略作修改如下,另外由于價格原因最終選了阿里云搭建本博客= =!


本實驗用centos 6.8 64位系統(tǒng),其他系統(tǒng)可能在linux命令有點差別


  • 安裝Nginx

    • 用yum安裝Nginx
      yum install nginx -y
    • 修改/etc/nginx/default.conf(nginx的默認配置,沒啥用,后面會被代替),去除對IPv6的監(jiān)聽,示例如下:

    CentOS 6 不支持 IPv6,需要取消對 IPv6 地址的監(jiān)聽,否則 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 進程(默認監(jiān)聽9000):
      service php-fpm start
    • 設置PHP-FPM 為開機啟動
      chkconfig php-fpm on
    • 至此LNMP環(huán)境安裝完成
  • 安裝WordPress

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

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

    默認安裝了最新版英文包,會導致在wordpress后臺選網站語言選中文沒反應,因為缺少中文語言包。
    解決方案:到網上下載一個中文版,將wordpress-content中的lanuages文件夾加入到服務器相同目錄下(wordpress-content文件夾下)

  • 配置wordpress數據庫

    • 進入Mysql,創(chuàng)建 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 將請求轉發(fā)給php
    • 刪掉default.conf 文件, 在/etc/nginx/conf.d 創(chuàng)建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

域名購買,解析后續(xù)再說~
最后附上我搭建的博客,羞恥的域名~
網站沒備案= =!被封了

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容