Category: Wordpress

  • 왜 ‘woocommerce_update_options_shipping_’ . $this->id 이렇게 해야 할까? ‘woocommerce_update_options_shipping_. $this->id’ 로 쓰면 틀리나?

     

    'woocommerce_update_options_shipping_. $this->id' 이렇게 쓰면 문법 오류가 발생합니다. 이 부분은 문자열 연결(string concatenation)과 관련된 것으로, PHP에서 올바른 문법을 사용해야 합니다.

    1. 문법 차이

    • 올바른 방식: 'woocommerce_update_options_shipping_' . $this->id
      • **'.'**는 PHP에서 문자열을 **연결(concatenate)**하는 연산자입니다.
      • 이 방식은 'woocommerce_update_options_shipping_' 문자열과 $this->id 속성 값을 하나의 문자열로 결합합니다.
    • 잘못된 방식: 'woocommerce_update_options_shipping_. $this->id'
      • 여기서 . $this->id 부분은 따옴표 안에 그대로 문자열로 인식됩니다.
      • PHP는 . 연산자를 따옴표 안에서 문자열로 간주하므로, 실제로 문자열을 연결하지 않습니다.
      • 이로 인해 $this->id가 문자열에 포함되지 않고, 전체 문자열이 'woocommerce_update_options_shipping_. $this->id'로 처리됩니다.

    2. 예시 비교

    • 올바른 코드:phpCopyEdit'woocommerce_update_options_shipping_' . $this->id
      • $this->id'custom_shipping'이라면, 이 코드는 **'woocommerce_update_options_shipping_custom_shipping'**이 됩니다.
    • 잘못된 코드:phpCopyEdit'woocommerce_update_options_shipping_. $this->id'
      • PHP는 이 문자열을 그대로 **'woocommerce_update_options_shipping_. $this->id'**로 처리하고, $this->id 변수의 값을 문자열에 포함시키지 않습니다.

    3. 결론

    . 연산자를 따옴표 바깥에 사용해야 $this->id 값을 포함한 동적인 문자열을 생성할 수 있습니다. 그렇지 않으면 PHP는 문자열을 그대로 해석하여, 변수를 포함한 문자열 결합이 이루어지지 않습니다. 따라서 '.' 연산자를 올바르게 사용해야 동적인 훅 이름을 생성할 수 있습니다.

  • WordPress plugin 개발에서 add_filter와 add_action의 차이

    add_filteradd_action은 WordPress에서 플러그인을 개발할 때 사용하는 두 가지 주요 함수입니다. 이 두 함수는 WordPress의 Hook 시스템의 일부로, 플러그인이나 테마가 WordPress의 기본 기능을 확장하거나 수정할 수 있도록 도와줍니다.

    1. Hook 시스템 개요

    • Actions: 특정 시점에 실행되는 함수입니다. 예를 들어, 게시글이 저장될 때 특정 작업을 실행할 수 있습니다.
    • Filters: 특정 데이터를 변경할 수 있는 기회를 제공합니다. 예를 들어, 게시글 제목을 수정할 수 있습니다.

    2. add_action

    add_action 함수는 WordPress가 특정 Action Hook에서 실행될 때 사용자 정의 함수를 호출하도록 등록합니다. 이 함수는 주로 작업을 수행하는 데 사용됩니다.

    사용 예시:

    // 사용자가 로그인할 때 메시지를 로그에 기록하는 작업을 추가
    function log_user_login($user_login) {
        error_log("User logged in: " . $user_login);
    }
    add_action('wp_login', 'log_user_login');
    
    • wp_login: 사용자가 로그인할 때 실행되는 Action Hook.
    • log_user_login: 사용자가 로그인할 때 실행될 사용자 정의 함수.

    주요 특징:

    • 동작을 추가할 때 사용.
    • 기존 기능을 중단하지 않고 추가적인 작업을 수행.

    3. add_filter

    add_filter 함수는 특정 Filter Hook을 통해 전달되는 데이터를 수정할 때 사용됩니다. 이 함수는 주로 특정 데이터를 변경하거나 조작하는 데 사용됩니다.

    사용 예시:

    // 모든 게시글 제목 앞에 "Special: "를 추가
    function modify_post_title($title) {
        return 'Special: ' . $title;
    }
    add_filter('the_title', 'modify_post_title');
    
    • the_title: 게시글 제목을 출력하기 전에 데이터를 수정할 수 있는 Filter Hook.
    • modify_post_title: 제목을 수정하는 사용자 정의 함수.

    주요 특징:

    • 데이터를 변경하거나 조작할 때 사용.
    • 전달된 데이터를 수정하여 반환.

    4. 비교

    기능add_actionadd_filter
    목적특정 시점에 작업을 추가데이터를 수정하거나 필터링
    반환값없음필터링된 데이터를 반환해야 함
    사용 사례사용자가 로그인할 때 이메일을 보내기게시글 제목을 수정
    훅 유형Action HookFilter Hook

    5. 심화 예시

    add_action 심화 예시

    사용자가 로그아웃할 때 로그를 남기고 이메일을 보낼 수 있습니다.

    function notify_user_logout($user_login) {
        error_log("User logged out: " . $user_login);
        wp_mail('admin@example.com', 'User Logout', $user_login . ' has logged out.');
    }
    add_action('wp_logout', 'notify_user_logout');
    

    add_filter 심화 예시

    블로그 게시물 내용에 “이 글은 수정되었습니다.”라는 문구를 추가할 수 있습니다.

    function append_modified_notice($content) {
        return $content . '<p>This post has been modified.</p>';
    }
    add_filter('the_content', 'append_modified_notice');
    

    6. 결론

    • add_action은 WordPress에서 특정 이벤트가 발생할 때 추가 작업을 수행하도록 해줍니다.
    • add_filter는 WordPress에서 특정 데이터를 필터링하거나 변경할 수 있는 기회를 제공합니다.

    이 두 가지를 적절히 사용하면 WordPress의 기본 기능을 훨씬 더 유연하게 확장할 수 있습니다.

  • 배송방법 추가 코드

    <?php
    /*
    Plugin Name: Custom Shipping Method
    Plugin URI:
    Description: WooCommerce Custom Shipping Method
    Version: 1.0
    Author: Your Name
    */

    if (!defined(‘ABSPATH’)) {
    exit;
    }

    function custom_shipping_method_init() {
    if (!class_exists(‘Custom_Shipping_Method’)) {

    class Custom_Shipping_Method extends WC_Shipping_Method {
    /**
    * Weight unit
    */
    private $weight_unit;

    /**
    * Constructor for shipping class
    */
    public function __construct($instance_id = 0) {
    $this->id = ‘custom_shipping_method’;
    $this->instance_id = absint($instance_id);
    $this->title = ‘사용자 정의 배송’;
    $this->method_title = ‘사용자 정의 배송 방법’;
    $this->method_description = ‘배송 방법 설정을 관리합니다’;
    $this->supports = array(
    ‘shipping-zones’,
    ‘instance-settings’,
    ‘instance-settings-modal’
    );

    $this->weight_unit = get_option(‘woocommerce_weight_unit’);

    $this->init();
    }

    /**
    * Initialize shipping method
    */
    private function init() {
    $this->init_form_fields();
    $this->init_settings();

    $this->enabled = $this->get_option(‘enabled’);
    $this->title = $this->get_option(‘title’);

    add_action(‘woocommerce_update_options_shipping_’ . $this->id,
    array($this, ‘process_admin_options’));
    add_action(‘woocommerce_update_options_shipping_’ . $this->id,
    array($this, ‘clear_transients’));
    }

    /**
    * Initialize form fields
    */
    public function init_form_fields() {
    $this->instance_form_fields = array(
    ‘enabled’ => array(
    ‘title’ => ‘활성화’,
    ‘type’ => ‘checkbox’,
    ‘label’ => ‘이 배송 방법 활성화’,
    ‘default’ => ‘yes’
    ),
    ‘title’ => array(
    ‘title’ => ‘배송방법명’,
    ‘type’ => ‘text’,
    ‘description’ => ‘고객에게 표시될 배송 방법 이름’,
    ‘default’ => $this->method_title,
    ‘desc_tip’ => true
    ),
    ‘cost’ => array(
    ‘title’ => ‘기본 배송비’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘기본 배송비를 입력하세요’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘100’,
    ‘min’ => ‘0’
    )
    ),
    ‘cost_per_weight’ => array(
    ‘title’ => $this->weight_unit.’당 추가 배송비’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘무게당 추가되는 배송비’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘100’,
    ‘min’ => ‘0’
    )
    ),
    ‘min_weight’ => array(
    ‘title’ => ‘최소 배송 무게 (‘.$this->weight_unit.’)’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘이 무게 이상일 때 배송 가능’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘0.1’,
    ‘min’ => ‘0’
    )
    ),
    ‘max_weight’ => array(
    ‘title’ => ‘최대 배송 무게 (‘.$this->weight_unit.’)’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘0으로 설정시 무제한’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘0.1’,
    ‘min’ => ‘0’
    )
    ),
    ‘excluded_countries’ => array(
    ‘title’ => ‘제외 국가’,
    ‘type’ => ‘multiselect’,
    ‘class’ => ‘wc-enhanced-select’,
    ‘options’ => WC()->countries->get_shipping_countries()
    )
    );
    }

    /**
    * Calculate shipping cost
    */
    public function calculate_shipping($package = array()) {
    $cost = (float)$this->get_option(‘cost’, 0);
    $has_shipping_items = false;
    $weight = 0;

    // 배송 가능한 상품이 있는지 확인하고 무게 계산
    foreach ($package[‘contents’] as $item) {
    if ($item[‘data’]->needs_shipping()) {
    $has_shipping_items = true;
    $product_weight = (float)$item[‘data’]->get_weight();

    if (!empty($product_weight)) {
    $weight += $product_weight * $item[‘quantity’];
    }
    }
    }

    // 배송 가능 여부 확인
    if (!$has_shipping_items) {
    return;
    }

    // 무게가 있는 경우에만 무게 기반 배송비 계산
    $min_weight = (float)$this->get_option(‘min_weight’, 0);
    $max_weight = (float)$this->get_option(‘max_weight’, 0);

    if (($min_weight > 0 && $weight < $min_weight) ||
    ($max_weight > 0 && $weight > $max_weight)) {
    return;
    }

    $cost_per_weight = (float)$this->get_option(‘cost_per_weight’, 0);
    $cost += $weight * $cost_per_weight;

    // 배송비가 0 이상일 때만 배송 방법 추가
    if ($cost >= 0) {
    $rate = array(
    ‘id’ => $this->id . $this->instance_id,
    ‘label’ => $this->title,
    ‘cost’ => $cost,
    ‘calc_tax’ => ‘per_order’
    );

    $this->add_rate($rate);
    }
    }

    /**
    * Check if shipping method is available
    */
    public function is_available($package) {
    if ($this->enabled === ‘no’) {
    return false;
    }

    // 배송지 검사
    if (isset($package[‘destination’])) {
    $shipping_country = $package[‘destination’][‘country’];
    $shipping_state = $package[‘destination’][‘state’];
    $shipping_postcode = $package[‘destination’][‘postcode’];

    // 제외된 국가 확인
    $excluded_countries = $this->get_option(‘excluded_countries’, array());
    if (!empty($excluded_countries) &&
    in_array($shipping_country, $excluded_countries)) {
    return false;
    }

    // 배송지 주소가 비어있는 경우
    if (empty($shipping_country)) {
    return false;
    }
    }

    return apply_filters(
    ‘woocommerce_shipping_’ . $this->id . ‘_is_available’,
    true,
    $package,
    $this
    );
    }

    /**
    * Clear transients
    */
    public function clear_transients() {
    wc_delete_shipping_transients();
    }

    /**
    * Validate settings fields
    */
    public function validate_settings_fields($form_fields = array()) {
    if (!wp_verify_nonce($_POST[‘_wpnonce’], ‘woocommerce-settings’)) {
    return false;
    }
    return $form_fields;
    }
    }
    }
    }

    /**
    * Add shipping method to WooCommerce
    */
    function add_custom_shipping_method($methods) {
    $methods[‘custom_shipping_method’] = ‘Custom_Shipping_Method’;
    return $methods;
    }

    // 후크 등록
    add_action(‘woocommerce_shipping_init’, ‘custom_shipping_method_init’);
    add_filter(‘woocommerce_shipping_methods’, ‘add_custom_shipping_method’);

    // 관리자 스타일 추가
    add_action(‘admin_enqueue_scripts’, function() {
    wp_enqueue_style(‘custom-shipping-admin-style’,
    plugins_url(‘/assets/css/admin.css’, __FILE__));
    });

  • OCI Free Tier 상시 무료 서비스의 Docker 컨테이너에 WordPress 사이트 호스팅

    출처 : https://docs.oracle.com/ko/solutions/oci-free-wordpress-docker/install-and-configure1.html

    https://tyzen.net/2

    설치 및 구성
    OCI Free Tier 상시 무료 서비스의 Docker 컨테이너에 WordPress 사이트 호스팅

    다음 단계에 따라 설치 및 구성을 완료합니다.

    Docker를 설치합니다.
    Docker는 WordPress를 설치 및 유지 관리하는 프로세스를 만듭니다. 이전에는 훨씬 더 쉽게 여러 소프트웨어를 필요로 합니다.
    MySQL를 설치합니다.
    WordPress를 설치하기 전에 데이터를 저장할 MySQL를 설치해야 합니다.
    WordPress를 설치합니다.
    로드 밸런서를 생성하고 OCI 로드 밸런서를 사용하여 SSL 인증서를 설치합니다.
    OCI에 호스트된 WordPress 사이트에 액세스할 수 있도록 도메인의 DNS A 레코드를 로드 밸런서 IP 주소로 업데이트합니다.

    Docker 설치

    VM에 SSH로 접속하고 다음 명령을 실행하여 Docker를 설치합니다.

    sudo yum-config-manager –enable ol8_addons

    sudo dnf install -y dnf-utils zip unzip

    sudo dnf config-manager –add-repo=https://download.docker.com/linux/centos/docker-ce.repo

    sudo dnf install -y docker-ce –nobest

    sudo systemctl start docker

    다음 항목으로 진행하여 MySQL를 설치합니다.
    MySQL 설치

    MySQL를 설치하고 실행하려면 다음 명령을 실행하십시오.

    sudo docker pull container-registry.oracle.com/mysql/community-server:8.0.33-aarch64

    sudo docker run -e MYSQL_ROOT_PASSWORD= -e MYSQL_USER=wp -e MYSQL_PASSWORD= -e MYSQL_DATABASE=wordpress –name wordpressdb –restart on-failure -v
    “$PWD/database”:/var/lib/mysql -d container-registry.oracle.com/mysql/community-server:8.0.33-aarch64

    주:

    MYSQL_ROOT_PASSWORD – 데이터베이스 비밀번호를 입력합니다.
    MYSQL_DATABASE – 데이터베이스 이름을 wordpress로 입력합니다.
    MYSQL_USER – MySQL 사용자 이름을 입력합니다.
    MYSQL_PASSWORD – MySQL 비밀번호를 입력합니다.

    다음 항목으로 이동하여 WordPress를 설치합니다.
    WordPress 설치

    WordPress를 설치하려면 다음 절차를 수행하십시오.

    다음 명령을 실행하여 WordPress Docker 이미지의 최신 버전을 가져옵니다.

    sudo docker pull wordpress

    다음 명령을 실행하여 WordPress를 설치합니다.

    sudo docker run -e WORDPRESS_DB_USER=wp -e WORDPRESS_DB_PASSWORD= –name wordpress –link wordpressdb:mysql -p 80:80 -v
    “$PWD/html”:/var/www/html -d wordpress

    주:
    WORDPRESS_DB_USER – 데이터베이스 사용자 이름을 입력합니다. MySQL를 설치할 때 사용된 것과 동일한 사용자 이름을 사용합니다.
    -e WORDPRESS_DB_PASSWORD= – 데이터베이스 암호를 입력합니다. MySQL를 설치할 때 사용된 것과 동일한 암호를 사용합니다.
    -name wordpress – 컨테이너에 이름을 지정합니다.
    -link wordpressdb:mysql – MySQL 컨테이너 이름입니다.
    -p 80:80 – 컨테이너의 포트를 호스트에 게시하도록 Docker에 지시합니다.
    -v “$PWD/html”:/var/www/html – [host-src:]container-dest: 볼륨을 바인드합니다.
    -d – 컨테이너를 백그라운드로 실행합니다.
    wordpress – 단계 1에서 풀링된 이미지에서 WordPress를 설치하도록 Docker에 지시합니다.
    브라우저에서 컴퓨트 인스턴스의 공용 IP를 실행하고 WordPress 설치를 완료합니다.

    다음 항목으로 이동하여 SSL 인증서 설치를 위한 로드 밸런서를 생성합니다.
    로드 밸런서를 생성하고 SSL 인증서를 설치합니다.

    로드 밸런서를 생성하고 이 로드 밸런서를 사용하여 SSL 인증서를 설치해야 합니다.

    Oracle Cloud 인증서를 사용하여 Oracle Cloud Infrastructure 콘솔에 사인인합니다.
    왼쪽 탐색 창에서 네트워킹, 로드 밸런서, 로드 밸런서 생성을 차례로 누릅니다.
    Load Balancer 옵션을 선택한 다음 Create Load Balancer를 누릅니다.
    로드 밸런서 이름을 입력합니다.
    네트워킹 선택 영역에서 가상 클라우드 네트워크 및 서브넷을 선택하고 다음을 누릅니다.
    백엔드 추가를 누르고 WordPress 컴퓨트 인스턴스를 선택한 후 다음을 누릅니다.
    리스너 이름을 입력합니다.
    HTTPS 트래픽을 처리하려면 다음 필드를 완성하십시오.
    리스너 유형으로 HTTPS를 선택합니다.
    리스너가 수신 트래픽에 대해 모니터하는 포트로 443을 선택합니다.
    SSL 인증서 영역의 인증서 리소스 드롭다운 목록에서 로드 밸런서 관리 인증서를 선택합니다.
    인증 기관에서 도메인의 SSL 인증서를 업로드합니다.
    Specify Private Key 확인란을 선택하고 개인 키를 업로드합니다.
    다음을 누릅니다.
    필요한 로깅 옵션을 선택합니다.
    저장을 누릅니다.

    로드 밸런서 IP 주소를 복사하고 다음 항목으로 진행하여 OCI에 호스트된 WordPress 사이트에 액세스할 수 있도록 도메인의 DNS A 레코드를 로드 밸런서 IP 주소로 업데이트합니다.
    도메인의 DNS A 레코드 업데이트

    OCI에 호스팅된 WordPress 사이트에 액세스할 수 있도록 도메인의 DNS A 레코드를 로드 밸런서 IP 주소로 업데이트해야 합니다.

    주:이러한 단계는 도메인 호스팅 제공자에 따라 다를 수 있으므로 참조로 사용하십시오.

    호스트된 도메인의 DNS 관리 페이지로 이동합니다.
    DNS 레코드 페이지에서 다음을 수행합니다.
    유형을 A로 선택합니다.
    이름을 입력합니다.
    값 필드에 OCI 로드 밸런서 IP 주소를 입력하거나 붙여넣습니다.
    저장을 누릅니다.

    이제 도메인이 Oracle Cloud Free Tier에 호스트된 WordPress 사이트로 재지정됩니다.

  • Organizing Your Blog: Categories, Tags, and HTML Structure

    Organizing Your Blog: Categories, Tags, and HTML Structure

    As a blogger, organizing your content effectively is crucial for both user experience and search engine optimization (SEO). In this post, we will explore the importance of categories and tags, and how to structure your blog using HTML elements.

    Categories: The Foundation of Your Blog

    Categories are the primary way to organize your blog content. They provide a hierarchical structure, making it easy for readers to find related posts. For example, if you have a blog about technology, you might have categories like ‘Software,’ ‘Hardware,’ and ‘Gadgets.’

    **Why Use Categories?**

    Categories help in several ways:

    • They provide a clear structure, making it easier for readers to navigate your blog.
    • They improve SEO by helping search engines understand the content of your blog.
    • They allow you to create subcategories, further organizing your content.

    Tags: The Specific Details

    Tags are optional but highly useful for adding specific details to your posts. Unlike categories, tags do not have a hierarchical relationship and can be used multiple times for different posts.

    **How to Use Tags Effectively?**

    Tags should be used strategically:

    • They should be specific and relevant to the content of the post.
    • They should be consistent across all posts to maintain a uniform structure.
    • They can help in creating a tag cloud, which presents the most frequently used tags, making it easier for readers to find related content.

    HTML Structure: The Backbone of Your Blog

    The HTML structure is essential for organizing and presenting your blog content effectively. Here’s a basic structure you can follow:

    **The Basic HTML Structure:**

    The basic structure of an HTML document includes the , , and tags.

    ### The Tag

    The tag is the root element of your HTML document. It contains all other elements and helps browsers and assistive technologies identify the start of the HTML content.

    ### The Tag

    The section contains meta-information about the page, such as the page title, character set, links to stylesheets, and scripts that should be loaded.

    ### The Tag

    The element contains all the information and other visible content that you want to display on the web page. It includes elements like

    ,

  • When you can’t crop the image for your header for your WordPress Page

    After you install your WordPress, and if you face an error like this, and if you can’t crop new image for your header on your dashboard,

    /var/www# php -v

    PHP Warning: PHP Startup: Unable to load dynamic library ‘imagick.so’ (tried: /usr/lib/php/20240924/imagick.so (/usr/lib/php/20240924/imagick.so: undefined symbol: php_strtolower), /usr/lib/php/20240924/imagick.so.so (/usr/lib/php/20240924/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
    PHP 8.4.0RC3 (cli) (built: Oct 30 2024 11:34:47) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.4.0RC3, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.0RC3, Copyright (c), by Zend Technologies

    ==========================

    use following command

    php –ini

    Check for GD in php.ini

    1. Edit the PHP-FPM php.ini File: Open the main php.ini for PHP-FPM:
      sudo nano /etc/php/8.4/fpm/php.ini
    2. Look for extension=gd: Use the search function (usually CTRL + W in nano) to locate any lines that mention extension=gd.
    3. Comment Out Duplicate Entry: If you find extension=gd in php.ini, comment it out by adding a semicolon (;) in front of it: php.ini
      ;extension=gd
    4. Save and Exit: Save the file and exit the editor.
    5. Restart PHP-FPM: Restart PHP-FPM to apply the change:
      sudo service php8.4-fpm restart

     

  • Installing WordPress on an Ubuntu Server using Nginx, PHP, and MariaDB on Oracle Cloud Infrastructure Free Tier.

    Installing WordPress on an Ubuntu Server using Nginx, PHP, and MariaDB on Oracle Cloud Infrastructure Free Tier.

    Wordpress Installation

    Prerequisites

      • Oracle Cloud Infrastructure Free Tier account
      • Ubuntu Server instance
      • SSH access to the server

     

    Step 1: Update System Packages

    sudo apt update
    sudo apt upgrade -y
     

    Step 2: Install Nginx Web Server

    sudo apt install nginx -y
    sudo systemctl start nginx
    sudo systemctl enable nginx
     

    Step 3: Install MariaDB Database

    sudo apt install mariadb-server -y
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation
     

    During the secure installation:

    • Set root password
    • Remove anonymous users
    • Disallow root login remotely
    • Remove test database
    • Reload privilege tables

     

    Step 4: Install PHP 8.1 and Required Extensions

      sudo add-apt-repository ppa:ondrej/php
      sudo apt update
      sudo apt install php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring
    php8.1-xml php8.1-zip -y

    Step 5: Configure Database for WordPress

       sudo mariadb
    CREATE DATABASE wordpress;
    CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'strong_password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
     

    Step 6: Download and Install WordPress

      cd /tmp
      wget https://wordpress.org/latest.tar.gz
      tar -xvf latest.tar.gz
      sudo mkdir -p /var/www/wordpress
      sudo cp -R wordpress/* /var/www/wordpress/
      sudo chown -R www-data:www-data /var/www/wordpress
      sudo chmod -R 755 /var/www/wordpress
     

    Step 7: Configure Nginx for WordPress

      sudo nano /etc/nginx/sites-available/wordpress
     

    Add the following configuration:

    server {
       listen 80;
       server_name your_domain.com;
       root /var/www/wordpress;
       index index.php;
       location / {
       try_files $uri $uri/ /index.php?$args;
            }
       location ~ \.php${
       fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
       fastcgi_index index.php;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
       }  

     

    Step 8: Enable Site and Restart Services

        sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
        sudo nginx -t
        sudo systemctl restart nginx
        sudo systemctl restart php8.4-fpm
     

    Step 9: Configure WordPress

    • Navigate to http://your_domain.com
    • Follow WordPress setup wizard
    • Create wp-config.php with database details
    •  

    Security Considerations

    • Configure firewall rules in Oracle Cloud Console
    • Open ports 80 and 443
    • Consider installing SSL with Let’s Encrypt
    •  

    Troubleshooting

    • Check Nginx logs: sudo tail /var/log/nginx/error.log
    • Check PHP-FPM logs: sudo tail /var/log/php8.4-fpm.log
    • Verify services: sudo systemctl status nginx php8.4-fpm mariadb