Setting up auto deploy for PHP - php

Good day,
Problem
I have been trying to deploy my local PHP Code that is hosted in GitLab using Google Cloud Platform for my Kubernetes. I have managed to link the project to Kubernetes but I'm failing to deploy it to production as I have little or no knowledge on how to use .yml configs.
Tried Solutions and Code
.gitlab-ci.yml
image: google/cloud-sdk:alpine
deploy_production:
stage: deploy
environment: Production
only:
- master
script:
- echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
- gcloud --quiet --project $PROJECT_ID app deploy app.yaml dispatch.yaml
after_script:
- rm /tmp/$CI_PIPELINE_ID.json
app.yaml
runtime: php73 # Replace with php73 to use the PHP 7.3 runtime
handlers:
# Serve a directory as a static resource.
- url: /stylesheets
static_dir: stylesheets
secure: always
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
# Serve your app through a front controller at index.php or public/index.php.
- url: .*
script: auto
dispatch.yaml
dispatch:
- url: "example.com/*"
service: default
Outcome Trying to achieve
So what I am trying to archive for starters is for production to install PHP with all dependencies, have an app staging, production stage and specifying the domain I want to serve the application at.
Recommendations are highly welcome

Related

Google App Engine problem. URL grouping not working

My app was working fine in php55 using the below app.yaml settings to grouped URLs. E.G. /api/manage, /api/edit, api/user/add should all be forwarded to /api/api.php but stopped working when upgraded to php72.
Fine below the app.yaml conifig for both php55 and php72 for your help.
Configuration for php55
service: default
runtime: php55
handlers:
- url: /api((/$)|(/[^/]+(/$)?)*)
script: /api/api.php
secure: always
Configuration for php72
service: default
runtime: php72
handlers:
- url: /api/(.*?)/(.*)
script: /api/api.php
secure: always
Thanks in advance.
For the 2nd generation runtimes (including PHP 7+) you no longer use the script element to route traffic (documentation). You have to use a language idiomatic web/routing framework (e.g. Flask in Python, a front controller for PHP).

Css not loading in the other folders- PHP- GCP

I've deployed a website on GCP. The homepage is loading with CSS and other static files, But in the inside folders css is not loading(Attached imageshomepage- index.php user/index.php) . Here's my app.yaml code
# Use the PHP 7.3 runtime (BETA) by replacing "php/2" below with "php73"
runtime: php74
# Defaults to "arve-intes pļ" und "serve public/index.php". Can be used to
# serve a custom PHP front controller (e.g. "serve backend/Index.php") or to s run a long-running PHP script as a worker process (e.g. "php worker.php").
#
# Serve your app through a front controller at index.php or public/index.php.
runtime_config:
document_root: .
handlers:
- url: /css
static_dir: css
secure: always
redirect_http_response_code: 301
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg|css|js|map|PNG))$
static_files: \1
upload: .+\.(gif|png|jpg|css|js|map|PNG)$
- url: /.*
script: auto
secure: always
entrypoint:
serve handler.php
env_variables:
#Replace USER, PASSWORD, DATABASE, and CONNECTION NAME with the
#values obtained when configuring your Cloud SQL instance:
CLOUDSQL_USER: root
CLOUDSQL_DB: dbs5349083
CLOUDSQL_PASSMORD: Test#123
CLOUDSQL_DSN: /cloudsql/tactile-timer-340721:us-east1:mysql
# [END gae cloudsql_mysql_eny)

How to create or deploy another service/module (have deployed on default) on GAE [Google App engine] PHP

I have already deployed on Google App Engine default service in PHP, but I need to create another service to enable me redirect to the mobile version of my website from example.com to mobile.example.com.
I read on google docs that you use I AM ADMIN, I have done the suggested method but to no avail.
Please kindly point me to the way. Thanks in advance.
I just figured it out. The solution was in the app.yaml file, add the service:service_name in the app.yaml if it is not created, it would create it automatically.
runtime: php72
runtime_config:
document_root:
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
entrypoint:
serve worker.php
TO
runtime: php72
runtime_config:
document_root:
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
entrypoint:
serve worker.php
service: mobile-frontend

How to configure alias subfolder with Google Cloud Platform App Engine app.yaml?

I'm very new to the Google Cloud Platform App Engine. Managed to serve a static web site on the App Engine. But now, I need to deploy an application that will have static HTML web-site at the root level and a subfolder that will be running a PHP application in that folder.
So the domain.com will serve static HTML web-site and domain.com/blog will serve PHP application.
Folder structure:
[Root]
-index.html
[blog]
-index.php
app.yaml:
runtime: php72 # Replace with php73 to use the PHP 7.3 runtime
handlers:
# Serve a directory as a static resource.
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
secure: always
redirect_http_response_code: 301
# Serve blog
- url: /blog/.*
script: /www/blog/\1
# Blog default
- url: /blog/
script: /www/blog/index.php
Configured app.yaml like that but still getting 404 not found.

Error 400 : PHP 5.4 applications are prevented from being deployed to Google App Engine

This is my app.yaml file:
application: xxxxxxxxxxxxx
version: 1
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /images
static_dir: images
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /libraries
static_dir: libraries
- url: /
script: main.php
# Serve php scripts.
- url: /(.+\.php)$
script: \1
This is the error I get:
Error 400: --- begin server output ---
PHP 5.4 applications are prevented from being deployed to Google App Engine from any version of the SDK, including older ones. If you need to continue to deploy PHP 5.4 applications for compatibility reasons, you can request that your application be whitelisted for PHP 5.4 deployment by visiting http://goo.gl/qjKEuk.
--- end server output ---
Can somebody please tell me why I still get this error after changing runtime from php to php55 in app.yaml?
You need to update your Google App Engine Launcher to 1.9.18 or higher. You can't use php55 with 1.9.17 (and I just updated to 1.9.20 and it is a bit different, uses your browser to log in).
PhpStorm plugin is still not compatible with deploying php55 apps. Deploying through Google App Engine Launcher works fine.

Categories