How to develop with PhpStorm + Docker? - php

There's a lot info in the internet about docker's base operations: "how to pull image", "how to run/start container", but almost nothing about what to do next with it. How to develop?
For example, I pulled linode/lamp. Simple project is lying in /var/www/example.com/public_html/.
I launch: docker run -p 80:80 -t -i linode/lamp /bin/bash, service apache2 start. Now, in my browser in http://localhost I see an index page of the project.
Now I want to edit/add/delete files in the project. Do this with bash and nano is insane, obviously. Therefore I want to use PhpStorm. And I cannot understand what to do.
What option should I choose to create a project?
Web server is installed locally, source files are located under its document root.
Web server is installed locally, source files are located elsewhere locally.
Web server is on a remote host, files are accessible via network share or mounted drive.
Web server is on a remote host, files are accessible via FTP/SFTP/FTPS.
Source files are in a local directory, no Web server is yet configured.
it the first, then where shoud I get files? If "via FTP/SFTP/FTPS" - how to set up? I don't get it.
I know that PhpStorm has Deployment - Docker settings and I can configure it. That how it looks on my machine:
Docker settings Image
Debug/Run configuration Image
But it only gives an ability to start containers, connect to them via console. Shoulв I use it somehow?
Docker Image
Please, explain me, what should I do? I would like to see the answers for Windows и Linux (if there is a difference, of course)
P.S. I use Docker on Windows. But in Settings it's switched to Linux containers.

Related

Give a client working PHP file that is executable in Windows that also outputs directories and files

I created a PHP script that takes an input of a CSV file through the web browser and outputs a bunch of directories and files according to the CSV file. Now I want to give this to my client as a standalone application without the need to host their own LAMP stack as my client is not technical at all. He just wants it to live natively on their desktop where he can easily click to open it.
I think you can use Docker.
You can make the php script run from docker by creating a folder structure like this:
docker-compose.yml # This file should contain the docker configurations
run-application.bat # This file should run the docker application
app/ # Insert the script and map it inside the docker configuration
once run-application.bat is clicked the script should run docker and create a LAMP server mapped to the client computer local port.
You can also decide to automaticaly open the browser.
Two steps only, 5 minutes. Put EasyPHP (https://www.easyphp.org) on a USB key and put your file in "www". Your client will able to run those file by launching EasyPHP. He can even copy the whole folder on his hard drive. EasyPHP is portable.

How to share code between Docker containers?

I'm pretty new to Docker, and I have this task. I need to write a configuration for creating a container infrastructure to run a PHP application using nginx, PHP-FPM & MySQL. The code for the application is in a tarball on a remote server.
What I did so far:
Created the fully functioning nginx, php and mysql containers.
Downloaded the code manually, extracted it to a host directory and mounted to both nginx and PHP-FPM containers with bind mount.
This setup works, but I don't want to keep the code locally. What I want is to download it during the build step of one of the containers and use it. My first idea is to use a shared volume to store downloaded code and mount this volume both to nginx and PHP-FPM containers. However, if I do it from within one of the Dockerfiles, I don't have access to the mounted volume (volumes are mounted after the container is built). I can do it to the host filesystem, but this doesn't seem right. What is the right way to deal with it?
Actually I found that the data is copied from the container to the volume, so after the container builds, it can be then reused from another container.

A tool to transfer files using SSH in the browser on GCP it's doesn't work for run PHP files

I use a tool to transfer files using SSH in the browser on GCP
(centos7, Apache 2.4.6, php7.3) that copies PHP files
from Windows PC to /var/www/html. When I do this I cannot run my website.
But when I use the command cp to copy those files
I can run the website. Who recognizes this problem, please and can help me?

FTP access inside docker for a PHP envrionnement

I have a web server with multiple PHP website. I push all my updates through FTP.
I intend to move to a more containerized environnement without changing to much of my current basic workflow.
I would like to deploy each of my website in a Docker container. The database for all the website would be in another container.
I will have a Docker as a reverse proxy.
To update my website, i have two ideas :
Set up an FTP access in the container so i can update it directly
Set up a shared directories with the host through volume, so i can set up FTP access from the host.
What do you think of it ?
Thanks for your help
Changing the code inside a running container, or at all, is against docker best practices, as containers are designed to be ephemeral.
A better idea would be to rebuild the image every time you update the code, allowing the containers to stay ephemeral, and making it easier to scale. You could implement this through CI/CD, but that is out of the scope of this question.
If you really want to continue with the idea of ftp still, it's a good idea to have one container with an ftp service in it, and another one with the web server in, as containers should have only one concern.
If your FTP server image is my/ftp-image and your web server is my/web-server-image, then you can start your containers like this:
docker run -itd --name my-web-server -p 80:80 -v files_volume_name_here:/path/to/files/in/container my/web-server-image
docker run -itd --name my-ftp-server [ports for ftp server here] -v files_volume_name_here:/path/to/files/in/container my/ftp-image

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.

Categories