best practices for database connection file PHP and azure - mysql

I have a PHP application I am wanting to deploy to Azure via Github. One of the files is a connection to a MySQL DB, which for obvious reasons, I don't want to have tracked on Github. The issue I am running into is getting connected to the DB, and displaying my webpage properly, because the connect.php file isn't in Github. What is the best way to get that to Azure without going through Github?

In your connect.php file, get your values from an environment variable instead of setting it explicitly. Then, in your Azure portal, go to the web app's Application Settings blade & set your environment variables under the App settings section.

Related

When does the AWS .NET SDK load credential files? Is it on startup or on initializing client or...?

As my title states, we are using the AWS .NET SDK and on our web.config configured a profile that points to a credentials file(see: https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds.html using credentials file) on the disk(so out of the source code). This seems to work fine but we are rotating these keys every x period so we need to change the keys within the file. My question is does de AWS .NET SDK notice that the file is changed and automatically load the new credentials or when does it actually load? In other words, if we change the credentials in this file do we need to do additional steps for the application to actually use them?
What I tried now is start up the application locally, change the credentials to a faulty one and calls are still going thru without a problem. Next, I stopped my application and rebuilded in with the same file having faulty credentials. After doing this the application is still able to make correct calls so I'm wondering how this works as if it is falling back on credentials that did work. Or maybe I just didn't test right.
We are using .net framework 4.6.2 application using the aws sdk version 3.3
Also what i forgot to mention is that for each request we initialize the client like this:
using (AmazonCognitoIdentityProviderClient client = new AmazonCognitoIdentityProviderClient(regionEndpoint))
Short answer is creating a client like that will cause the credentials to be read from the credentials file when the first client is created.
The longer answer is when you create without credentials the client uses the FallbackCredentialsFactory class to find credentials either through the credentials file or environment like EC2 instance metadata. The FallbackCredentialsFactory has a static instance of Amazon.Runtime.CredentialManagement.CredentialProfileStoreChain which is what gets the credentials for a profile.
If you want to something different you could have your code create an instance of CredentialProfileStoreChain before creating a client and use that to get the credentials and pass those credentials into the client.

How to upload a CSV file in a microservice deployed in cloud foundry

I am new to cloud foundry. I am currently working on a requirement where I have to upload a CSV file (via JSP UI) into a service deployed in cloud foundry and persists its data in service.
The issue is from UI, I only get a local path of that CSV file and when I am trying to parse that CSV via this path the file is not recognized. I guess the reason is service is already deployed in CF, so it does not recognize this local machine path.
Can you please let me know how can I parse this CSV file in local machine and where to parse this CSV.
Thanks in Advance!
There is nothing specific to Cloud Foundry about how you would receive an uploaded file in a web application. Since you mentioned using Java, I would suggest checking out this post.
How to upload files to server using JSP/Servlet?
The only thing you need to keep in mind that's specific to Cloud Foundry is that the filesystem in Cloud Foundry is ephemeral. It behaves like a normal filesystem and you can write files to it, however, the lifetime of the filesystem is equal to the lifetime of your application instance. That means restarts, restages or anything else that would cause the application container to be recreated will destroy the file system.
In short, you can use the file system for caching or temporary files but anything that you want to retain should be stored elsewhere.
https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#filesystem

PhpStorm - working on a remote server

I have never used PhpStorm before for remote development because I used to work locally.
I am wondering if there is a method to set PhpStorm to work in such a way so it will be identical, in terms of functionality, to local development?
At least, debugging and jumping to functions/variables declaration across the whole project?
Tried to google it but found nothing. Maybe someone knows?
There are two ways to work with remote server development :
With a physically server
With a Virtual Machine locally
Those 2 ways are identical workflow parameters for working with this.
In PHPStorm the main area for parameters workflow deployement on remote server is : PHPStorm > Settings > Build, Execution, Deployement > Deployement
In this area you config the connection on your remote server (you before must config access on your remote server). SFTP is the best way to use this connection.
Most important to select where you want to send/push your modified code with Root path. Upload manually or use the sync auto functionality of PHPStorm use this parameter.
Mappings tabs is not very important you can keep this without change except for 'Deployement path on server' which just type '/' character if you have selected the good 'Root Path' in tab before.
For starting you can forget the Excluded Paths tab. after if you work on symfony framework you use this to exclude the vendor directory.
Don't forget to set the options 'use as Default' if you want to upload or sync auto more fastly and friendly.
Now you must parameters and config correctly your remote server for server be able to run the code which send it with PHPStorm. Dependly on your framework or other technologies you use.
Finally you have :
PHPStorm config OK for send correctly your modification code (auto or manually)
remote server config OK for executing and running correctly the code you are before sending from PHPStorm to your server remote
WARNING : you never run your website into your local OS.
IMPORTANT : config a web server on your remote server and don't forget to install layer for PHP executing script.

Is using a standalone SQL file risky as opposed to using full MySQL?

On my under development website I am using a standalone SQL database file, users.db, to store user login details.
I am wondering though: Should I be using full MySQL integrated to the server like PHPMyAdmin? Is my current "solution" as risky as I think?
I am handling it this way as it means easy access from a number of utilities, including standalone desktop Python programs, via SQLite3 but is this insecure? The file is in my secured cgi-bin but could someone get their hands on it and just download the whole database?
Any and all advice or clarification appreciated,
Ilmiont
Both SQLite and MySQL store their data in some file(s).
Both are insecure if you allow HTTP users to access these files.
Typically, the default configuration of MySQL puts the database files into a separate, non-public directory, while SQLite has no defaults and allows you to put the file anywhere.
But when you are aware of the possible problem, SQLite is as secure as MySQL.
(Checking is easy; just test if http://www.example.com/cgi-bin/users.db works from the outside.)
First of all, if you're on a linux machine, not sure about windows, you can set users and file permissions who are allowed access to that file, but you should know what you're doing when it comes to permissions. The other thing that you want to make sure of is the file location. Don't place the file in the web root, place it somewhere else not accessible from the web, but accessible to your app.

Make appharbor work with existing mysql server

When I was working on my project (asp.net mvc 3) before uploading it, I needed to make it refer to an already existing mysql database. There was/is no option of moving or cloning that database, and I had to add a block of code to my C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config file for it to be made compatible.
How do I make it work on appharbor without moving my database?
You should be able to use mysqldump to move your data to a database running in the context of the AppHarbor MySQL add-on. Here's a guide.
If your current database is publicly accessible it should also work if you configure your AppHarbor app to use that. If you need to open a firewall, you can find AppHarbor app server IPs here.