|
| 1 | +# Php Mysql example |
| 2 | + |
| 3 | +This example shows you how to develop a small php web application that uses mysql as a database. |
| 4 | + |
| 5 | +# Step 0: Prerequisites |
| 6 | + |
| 7 | +In order to use this example, make sure you have docker installed and a docker registry where you can push to (hub.docker.com, gcr.io etc.). Make sure you are logged in to the registry via `docker login`. |
| 8 | + |
| 9 | +Exchange the image name in `.devspace/config.yaml` under `images.default.name` with the image name you want to use. Do **not** add a tag to this image name, because this will be done at runtime automatically. |
| 10 | + |
| 11 | +## Optional: Use self hosted cluster (minikube, GKS etc.) instead of devspace-cloud |
| 12 | + |
| 13 | +By default, this example will deploy to the devspace-cloud, a free managed kubernetes cluster. If you want to use your own cluster instead of the devspace-cloud as deployment target, make sure `kubectl` is configured correctly to access resources on the cluster. Then just erase the `cluster` section in the `.devspace/config.yaml` and devspace will use your current `kubectl` context as deployment target. |
| 14 | + |
| 15 | +# Step 1: Start the devspace |
| 16 | + |
| 17 | +To deploy the application to the devspace-cloud simply run `devspace up`. The output of the command should look similar to this: |
| 18 | + |
| 19 | +``` |
| 20 | +INFO] Building image 'fabian1991/devspace' with engine 'docker' |
| 21 | +[DONE] √ Authentication successful (hub.docker.com) |
| 22 | +Sending build context to Docker daemon 7.168kB |
| 23 | +Step 1/6 : FROM php:7.1-apache-stretch |
| 24 | + ---> 93e6fb4b13e1 |
| 25 | +Step 2/6 : ENV PORT 80 |
| 26 | + ---> Using cache |
| 27 | + ---> 788a58416826 |
| 28 | +Step 3/6 : EXPOSE 80 |
| 29 | + ---> Using cache |
| 30 | + ---> b01729d4ade9 |
| 31 | +Step 4/6 : RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli |
| 32 | + ---> Running in 1dbd0ba85b71 |
| 33 | +Configuring for: |
| 34 | +PHP Api Version: 20160303 |
| 35 | +Zend Module Api No: 20160303 |
| 36 | +Zend Extension Api No: 320160303 |
| 37 | +[...] |
| 38 | +warning: mysqli (mysqli.so) is already loaded! |
| 39 | +
|
| 40 | + ---> d4942a93c915 |
| 41 | +Step 5/6 : COPY . /var/www/html |
| 42 | + ---> dbb818ed4318 |
| 43 | +Step 6/6 : RUN usermod -u 1000 www-data; a2enmod rewrite; chown -R www-data:www-data /var/www/html |
| 44 | + ---> Running in 1c90fe728588 |
| 45 | +Enabling module rewrite. |
| 46 | +To activate the new configuration, you need to run: |
| 47 | + service apache2 restart |
| 48 | + ---> 99eb800d832d |
| 49 | +Successfully built 99eb800d832d |
| 50 | +Successfully tagged fabian1991/devspace:HKgauKH |
| 51 | +The push refers to repository [docker.io/fabian1991/devspace] |
| 52 | +aff6c1858e21: Pushed |
| 53 | +d1bd441544af: Pushed |
| 54 | +60f45585ecc1: Pushed |
| 55 | +bc0dfe6b56ad: Layer already exists |
| 56 | +f82ba3fb9cea: Layer already exists |
| 57 | +c6a1866bd1a0: Layer already exists |
| 58 | +c9b57a1cfeb1: Layer already exists |
| 59 | +1e97bcb161b3: Layer already exists |
| 60 | +369e6fd590f3: Layer already exists |
| 61 | +1805144065e1: Layer already exists |
| 62 | +b6311cdc5fb6: Layer already exists |
| 63 | +e30181a94bbf: Layer already exists |
| 64 | +481da43a1302: Layer already exists |
| 65 | +a4ace4ed0385: Layer already exists |
| 66 | +fd29e0f8792a: Layer already exists |
| 67 | +687dad24bb36: Layer already exists |
| 68 | +237472299760: Layer already exists |
| 69 | +HKgauKH: digest: sha256:6530af9474b2e9b8b1bfc6986288b4dcd34fca5365ffee60a2f6f63de4327b80 size: 3868 |
| 70 | +[INFO] Image pushed to registry (hub.docker.com) |
| 71 | +[DONE] √ Done building and pushing image 'fabian1991/devspace' |
| 72 | +[INFO] Deploying devspace-default with helm |
| 73 | +[DONE] √ Deployed helm chart (Release revision: 2) |
| 74 | +[DONE] √ Successfully deployed devspace-default |
| 75 | +[DONE] √ Port forwarding started on 3000:80 |
| 76 | +[DONE] √ Sync started on /go-workspace/src/github.com/covexo/devspace/examples/php-mysql-example <-> /var/www/html (Pod: test/devspace-default-55c89799d5-x8rvl) |
| 77 | +root@devspace-default-55c89799d5-x8rvl:/var/www/html# |
| 78 | +``` |
| 79 | + |
| 80 | +The command built your Dockerfile and pushed it to the target docker registry. Afterwards, it created a new kubernetes namespace for you in the devspace-cloud and deployed the `kube/deployment.yaml` to that namespace. It also created a new kubectl context for you. If you want to access kubernetes resources via kubectl in the devspace-cloud you can simply change your kubectl context via `devspace up --switch-context`. Now you can check the running pods via `kubectl get po`. |
| 81 | + |
| 82 | +Furthermore a bi-directional sync was started between the local folder `/go-workspace/src/github.com/covexo/devspace/examples/php-mysql-example` and `/var/www/html` within the docker container. Whenever you change a file in either of those two folders the change will be synchronized. In addition the container port 80 was forwarded to your local port 3000. |
| 83 | + |
| 84 | +# Step 2: Start developing |
| 85 | + |
| 86 | +Navigate in your browser to `localhost:3000` and you should a signin page. If you submit the form, the application will insert a new entry in the `Users` table of the mysql database. Try changing the `index.php` locally and reload the webpage and you should be able to see the changes immediately. |
0 commit comments