How to setup "PHP IntelliSense" on Visual studio code with Laradock to use the PHP binary in the laradock_workspace_1 container?
I have tried to start Remote-containers: attach to running container..., then problem is I can´t access my git repo since its mounted on Windows.
In Windows I can´t access the PHP binary in the docker container, is it possible for vs code to access PHP some remote way(without open a new vs code in the container), so it will have all libraries and modules loaded. This is something I need to get PHP IntelliSense working in correct way? Now some of the autocomplete are not working for example all functions related to Eloquent.
I have found this but unfortunately I don´t understand how to get it work:
https://github.com/laradock/laradock/issues/2248
Any other suggestions on how to get autocomplete to work, without install same PHP version in Windows (I don´t want to pollute my system)?
Start with connecting to the Laradock workspace container (Remote-containers) and mount the folder:
/var/www/
This will allow you to access the files outside the container.
Then for PHP IntelliSense you should add this line to the settings file:
{
"php.executablePath": "/usr/local/bin/php"
}
It might be possible to export the port to php-fpm outside the container, but nothing I know how to do. You can also connect to the php-fpm container, but I think the workspace is more practical to connect to.
Related
I put my Symfony project into Docker, using a volume for my code. I want to user a php command (php app/console doctrine:generate:entities MyBundle:MyEntity to be precise).
When I try to use my php command outside docker, where my code is, nothing happen. But when I connect myself into my docker, the php command is running well.
Do you know why my php command is not working outside my docker ?
Thanks :)
Docker contains your PHP image, it is only accessible from your container. If you try to make your order out of your Docker, it will not just find PHP sources because they are containerized
Your Symfony application can find them because you have indicated the way to the sources Dockers, that's all :)
Right now we have a website running on php 5.6 at Azure on a CentOS 7 based operating system.
Every time if we want to do a new code deploy we have to do it using ftp to our server and manually transfer files and folders. This is very error prone and takes us hours of deploying and debugging afterwards every single time.
we develop on our localhost Windows machine using PHP with WAMP. So there's already a discrepancy between our localhost environments and the production environment.
I started reading a lot about docker lately and how it integrates with BitBucket pipelines. So I wanted to make our deployment Flow more streamlined and automatic with BitBucket pipelines.
Before I get to the technical stuff I have already tried, I want to make sure that I have the general picture of steps that need to be done correct.
What I want to achieve is a way for me and my colleague to write our code and push it to our BitBucket repository, from there on the pipeline picks it up, creates a docker container and deploys it (automatically) (is this a good idea, what about active users during a new container deploy?) to our website.
These are the steps I think that need to be done, please correct me where I am wrong:
1) I create a CentOS virtual machine using VirtualBox
on this VM I install docker
I create a dockerfile here where I use the php7.3-apache base image and I will install mysql on top of it as well.
?? Do I need to do extra stuff here like copying of folders with code or is
that done by bitbucket??
Now the problem I encounter is whilst creating this "docker container" for my situation. I realize this is probably a very common use case for Docker, but I've read through thousand of tutorials and watches tons of videos, but I cannot find answers to my most basic questions and I end up being stuck and frustrated for days/weeks.
I've got a fully working website created in CodeIgniter, but for the sake of the question I just want to have a working version of the docker container containing PHP MySQL and Apache.
I've logged into the CentOS VM and performed the following commands:
mkdir dockertest
touch index.html (and i placed some text in here)
touch index.php (and i placed a basic echo "hello world" in here)
touch docker-compose.yml
mkdir .docker
cd .docker
touch Dockerfile
touch vhost.conf
Dockerfile looks like this:
FROM php:7.3.0-apache-stretch
MAINTAINER Dennis
COPY . /srv/app
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data /srv/app && a2enmod rewrite
Then I'm able to build the image using
docker build --file .docker/Dockerfile -t docker-test .
Right now I can run the container with the following command:
docker run --rm -p 8080:80 docker-test
At this point I go to my CentOS VM and I try to do a curl localhost:8080 and I get the following HTML:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access on this server. <br />
</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at localhost Port 8080</address>
</body></html>
So I guess this means that the Apache server is running, but it does not see my index files anywhere.
I am massively overwhelmed by the amount of documentation and tutorials that are available for Docker, but they all seem to be too high level for me or none which targets CentOS 7, PHP, MySQL and Apache combined.
A question that's also bugging me: The advantage of Docker is that it can be deployed to anywhere and the environment is the exact same. This causes no problems like "it works on my localhost". But how does this exactly work, do me and my colleague need to develop our code INSIDE the docker container? How does this even work?
The process should be:
develop: you and your colleages develop code, they push that to a version control system (git on bitbucket/github) -> the code is in one trusted repository
build: you take this code and create a (or multiple) Docker image(s) with it: on the Apache server, you need the HTML, Javascript code. Build a Docker image starting from Apache image, which then has a step to PULL the code from the git repository inside the container. That's your front end server.
For the DB part, you probably want another container, or even use a managed service that handles the migrations/updates for you, so you only need to worry about the data in the database. If you want to have you own container, make sure the data is in a VOLUME that is mounted in the container, but is otherwise stored on a local or network drive, (i.e. NOT inside the container which would get destroyed on any update)
deploy: pull the images from registry of choice, and make sure the containers are connected as needed (i.e. either on the same host and linked, or on different nodes that have access to each other through a private network)
Notes:
Use Docker for Windows rather than virtual machine and installing Docker inside it.
The host doesn't matter, it's the base image in the container that matters whether you deploy on a Ubuntu, CentOS or CoreOS host, the Docker base image is what matters for you to install dependencies and make your code run.
On the build phase, you probably don't want to pull from git inside the image if your project is a private repository, because you would need to have credentials inside the image to do that: rather you either pull the code from git outside the image, and ADD it to the image, or use another (private) container that has the git pull credentials to pull the code, do the build, and dump a build file that you can then ADD to a shippable container.
Imagine that i had created service for uploading kittens pictures and use Docker container on production.
To do it I created Docker image with PHP 5.5 service, mounted "upload" folder of my app from real OS and also mounted folder with source code.
After some time I decided to improve my app, changed source code and now it requires different env from existed in Docker.
For example, now I need PHP 5.6 instead of PHP 5.5
So when I want to change source code of my app, I can do it by switching mounted source code folder with symlinks (or cannot, because Docker will keep socket? If so, how to switch source code? Should I do it right in container without mounting?).
But how can I quickly switch Docker container after switching source code?
Fastest way would be to exec a shell session in the container, update the environment, restart the php service. As you have mounted the source code, no need to switch.
Best way would be to create a docker image with required environment and stop previous container then run the new image mounting appropriate directories.
I deployed a local project using gcloud command since there everything OK. I'm getting a 500 error in the browser, but I still have hundreds of questions. Where's the code? What is doing gcloud behind the scenes when I do a deploy? Why do I see 3 instances when I just deployed just one project?
I did SSH to each of the three compute instances I see and I couldn't find the code. I want to do something very silly and easy, just go to the index.php file and do echo '1';die; to check that's the code I can play with to make my project work on Google Platform.
Because I'm noob on this I won't be able to tweak my project perfectly to work on Google Cloud at first, so it's probably silly but a must!
My current and only config file:
runtime: php
vm: true
runtime_config:
document_root: public
You are using the AppEngine Flexible Environment (what used to be called Managed VMs). This environment uses Docker to build an image out of your application code and run it in a container.
See the Additional Debugging part of the Managed VMs PHP tutorial for more info on how to debug on the machine. After SSHing into an instance, you are on the host machine, but you still need to run additional commands to access the container, which is where your application code is running. The following command will get you on your machine:
sudo docker exec -t -i gaeapp /bin/bash
Once there, you can edit your running application by running the following commands
apt-get update
apt-get install vim # or your editor of choice
vi /app/public/index.php # I am assuming this is where your file is
Yes, you have to install vim on the container because it will not be installed by default, as this is your production image.
Also be sure to check the Logging page in Developer Console, as that is where the 500 error message will be logged, and it's a lot easier than going through these steps!
I play with docker for a while and I wanted to use this to build a PHP development environment.
With PHP I use composer.
Despite my research about using docker to build a devlopmenet environment, I essentially found sample code showing how to run an existing PHP app (but not how to make a development environment)
like : https://github.com/tutumcloud/tutum-docker-php
I don't really understand if I have to run composer inside the container or outside ?
Can you show me some examples where I have my source code in a directory on the host, shared with container via a docker volume and how to use composer with this setup ?
Thanks :)
interesting setup here :
geoffrey.io/a-php-development-environment-with-docker.html
available on github :
https://github.com/ubermuda/docker-symfony