אירוח של WordPress בסביבה הגמישה של App Engine

במדריך הזה נסביר איך לפרוס אתר קטן של WordPress בסביבה הגמישה של App Engine.

מטרות

  • יוצרים מכונה של Cloud SQL מהדור השני.
  • להגדיר אתר WordPress לדוגמה.
  • פורסים את האתר לדוגמה של WordPress בסביבה הגמישה של App Engine.

עלויות

לפני שמתחילים

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Cloud de Confiance project.

  3. Enable the required APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  4. Install the Google Cloud CLI.

  5. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. כדי ליצור פרטי כניסה:
    • נכנסים לדף Credentials במסוף Cloud de Confiance .

      פתיחת הדף API Credentials

    • לוחצים על Create credentials ובוחרים באפשרות Service account key.
    • בוחרים באפשרות חשבון שירות > חשבון השירות של App Engine שמוגדר כברירת מחדל.
    • לוחצים על יצירה.
    • שומרים את המפתח שהורדתם במקום מאובטח.
  8. מתקינים את PHP ואת Composer.
  9. מורידים את Cloud SQL Proxy והופכים אותו לקובץ הפעלה. מוסיפים גם את המיקום של קובץ ההפעלה של Cloud SQL Proxy למשתנה הסביבה PATH.
  10. מתקינים לקוח MySQL ומוודאים שהמיקום של הקובץ להפעלה mysql נמצא במשתנה הסביבה PATH.

יצירה והגדרה של מכונה מדור שני ב-Cloud SQL

  1. יוצרים מכונה של Cloud SQL מדור שני:

    gcloud sql instances create tutorial-sql-instance \
        --activation-policy=ALWAYS \
        --tier=db-n1-standard-1 \
        --region=us-central1
    
  2. מגדירים את סיסמת הבסיס למכונה:

    gcloud sql users set-password root --instance tutorial-sql-instance \
        --password [YOUR_SQL_ROOT_PASSWORD] \
        --host %
    

    כאשר [YOUR_SQL_ROOT_PASSWORD] היא סיסמה מאובטחת לבחירתכם.

  3. מורידים ומריצים את Cloud SQL Proxy:

    ./cloud-sql-proxy \
        -dir /tmp/cloudsql \
        -instances=[YOUR_PROJECT_ID]:us-central1:tutorial-sql-instance \
        -credential_file=[PATH_TO_YOUR_SERVICE_ACCOUNT_JSON]

    כאשר

    • ‫[YOUR_PROJECT_ID] הוא מזהה הפרויקט ב- Cloud de Confiance .

    • ‫[PATH_TO_YOUR_SERVICE_ACCOUNT_JSON] הוא הנתיב לקובץ ה-JSON של חשבון השירות שהורדתם קודם.

    הפלט הבא מציין שהפרוקסי מוכן לחיבורים חדשים:

    Listening on 127.0.0.1:3306 for [YOUR_PROJECT_ID]:us-central1:tutorial-sql-instance
    Ready for new connections
    
  4. בחלון טרמינל אחר, יוצרים מסד נתונים חדש ומשתמש:

    mysql -h 127.0.0.1 -u root --password=[YOUR_SQL_ROOT_PASSWORD]
    mysql> create database tutorialdb;
    mysql> create user 'tutorial-user'@'%' identified by '[YOUR_DATABASE_PASSWORD]';
    mysql> grant all on tutorialdb.* to 'tutorial-user'@'%';
    mysql> exit

    where:

    • ‫[YOUR_SQL_ROOT_PASSWORD] היא סיסמת הבסיס למכונה של Cloud SQL.
    • ‫[YOUR_DATABASE_PASSWORD] היא סיסמה מאובטחת לבחירתכם.

הגדרת הפרויקט ב-WordPress

  1. משכפלים את המאגר לדוגמה:

    git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git
    
  2. עוברים לספרייה שמכילה את הקוד לדוגמה:

    cd php-docs-samples/appengine/flexible/wordpress
    
  3. יחסי תלות של התקנות:

    composer install
    
  4. מריצים את סקריפט העזר:

    php wordpress.php setup -n \
        --dir=./wordpress-project \
        --db_instance=tutorial-sql-instance \
        --db_name=tutorialdb \
        --db_user=tutorial-user \
        --project_id=[YOUR_PROJECT_ID] \
        --db_password=[YOUR_DATABASE_PASSWORD]

    כאשר:

    • ‫[YOUR_PROJECT_ID] הוא מזהה הפרויקט.
    • הסיסמה למסד הנתונים שלך היא [YOUR_DATABASE_PASSWORD].

    הפרמטר -dir מציין את המיקום של פרויקט WordPress.

  5. הסקריפט המסייע כותב מידע ל-wordpress-project/wordpress/wp-config.php. בודקים את התוכן של wp-config.php כדי לוודא שהשמות, מזהה הפרויקט והסיסמה של מסד הנתונים נכונים.

    if ($onGae) {
        /** Production environment */
        define('DB_HOST', ':/cloudsql/[YOUR_PROJECT_ID]:us-central1:tutorial-sql-instance');
        /** The name of the database for WordPress */
        define('DB_NAME', 'tutorialdb');
        /** MySQL database username */
        define('DB_USER', 'tutorial-user');
        /** MySQL database password */
        define('DB_PASSWORD', '[YOUR_DATABASE_PASSWORD]');
    } else {
        /** Local environment */
        define('DB_HOST', '127.0.0.1');
        /** The name of the database for WordPress */
        define('DB_NAME', 'tutorialdb');
        /** MySQL database username */
        define('DB_USER', 'tutorial-user');
        /** MySQL database password */
        define('DB_PASSWORD', '[YOUR_DATABASE_PASSWORD]');
    }

פריסת פרויקט WordPress בסביבה גמישה ב-App Engine

  1. עוברים לספריית הפרויקט של WordPress:

    cd wordpress-project
    
  2. פורסים את הפרויקט ב-WordPress:

    gcloud app deploy \
        --promote --stop-previous-version app.yaml cron.yaml
    
  3. בדפדפן, מזינים את כתובת ה-URL הבאה:

    https://PROJECT_ID.REGION_ID.r.appspot.com

    מחליפים את מה שכתוב בשדות הבאים:

עדכון של WordPress, פלאגינים ועיצובים

חשוב לעדכן את WordPress, את הפלאגינים ואת העיצובים. אפשר להשתמש בכלי wp כדי לעדכן את הפריטים האלה. אחרי עדכון, צריך לפרוס מחדש את פרויקט WordPress.

  1. עדכון של WordPress:

    vendor/bin/wp core update --path=wordpress
    
  2. עדכון פלאגינים:

    vendor/bin/wp plugin update --all --path=wordpress
    # Just in case it updates any of the dropins, copy the files:
    cp wordpress/wp-content/plugins/batcache/advanced-cache.php \
        wordpress/wp-content/plugins/memcached/object-cache.php \
        wordpress/wp-content
    
  3. עדכון עיצובים:

    vendor/bin/wp theme update --all --path=wordpress
    
  4. פורסים את הפרויקט שוב:

    gcloud app deploy \
        --promote --stop-previous-version app.yaml cron.yaml
    

הסרת המשאבים

כדי להימנע מחיובים בחשבון Google Cloud בגלל השימוש במשאבים שנעשה במסגרת המדריך הזה, אפשר למחוק את הפרויקט שמכיל את המשאבים או להשאיר את הפרויקט ולמחוק את המשאבים בנפרד.

מחיקת הפרויקט

הדרך הקלה ביותר לבטל את החיוב היא למחוק את הפרויקט שיצרתם בשביל המדריך הזה.

כדי למחוק את הפרויקט:

  1. במסוף Cloud de Confiance , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  3. כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.

מחיקת גרסאות של האפליקציה שלא מוגדרות כברירת מחדל

אם אתם לא רוצים למחוק את הפרויקט, אתם יכולים למחוק את הגרסאות של האפליקציה שהן לא ברירת המחדל כדי לצמצם את העלויות.

כדי למחוק גרסת אפליקציה:

  1. במסוף Cloud de Confiance , נכנסים לדף Versions של App Engine.

    כניסה לדף Versions

  2. מסמנים את התיבה שלצד גרסת האפליקציה שלא מוגדרת כברירת מחדל ושרוצים למחוק.
  3. כדי למחוק את גרסת האפליקציה, לוחצים על Delete.

מחיקת מכונה של Cloud SQL

כדי למחוק מכונה של Cloud SQL:

  1. נכנסים לדף Instances במסוף Cloud de Confiance .

    כניסה לדף Instances

  2. לוחצים על השם של מכונת ה-SQL שרוצים למחוק.
  3. כדי למחוק את המכונה, לוחצים על Delete ופועלים לפי ההוראות.

המאמרים הבאים