WordPress WooCommerce Ubuntu22.02搭建

资源申请

机器

阿里云购买机器,最低需要2.0G内存,低于这个安装Woo Commerce插件的时候会有bug
记得需要有外网ip可供访问

域名

阿里云购买即可

证书

直接使用免费证书
https://freessl.cn/
按照指示部署好 ACME

LNMP部署

安装基础软件

apt update 
apt install nginx php-fpm mysql-server

修改nginx配置

vim /etc/nginx/sites-available/default
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}
server {
    #listen  default_server;
    #listen [::]:80 default_server;

    # SSL configuration
    #
     listen 443 ssl default_server;
     listen [::]:443 ssl default_server;
     ssl_certificate /root/.acme.sh/nntall.com_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/nntall.com_ecc/nntall.com.key;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;
    gzip off;
    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

安装wordpress

基本遵循官方的安装方案
https://developer.wordpress.org/advanced-administration/before-install/howto-install/

数据库创建

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

CREATE USER "wordpress"@"localhost" IDENTIFIED BY "xxxxxxxxxx";


GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost";

FLUSH PRIVILEGES;

EXIT;

下载和解压wp

 wget https://wordpress.org/latest.zip
apt install unzip
unzip latest.zip
cp -r /root/wordpress/* /var/www/html/

修改wp-config配置

主要是修改数据库配置和自动生成
https://api.wordpress.org/secret-key/1.1/salt/

 vim wp-config.php
<?php
define( 'WP_CACHE', true );

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the website, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/documentation/article/editing-wp-config-php/
 *
 * @package WordPress
 */

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

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', 'xxxxx' );

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

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

/** 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',         '|[^?SF8sVJFf_)7hN2B#xxxx<TGj|tD:$ORE,G1`m@4p-NgU:O;+=&56sJ2PbS`#H');
define('SECURE_AUTH_KEY',  '&o8nzJFKO/Zv:%.=m/zp2KitcJI_1[U~5<|W<7(-uUi+b!Ps8Got^AJ$Sw[!Zp+x');
define('LOGGED_IN_KEY',    'xxx_s++7IT;:j$t>Iz]wHt_/6');
define('NONCE_KEY',        '[-kC}p7o)K>7-,V%.=-2*xxxxiZ-IY?@`H-d_7sW%Tz0%bsd./Sw/};*kPm7Jx}Wc=');
define('AUTH_SALT',        '.~l[BqEv|q!$m6x+^<L{ 7]xxx8=[| o`Z2(H-^6aNm7U{%*Bko6E-|?XDX2-RbY?*L');
define('SECURE_AUTH_SALT', 'G AUu)qv?1]cM|%S[9Bxxx[./,-&5oP!S+Ybeo;n+a>bE3(u$#?MPlbI?Cv|.4yh|6}');
define('LOGGED_IN_SALT',   'i6*J5oX-z:>gYP8&xxx%UY*O,P!`.IhhO=L 3Ot0L;F@]SH{=H{<o0`p(y-qkW)|>@B');
define('NONCE_SALT',       's(VtDjKH~E7CM`-|!<$I4xxxTF+LE6!JZ,6-gZ#`1I5rh@Y+xbD}1-heGr-b[F/c$nd');
/**#@-*/

/**
 * 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_';

/**
 * 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 documentation.
 *
 * @link https://wordpress.org/documentation/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



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

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
    define( 'ABSPATH', __DIR__ . '/' );
}

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

记得修改文件夹权限

chown -R  www-data html

直接进入

http://xxxx/wp-admin/install.php
按照引导安装完成即可

安装woo commerce

确保文件夹给了权限后直接
plugin-> add new plugin 搜索安装即可

其他修改

价格展示顺序和模板

我想要的效果如下

商品详情页

列表页

首先修改展示顺序

vim /var/www/html/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php

其实就是调换了一个顺序

function wc_format_sale_price( $regular_price, $sale_price ) {
        // Format the prices.
        $formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
        $formatted_sale_price    = is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price;

        // Add the sale price.
        $price = '<ins aria-hidden="true">' . $formatted_sale_price . '</ins>';

        // For accessibility (a11y) we'll also display that information to screen readers.
        $price .= '<span class="screen-reader-text">';
        // translators: %s is a product's current (sale) price.
        $price .= esc_html( sprintf( __( 'Current price is: %s.', 'woocommerce' ), wp_strip_all_tags( $formatted_sale_price ) ) );
        $price .= '</span>';


        // Strikethrough pricing.
        $price .= '<del aria-hidden="true">' . $formatted_regular_price . '</del> ';

        // For accessibility (a11y) we'll also display that information to screen readers.
        $price .= '<span class="screen-reader-text">';
        // translators: %s is a product's regular price.
        $price .= esc_html( sprintf( __( 'Original price was: %s.', 'woocommerce' ), wp_strip_all_tags( $formatted_regular_price ) ) );
        $price .= '</span>';

        return apply_filters( 'woocommerce_format_sale_price', $price, $regular_price, $sale_price );
}

增加css全局样式

.wc-block-components-product-price del {
    color: gray;
     padding-left: 10px;
}


.single-product .wc-block-components-product-price del {
    font-size: medium;
}


.wc-block-components-product-price > span {
    color: var(--wp--preset--color--contrast-2);
}

.wc-block-components-product-price > ins {
    color: var(--wp--preset--color--contrast-2);
}

tips

wordpress用了古堡编辑器以后已经非常厉害了,直接自己编辑即可,不过目前的问题是提供的block有点少,这个还需要研究怎么处理,不过整体问题不大。
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,809评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,189评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,290评论 0 359
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,399评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,425评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,116评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,710评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,629评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,155评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,261评论 3 339
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,399评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,068评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,758评论 3 332
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,252评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,381评论 1 271
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,747评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,402评论 2 358

推荐阅读更多精彩内容