how to download file from heroku with git - php

How can I download my currently changed file from heroku server?
I built a PHP application that is running on Heroku.
If I use $ git clone git#heroku.com:myappli.git -o heroku then would this upload my original project files from my computer to the Heroku server?
If I use $ heroku git:clone -a myappli then would this download the whole project files to my computer?
How can I download my file (logfilled.txt) from the Heroku server?

Like most PaaS providers, Heroku does not provide a persistent filesystem:
Ephemeral filesystem
Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.
This means that every time you deploy files that you have created or modified will be lost or reverted to the last committed state. It is probably not a great idea to create your own log files on Heroku.
However, Heroku automaticaly logs anything printed to standard out or standard error:
Writing to your log
Anything written to standard out (stdout) or standard error (stderr) is captured into your logs. This means that you can log from anywhere in your application code with a simple output statement.
Logs may be retrieved using the heroku logs command.
Try using PHP's error_log function to write your logs. If you are using a logging library like Monolog you may have to configure it to output to php://stderr instead of to a file.
Finally, you could write to an arbitrary file like logfilled.txt and make that accessible via HTTP, then download it using a regular web browser, wget, curl, or any other tool. Note that you will almost certainly want to build some authentication around this; using Heroku's logging facility is a much better option.

Related

How to set up online directory that two servers can access?

I have a very weird, but specific situation. I use XAMPP localhost on my mac, call it server1, and heroku running a php app, call it server2. I need to move a txt file from server1 to server2 (at regular intervals as the txt constantly updates). I cannot use PHP's ftp as heroku doesn't like that. I have no idea how to do this.
I have come up with a plan to somehow get the txt from server1 to an online 'directory' that the app on server2 can access, but I have no idea how to do this, or if this is even possible? Is there a better way to transfer the file? Should I not be using heroku for this in the first place?
Heroku is great for running PHP apps, but it has an ephemeral filesystem. It's not build to upload files and store them on the "server".
(https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem)
If you deploy a new version of your app to Heroku, the uploaded file will be removed. If you don't mind uploading the file again, simply push it to your PHP app running on Heroku using a POST request.
If you want to save it more reliable, think about using a storage service like AWS S3.

How to run an php application without installing xampp on client system?

In my application i have to deploy my application on client system.
So is there any way to run my php application without installing xampp...
Because the client should access it as a readymade app without installing anything...
This is the description of my project...
We have to develop an application where the client will have our application he will connect to remote server
Then he will download the data from remote server...
Then he uses that downloaded data using that app
Here my requirement is the user may not have the knowledge of installing the xampp...
So is there any way to run the application in user system just by copying some files
U may suggest me a one click solution (like using installer which will include installation of xampp and copying my data into user system)
I really dont want to use any external software to render no database PHP pages so I did some digging and found that if you run php -S localhost:port in your working directory you basically start a server there.
S is a capital S and not s
I'm a big fan of server2go. I've used it to deploy PHP applications on CD/DVD. It comes with MySQL and is relatively easy to configure. I've even replaced their splash screen with my own so no one knows I'm using it. It's donationware, but I was impressed enough to donate:
server2go-web
With this application, you don't have to install all that other stuff. It's self-contained in this executable and directory.
EDIT: To clarify, server2go does not install anything on the client machine. It runs as an exe only when you specifically want it to. When you click on the .exe file, it launches your PHP application in a browser window, then you can right-click on the server2go icon in the system tray and close it when you're done.
EDIT2: One gotcha: if you want to save data to the MySQL db on the client machine, you'll need to copy serve2go to a directory on the client machine or run it on a writable USB stick. If you run this application off CD/DVD, it will be able to read data from the database, but not write.
The better way is to use PHP Desktop Application. It will allow you to run your PHP Script like a Desktop application and you don't need to install Xampp or any other web server to run.
PHP Desktop Application
After downloading the .Zip file unzips it to any folder that you like. After unzipping, Go to the folder, and there you can see a folder "www". Delete all the files contained in it and move all your php script to it.
Once you moved all your files into it. Run the .Exe file named "PHP desktop-chrome"
It will open your PHP Script really like a Desktop Application.
This script doesn't require any kind of server software like Xampp, Wamp, Etc installed in your PC.
You can either host the php application or install the application into one system as server and call in client system using the ip of the server system like the following
http://**ip address/php file name
If you don't want your client to install anything then you should create Client Server architecture, there is no another way.
PHP Application are not meant to be deployed on multiple clients. It's meant to be deployed on a webserver (your own server with sth. like IIS or XAMPP) so the clients can access it via their browser and doesn't have to install anything more.
If you want to deploy applications on the client pc's i recommened an other programming language like Java or C/C++.
I simply used xampp zip version so i copied my application into htdocs and the whole xampp is given to the customer so he simply running the application eazily without installation.
Make sure you have installed php from https://www.php.net/downloads.php. Once installed add it to path. Lastly type php -S localhost:8000
PHP needs to be installed on the machine it is running at in order to make sure it works. Since the app may grow and may require extension installing, PHP upgrading over time, hosting this on a client machine is not a very easy task in terms of management. You may want to host your project on a server and write a small bash script sending requests to the API.
If, for some reason you cannot host this on a server where your clients would send requests via the bash scripts, then you may want to install only PHP. If it does not need to listen to HTTP requests, then you do not need a server, you can just implement the PHP application and create a bash script so the user will be able to run it from the UI of their operating system.
No, you need some kind of server - Wamp, Xampp, etc.
You can host it online, and then he can just browse it from his PC.

Heroku commands inside the app

I have an app on Heroku, using PHP and PostgreSQL. Now I would like to create backup of my database regularly, put it on a folder on the server, or record its S3 urls and download it.
I have been doing research on the topic. It seems that the best is to use pgbackups add-on which I already have and can use on local command line, like: heroku pgbackups:url --app=APP_NAME
I want to automate the process, lets say in a cron job. I see we have workers on Heroku, but I have never used them and this is still a development environment. A free plan does not have workers. Besides, my app doesnt really require background workers. I dont want to buy worker dynos only for automatic database backups. Which way should I go?
If I can create PHP cron jobs on Heroku, then I need to know: How can I run Heroku commands in PHP? I tried exec and passthru, but none of them seems to work on Heroku server. On my localhost, the above command (heroku pgbackups) works pretty well, providing the Heroku toolbelt installed on local server.
For Ruby, they have https://github.com/heroku/ toolkit for server-side commands. But I had no luck in my search for a PHP branch...
The overall purpose is to have the DB backup and store it on the server and download it. (Even though Heroku makes backups itself, we want to see it in our hands :)
How can I make it happen?
Probably the best thing to do is to have a cron job on your backup server to run heroku pgbackups:url and to get a URL to the latest pgbackup, and then download it with curl. Something like this:
curl $(heroku pgbackups:url) > latest_backup
For more info about heroku pgbackups:url, see:
https://devcenter.heroku.com/articles/pgbackups#downloading-a-backup
Doing anything with worker dynos wouldn't really make sense because that wouldn't really help you get the backup to your backup server unless you were downloading and re-uploading it or something. Just running a cron job on your backup server downloading once is a lot more straight forward.

Pull live code from heroku

How do i get the changes from live to my repo? The files running on the heroku app have changed and now if i push these will be overwritten.
I have my php code running on heroku and storing 'database' things in local files.
{
"id":1,
"date":"12/1/2012",
"topImg":"/img/dates/1.jpg"
.....
So these things are stored in a json object then just saved over.
Don't do this!
Local files are your enemy, because Heroku is a cloud application host that runs applications on multiple anonymous load-balanced nodes.
Perhaps you're running a single dyno right now for development purposes, but if you ever want to make your site go live you'll need at least two dynos (because Heroku free tier service is qualitatively different from their non-free tier service, particularly in that they will spin down a free dyno if it is not being used but they will never do that to a non-free dyno). When you have multiple dynos, using local files for anything other than caching will be totally unmanageable.
Even if you somehow stay with one dyno forever, Heroku dynos are not guaranteed to maintain their local storage -- if for instance there is a hardware failure on the machine your dyno is served from, Heroku will not hesitate to spin down your application, deleting all local storage, and spin it up again with just your application code loaded, because it does not expect your application to be using local storage for anything.
There is no one supported method for getting files off of a dyno, because, again, it's never a good idea to store local files on a dyno. However, if you really, really need to do this, you can use heroku run and run one-off commands to, for instance, open up a shell and upload the files somewhere. Again: do not do this for anything serious, because once you have multiple dynos it'll be nearly impossible to manage files on them.
Totaly agree with #Andrew. Prefer to use something as mongoDB database as a service with heroku : https://addons.heroku.com/catalog/mongolab or elasticsearch, if you want to add search function over those documents: https://addons.heroku.com/catalog/searchbox. There are well designed to store json docs and, with those services, you are sure that your data will be persistent no matter your dynos are.
Now, to get back your heroku local files, I would do something like that :
run the heroku bash with heroku run bash
make a scp -pYourPort yourFile(s) userName#yourDestination:/pathToSaveLocaion
logout from your heroku instance
I hope this will help you.

How to package PHP apps so they will work on any user computer?

Is there a way to distribute a PHP program like a desktop app, so that even if the user of the app doesn't have a local server environment setup on there PCs, the app will still work?
I was thinking, if there was some type of portable server environment program which includes PHP/Apache, then we could create a batch file which when clicked would start up apache in the portable program and launch the PHP app in the user's default browser. That way PHP apps could be distributed like desktop apps.
But the question is, is there such a portable server environment program that can be used for this?
Yes, if you google for XAMPP portable, you can find several versions of fully portable, fully functioning xampp servers for the go. You would have to make sure it contains all the security settings and extensions you need.
The file your user launches should be an .html file to be sure it opens in your browser. As you need to point the user to his own localhost to run your app (otherwise PHP won't be executed and he'd see a plain html file), you'd have to create a redirect, possibly using javascript or a simple "click here to start" link.
The XAMPP only provides half of the solution:
In addition to the XAMPP you can use Phar files that give you the ability to package your PHP applications as a unit for installation and/or deployment.
You can configure a separate php file which will handle any database creations and initial configuration which can be set to run on the first time.
For a helpful start guide consider the following link:
http://phpmaster.com/packaging-your-apps-with-phar/
Finally if you want to make it seamless (easier) to the user, consider writing a Batch script which will handle running some of the task required (Such as starting apache and mysql and running run.php). Take note of using relative rather than absolute directories to make script development easier.

Categories