במדריך הזה נסביר איך לפרוס אתר קטן של WordPress בסביבה הגמישה של App Engine.
מטרות
- יוצרים מכונה מדור שני של Cloud SQL.
- מגדירים אתר לדוגמה ב-WordPress.
- פורסים את אתר WordPress לדוגמה בסביבה הגמישה של App Engine.
עלויות
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud 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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
התקינו את ה-CLI של Google Cloud.
-
אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
-
כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud 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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
התקינו את ה-CLI של Google Cloud.
-
אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
-
כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:
gcloud init -
כדי ליצור פרטי כניסה:
נכנסים לדף Credentials במסוף Google Cloud .
- לוחצים על Create credentials ובוחרים באפשרות Service account key.
- בוחרים באפשרות חשבון שירות > חשבון השירות של App Engine שמוגדר כברירת מחדל.
- לוחצים על יצירה.
- שומרים את המפתח שהורד במקום מאובטח.
- מתקינים את PHP ואת Composer.
-
מורידים את Cloud SQL Proxy
והופכים אותו לקובץ הפעלה. צריך גם להוסיף את המיקום של קובץ ההפעלה של Cloud SQL Proxy למשתנה הסביבה
PATH. -
מתקינים לקוח MySQL ומוודאים שהמיקום של קובץ ההפעלה
mysqlנמצא במשתנה הסביבהPATH.
יצירה והגדרה של מכונה מדור שני ב-Cloud SQL
יצירת מכונה של Cloud SQL מהדור השני:
gcloud sql instances create tutorial-sql-instance \ --activation-policy=ALWAYS \ --tier=db-n1-standard-1 \ --region=us-central1מגדירים את סיסמת הבסיס למכונה:
gcloud sql users set-password root --instance tutorial-sql-instance \ --password [YOUR_SQL_ROOT_PASSWORD] \ --host %כאשר
[YOUR_SQL_ROOT_PASSWORD]היא סיסמה מאובטחת לבחירתכם.מורידים ומריצים את 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]הוא מזהה הפרויקט. Google Cloud
[PATH_TO_YOUR_SERVICE_ACCOUNT_JSON]הוא הנתיב לקובץ JSON של חשבון השירות שהורדתם קודם.
הפלט הבא מציין ששרת ה-proxy מוכן לחיבורים חדשים:
Listening on 127.0.0.1:3306 for [YOUR_PROJECT_ID]:us-central1:tutorial-sql-instance Ready for new connectionsבחלון טרמינל אחר, יוצרים מסד נתונים חדש ומשתמש:
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
משכפלים את המאגר לדוגמה:
git clone https://github.com/GoogleCloudPlatform/php-docs-samples.gitעוברים לספרייה שמכילה את הקוד לדוגמה:
cd php-docs-samples/appengine/flexible/wordpressיחסי תלות של התקנות:
composer installמריצים את סקריפט העזר:
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]
where:
-
[YOUR_PROJECT_ID]הוא מזהה הפרויקט. -
[YOUR_DATABASE_PASSWORD]היא הסיסמה למסד הנתונים.
הפרמטר
-dirמציין את המיקום של פרויקט WordPress.-
הסקריפט המסייע כותב מידע ל-
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
עוברים לספריית הפרויקט של WordPress:
cd wordpress-projectפורסים את פרויקט WordPress:
gcloud app deploy \ --promote --stop-previous-version app.yaml cron.yamlבדפדפן, מזינים את כתובת ה-URL הבאה:
https://PROJECT_ID.REGION_ID.r.appspot.comמחליפים את מה שכתוב בשדות הבאים:
-
PROJECT_ID: מזהה הפרויקט ב- Google Cloud -
REGION_ID: קוד שמוקצה לאפליקציה על ידי App Engine
-
עדכון של WordPress, פלאגינים ועיצובים
חשוב לעדכן את WordPress, הפלאגינים והעיצובים. אפשר לעדכן את הפריטים האלה באמצעות הכלי wp. אחרי עדכון, צריך לפרוס מחדש את פרויקט WordPress.
עדכון של WordPress עצמה:
vendor/bin/wp core update --path=wordpressעדכון פלאגינים:
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עדכון העיצובים:
vendor/bin/wp theme update --all --path=wordpressפורסים את הפרויקט שוב:
gcloud app deploy \ --promote --stop-previous-version app.yaml cron.yaml
הסרת המשאבים
כדי להימנע מחיובים בחשבון Google Cloud בגלל השימוש במשאבים שנעשה במסגרת המדריך הזה, אפשר למחוק את הפרויקט שמכיל את המשאבים, או להשאיר את הפרויקט ולמחוק את המשאבים בנפרד.
מחיקת הפרויקט
הדרך הקלה ביותר לבטל את החיוב היא למחוק את הפרויקט שיצרתם בשביל המדריך הזה.
כדי למחוק את הפרויקט:
- במסוף Google Cloud , נכנסים לדף Manage resources.
- ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
- כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.
מחיקת גרסאות של האפליקציה שלא מוגדרות כברירת מחדל
אם אתם לא רוצים למחוק את הפרויקט, אתם יכולים להקטין את העלויות על ידי מחיקת הגרסאות של האפליקציה שאינן ברירת המחדל.
כדי למחוק גרסת אפליקציה:
- במסוף Google Cloud , נכנסים לדף Versions של App Engine.
- מסמנים את התיבה שלצד גרסת האפליקציה שלא מוגדרת כברירת מחדל ושרוצים למחוק.
- כדי למחוק את גרסת האפליקציה, לוחצים על Delete.
מחיקת המכונה של Cloud SQL
כדי למחוק מכונה של Cloud SQL:
- נכנסים לדף Instances במסוף Google Cloud .
- לוחצים על השם של מכונת ה-SQL שרוצים למחוק.
- כדי למחוק את המכונה, לוחצים על Delete ופועלים לפי ההוראות.
המאמרים הבאים
איך מריצים את אפליקציית הדוגמה של מדף הספרים ב-PHP בסביבה הגמישה של App Engine
איך מריצים את אפליקציית הדוגמה PHP Bookshelf ב-Google Kubernetes Engine
איך מריצים את אפליקציית הדוגמה PHP Bookshelf ב-Compute Engine
כדאי להעמיק את הקריאה ולהכיר דוגמאות לארכיטקטורות, תרשימים ושיטות מומלצות בנושאי Google Cloud. כל אלה זמינים במרכז הארכיטקטורה של Cloud.