How to integrate Laravel app with Azure Monitor Logs - php

I have Laravel application runs on an azure VM and I would like to send app logs to Azure Monitoring Logs instead of use the traditional log file.
I have checked this documentation https://learn.microsoft.com/en-us/azure/azure-monitor/agents/data-sources-custom-logs but it also depends on custom log file.
Is there any other solutions to send logs directly to azure?

For monitoring application data, we use azure application insights service. However, currently the instrumentation is available only few languages as stated
in this document (https://learn.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks)
Alternatively, you can use Open Telemetry in PHP which is a observability framework – an API, SDK, and tools that are designed to aid in the generation and collection of application telemetry data such as metrics, logs, and traces which is not currently in production.
You can also leverage the below SDK to write your custom log messages to application insights.
https://github.com/Microsoft/ApplicationInsights-PHP
https://github.com/provisions-group/ms-application-insights-laravel

Related

Azure portal Web Service PHP Monitoring

I wrote a simple Application in HTML with a form. I submit the form into a PHP file and insert the data into a database.
I created an App Service on Azure Portal + MySQL database
It took me a while to get the git Pipeline going (So Git - Azure Portal - deploying into a Webservice)
If I submit my form, the data will go to the database just fine.
Now I wanted to extend everything with a monitoring tool. So I tried Application Insights. But unfortunately, that doesn't work. If I understand it correctly it's because of the PHP file or to be exact the Php Stackruntime on Azure.
Is it possible to the monitoring anyway somehow? I only have experience in Php and Html a little bit of Java and Javascript.
Thanks.
I have deployed sample PHP App to Azure App Service.
So I tried Application Insights. But unfortunately, that doesn't work.
I have checked with both PHP 8.0 and 8.1 runtime version. The Application Insights option is disabled for PHP.
Thanks #Dmitry-Matveev for the Application Insights SDK.
Is it possible to the monitoring anyway somehow?
Check the below steps to Monitor Azure PHP App Service.
Way 1:
Check the Logs under Monitoring.
Way 2:
Enable Application logging (File System).
Navigate to the Log stream to check the Live metrics.
Also, we can check the metrics section to monitor the App.

Error logging for PHP API deployed in AWS Ec2

I am using AWS Ec2 instance to place my API written in PHP.Right now i have used Log4PHP for error logging.I want to know any other built in Error Logging facilities available for AWS Ec2.?
Ec2 has nothing to do with your application logs, it's something that totally depends on the application logic. you application write logs and cloud service ship the logs The most common way of writing logs
Push logs to stdout/stderr
Write logs to log file
The first approach is recommended approach in cloud environment plus this is also base on The twelve-factor app
A twelve-factor app never concerns itself with routing or storage of
its output stream. It should not attempt to write to or manage
logfiles. Instead, each running process writes its event stream,
unbuffered, to stdout. During local development, the developer will
view this stream in the foreground of their terminal to observe the
app’s behavior.
XI Logs: Treat logs as event streams
You can use PHP Monolog, which also suggested by AWS PHP logging article
PHP Monolog is a standards-compliant PHP library that enables
developers to send logs to various destination types including,
databases, files, sockets, and different services. Although PHP
Monolog predates the standards for PHP logging defined in PSR-3, it
does implement the PSR-3 interface and standards.
Here is the details article to check about integration of the library with different framework.
Also, rollbar can be considered as suggested in the comment, its environment independent and you use this any platform but its not free and you can trial with limited log stream.

How to view files a php application deployed to google app engine

I have deployed a php application to google app engine. I can access the application using the url: http://project-id.appspot.com. Since, I have integrated log4php in my application, I want to access the log files of the application using putty or winscp(sftp). How can I access the files deployed on the server ?
Thanks
Take a look at "Reading and Writing Application Logs. If you log in the correct manner, logs are viewable in the Cloud Console or by using the gcloud app logs read command.
Yes, we can use Logs PHP API to write and read logs. But I chose to configure log4php to log into the database.
Thanks

Deploying Azure Cloud Service on a Schedule

I want to host an Azure Website and I need to run a PHP script on the site every hour. Usually I would do something like this using cron jobs. Is Azure WebJobs via Azure Scheduler the only option to accomplish this?
Using PHP or a REST API via PHP cURL, how do I create and deploy an Azure cloud service worker role to run some back-end PHP software independent of the website?
How would pricing work for the cloud service? Would I only be paying while it is deployed, or would I be paying when it is created also? E.g. Could I create the service via Azure portal and deploy via PHP to get same pricing with less coding?
How do I stop a cloud service once it is done processing?
You can use the Azure WebJobs under the website as you pointed out. You can also use the Azure scheduler direct and have it fire a call to another website or even an external system somewhere to kick something off. There is also a scheduler in the Azure Marketplace you could look at. Another option is the Azure Automation, which allows you to run a script separate from a web site or other deployment, though is PowerShell.
You can create deployments using the Azure Management REST API. Here is some documentation on how to use the API from PHP. As for running this independent from the website, you'd either need to run this from an external system, or from a VM running within Azure.
You pay for the Cloud Service from time it starts its deployment until the deployment is deleted. You pay only when something is deployed to the Cloud Service. If you create a cloud service via the portal or script, but don't deploy anything, then you aren't charged anything. When you deploy something into the cloud service you will be charged for as long as the deployment is there.
Based on this question I'm assuming you mean the cloud service is some sort of back end processing. You could have the cloud service use the management api to shut itself down, but that would require that the management certificate be deployed with the cloud service, which some people don't like to do for security reasons. Other folks would have the worker roles push messages to an external system, or another service running in Azure, to say that they are done and it would then reach out and shut them down. There are really several options here depending on if you want it all managed in the cloud or have resources elsewhere that would perform the shutdown. The link to the management APIs above will give you "how to" shut them down, but the decision on what does that is really pretty open.

Running PHP on Windows Azure

I have a Windows Azure subscription.
My requirement is to run a PHP script on my server. This PHP script will create a JSON file.
This JSON file will be downloaded by my iOS app. (Some kind of authentication is an added bonus)
How would I go about doing this? Should I create a "Mobile Service" or should I create a "Website" or something else like "Cloud Services"?
As far as I have researched, I think the only way to do this would be the old school website way. Any input on this will be really helpful. Thanks.
Mobile services are great if you want to create a quick CRUD layer for an app with a backend cloud storage such as Azure SQL DB. It also provides support for scheduled tasks and push notification. But for what you're after (producing a JSON file), you may find it easier to go with Azure Web Sites or Azure Cloud Services (PaaS). Azure Web Sites has a model that you'll likely find easier and with the free/shared tiers, provides a lower cost point for many models. If you want something that gives you a bit more control, then Cloud Services might be a good alternative as well. But given the simple example you've provided, you should be able to accomplish this fairly quickly using Web Sites.

Categories