Css not loading in the other folders- PHP- GCP - php

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)

Related

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.

Setting up auto deploy for 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

How should I write my app.yaml for my php app deployed to gcp's app engine?

I'm deploying a php app to GCP's app engine and can't make the app.yaml configuration work.
The app has this directory structure:
index.php
/sistema
/js
/images
/css
index.php
login.php
otherpage.php
...
I'm having problems with the pages that are under the 'sistemas' folder. And also would like to access those pages without the '.php' in the url.
I've tried with many handlers, but none of them worked as I wanted.
runtime: php55
threadsafe: yes
api_version: 1
handlers:
- url: /sistema/css/*
static_dir: sistema/css
- url: /sistema/js/*
static_dir: sistema/js
- url: /sistema/fonts/*
static_dir: sistema/fonts
- url: /sistema/images/*
static_dir: sistema/images
# Serve php scripts.
- url: /(.+\.php)$
script: \1
- url: /
script: index.php

Removing PHP file extension when serving PHP files

I'm trying to remove the file extension in the address from all *.php files in my site. For instance, if a user visits mysite.com/about.php I want the URL to read mysite.com/about.
Here's my app.yaml:
application: mysite
version: 1
runtime: php55
api_version: 1
handlers:
# Static files
- url: /images/*
static_dir: images
- url: /css/*
static_dir: css
- url: /js/*
static_dir: js
# Routing
- url: /services(.*)
script: services.php
- url: /portfolio(.*)
script: portfolio.php
- url: /project(.*)
script: project.php
- url: /about(.*)
script: about.php
- url: /contact(.*)
script: contact.php
- url: /(.*)
script: index.php
How could I achieve this within GAE?
If all you need to do is perform that type of routing, you could use this:
application: mysite
version: 1
runtime: php55
api_version: 1
handlers:
# Static files
- url: /images/*
static_dir: images
- url: /css/*
static_dir: css
- url: /js/*
static_dir: js
# Special case, route requests for the root document
- url: /
script: /index.php
# If the request ends in [something].php, route to that file directly
- url: /(.+\.php)$
script: /\1
# Map all other requests to scripts of the same name
# so that, eg, /thispage (or /thispage/) routes to /thispage.php
- url: /(.*?)/?$
script: /\1.php
NB however that using this method you won't be able to handle 404 errors (although they don't appear to be handled in the app.yaml provided in the question either). Error-handlers in your app.yaml won't work for a 404 because they'll only kick in if they can't match any route you've provided.
So, if you want to handle 404 errors and such, what you should do instead is do the routing from inside a php script, like this:
-url: /(.*)
script: /routes.php
and inside routes.php inspect the $_SERVER['REQUEST_URI'] variable to see what page was requested, and serve the appropriate content accordingly.
edit: thanks to #Avinash Raj for cleaning up the regex Here

Google App Engine .yaml file working locally but not when deployed

My GAE PHP .yaml file works locally but not when deployed. Everything worked fine up until I reorganized the folders my .php scripts were contained in. There is a php folder in the root of the app and the .php further organized into folders.
Current YAML file:
application: raven3mil
version: 1
runtime: php
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /images
static_dir: /static/images
# Serve php scripts.
- url: /(.+\.php)$
script: \1
- url: /.*
script: /login.php
error_handlers:
- file: /errors/404.html
File structure example:
+root
+php
+admin
manageUsers.php
+teacher
lessons.php
+student
schedule.php
dashboard.php
+css
index.css
main.css
+js
+jquery
+bootstrap
login.php
I'm not sure why my YAML file works locally but not deployed. Can anyone give any insight?
If your scripts are using content from static_dir's you need to make sure they are available to the application.
You can achieve that by adding application_readable: true to your js, css and images handlers.
You can read more about it here: https://cloud.google.com/appengine/docs/php/config/appconfig

Categories