Eleo Nona

Eleo Nona

1574232259

Getting started with Directus 7 and Docker (PHP & MySQL & Nginx)

I recently wanted to try out the very promising Directus 7, a PHP based Headless CMS (Content Management System, headless meaning it creates an API to work with single page apps), without a doubt explained better on the Documentation.

To get started, I went to visit the very well written documentation, which tells that the best way to start is to git clone [https://github.com/directus/directus.git](https://github.com/directus/directus.git) and configure a local Apache Web Server and MySQL database to try it.

Not wanting to install it locally (because… well, who does that anymore? Local environments are the less reproducible things of all, everyone does not have the same OS, OS version, packages installed, etc.), I turned to my best development friend: Docker!

I found that there is an official Docker repository for directus (Yay!), but sadly couldn’t make it work properly, was out of date and just wasn’t easy to use.

I finally decided to write this article to help dear developper friends in this inquiry.

Our goal :

  • Setup a docker PHP container being able to run the latest Directus version
  • Setup a docker container hosting a MySQL DB to use with Directus
  • Making them work together and letting us try it

Requirements to achieve that goal :

TL;DR : You can find the result of this article here , get it and run the Start stuff instructions to try out Directus 7 in Docker 🙂

Setup a docker PHP container being able to run the latest Directus version

I have to say my favorite stack does not include Apache, I way prefer Nginx working with PHP-FPM, so that is what this example with showcase.

First, let’s create a folder for our experiment: mkdir directus-test/

Inside that folder ( cd directus-test/ ), let’s create a Dockerfile and start from an image that’s gonna help us out:

FROM wyveo/nginx-php-fpm:latest

Then, let’s install a very simple NGINX config allowing us to serve the directus code:

COPY default_nginx_conf /etc/nginx/conf.d/default.conf

The default_nginx_conf is the following:

server {
  listen 80;  root /app/public/;
  index index.php index.html index.htm;
  server_name _; 
  location / {
    try_files $uri $uri/ /index.php;
  }
  
  # pass the PHP scripts to FastCGI server 
  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Hence, a very simple NGINX configuration looking for an index.php in the /app/public folder of our container, and forwarding any request to a *.php file to PHP-FPM through a socket ( /run/php/php7.3-fpm.sock ) which is already set up in the container.

We’re just missing the directus code!

Let’s get it from github, as it is advised in the documentation :

git clone https://github.com/directus/directus.git

Let’s build our container!

docker build -t directus_img .

Setup a docker container hosting a MySQL DB to use with Directus

You know what? I feel lazy and would prefer to spend my time trying the damn thing, so let’s just get an image from Docker hub!

For example, the default MySQL image looks nice ! https://hub.docker.com/_/mysql

Making them work together and letting us try it

Let’s run both containers and make sure they can interact with each other thanks to a Docker Network:

docker network create directus_test_network

Then let’s run our PHP container and give it access to the directus code :

docker run -dit --name directus_php --network directus_test_network -p 8000:80 -v "$(pwd)/directus/":/app/ --rm directus_img

In case you are not familiar with docker, the options allow us to:

  • directus_img is the image we built just before, including all we need
  • -d detach the process from the command line, i.e. your bash is not “stuck” in the process
  • -i keeps the shell interactive even if detached, which means you can still interact with the container
  • -t allocates a pseudo-TTY
  • --name names the container so we can find it easily with docker ps later, or to interact with it
  • --network specifies that container should be available in the network created just before
  • -p allows us to bind ports from the container (80 : the default web port) to a port of the host (your machine), here the 8000 , making it possible for you to go to localhost:8000 and see what the container serves on its port 80
  • -v mounting a volume (here: $(pwd)/directus/ , $(pwd) being the current folder) as a folder in the container ( /app/ )
  • --rm Automatically removes the container when it exits

The fact that directus_img is a the very end of the command is NOT because it is linked to --rm , but simply because it is necessary to pass all the options to docker run before specifying which image to run.

Then, let’s run our MySQL container:

docker run -d --name directus_mysql --network directus_test_network -p 3306:3306 -e MYSQL_DATABASE=directus -e MYSQL_ROOT_PASSWORD=root -v data:"$(pwd)/data" --rm mysql:5.7

The only new thing here is the -e option, allowing you to pass an environment variable to the container.

You can see here that we also bind the port 3306 on the host… Why? This allows you to connect you favorite SQL Manager tool (ex: Sequel Pro) to the DB on localhost:3306 and browse your data if need be.

We can see that our containers are running thanks to docker ps , which should give you something like the following:

This is image title

Result of docker ps

You can now go to http://localhost:8000/admin and setup directus :

This is image title

Ready to install!

The first step is to choose your login and password:

Fill the settings for the admin login

Then to specify the database credentials and settings:

This is image title

Fill the database settings

The only parameters to change here are:

  • the host , which is going to be directus_mysql
  • the user and password : root and root

Which is where we see the influence of having the two containers in the same network. Indeed, having them in the same network makes them “aware” of each other, giving access in the MySQL container to the PHP container on the “host name” directus_php and giving the PHP container access to the MySQL one on directus_mysql .

The docker network with default driver actually includes a DNS resolver so the nslookup done to resolve the IP from the hostnames (e.g. directus_mysql) finds the other container within the same subnet based on the same container name.

Submit the login form with the credentials set and BOOM! You’re in!

This is image title

Boom, you’re in!

You can now access the Admin Settings at the bottom left of the screen and get started creating your collections, etc. 🚀

This is image title

Admin settings at the bottom left of the screen

I have to say that after that, Directus gives a great feeling, everything is pretty smooth with a few hiccups, like some buttons not working, but you get it, it’s still a Work in Progress :)

You can find “all of this code” plus a few helpers here if you don’t want to waste your time trying all of that out.

Thank you for reading !

#Docker #Directus #PHP #MySQL #Development

What is GEEK

Buddha Community

Getting started with Directus 7 and Docker (PHP & MySQL & Nginx)
Eleo Nona

Eleo Nona

1574232259

Getting started with Directus 7 and Docker (PHP & MySQL & Nginx)

I recently wanted to try out the very promising Directus 7, a PHP based Headless CMS (Content Management System, headless meaning it creates an API to work with single page apps), without a doubt explained better on the Documentation.

To get started, I went to visit the very well written documentation, which tells that the best way to start is to git clone [https://github.com/directus/directus.git](https://github.com/directus/directus.git) and configure a local Apache Web Server and MySQL database to try it.

Not wanting to install it locally (because… well, who does that anymore? Local environments are the less reproducible things of all, everyone does not have the same OS, OS version, packages installed, etc.), I turned to my best development friend: Docker!

I found that there is an official Docker repository for directus (Yay!), but sadly couldn’t make it work properly, was out of date and just wasn’t easy to use.

I finally decided to write this article to help dear developper friends in this inquiry.

Our goal :

  • Setup a docker PHP container being able to run the latest Directus version
  • Setup a docker container hosting a MySQL DB to use with Directus
  • Making them work together and letting us try it

Requirements to achieve that goal :

TL;DR : You can find the result of this article here , get it and run the Start stuff instructions to try out Directus 7 in Docker 🙂

Setup a docker PHP container being able to run the latest Directus version

I have to say my favorite stack does not include Apache, I way prefer Nginx working with PHP-FPM, so that is what this example with showcase.

First, let’s create a folder for our experiment: mkdir directus-test/

Inside that folder ( cd directus-test/ ), let’s create a Dockerfile and start from an image that’s gonna help us out:

FROM wyveo/nginx-php-fpm:latest

Then, let’s install a very simple NGINX config allowing us to serve the directus code:

COPY default_nginx_conf /etc/nginx/conf.d/default.conf

The default_nginx_conf is the following:

server {
  listen 80;  root /app/public/;
  index index.php index.html index.htm;
  server_name _; 
  location / {
    try_files $uri $uri/ /index.php;
  }
  
  # pass the PHP scripts to FastCGI server 
  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Hence, a very simple NGINX configuration looking for an index.php in the /app/public folder of our container, and forwarding any request to a *.php file to PHP-FPM through a socket ( /run/php/php7.3-fpm.sock ) which is already set up in the container.

We’re just missing the directus code!

Let’s get it from github, as it is advised in the documentation :

git clone https://github.com/directus/directus.git

Let’s build our container!

docker build -t directus_img .

Setup a docker container hosting a MySQL DB to use with Directus

You know what? I feel lazy and would prefer to spend my time trying the damn thing, so let’s just get an image from Docker hub!

For example, the default MySQL image looks nice ! https://hub.docker.com/_/mysql

Making them work together and letting us try it

Let’s run both containers and make sure they can interact with each other thanks to a Docker Network:

docker network create directus_test_network

Then let’s run our PHP container and give it access to the directus code :

docker run -dit --name directus_php --network directus_test_network -p 8000:80 -v "$(pwd)/directus/":/app/ --rm directus_img

In case you are not familiar with docker, the options allow us to:

  • directus_img is the image we built just before, including all we need
  • -d detach the process from the command line, i.e. your bash is not “stuck” in the process
  • -i keeps the shell interactive even if detached, which means you can still interact with the container
  • -t allocates a pseudo-TTY
  • --name names the container so we can find it easily with docker ps later, or to interact with it
  • --network specifies that container should be available in the network created just before
  • -p allows us to bind ports from the container (80 : the default web port) to a port of the host (your machine), here the 8000 , making it possible for you to go to localhost:8000 and see what the container serves on its port 80
  • -v mounting a volume (here: $(pwd)/directus/ , $(pwd) being the current folder) as a folder in the container ( /app/ )
  • --rm Automatically removes the container when it exits

The fact that directus_img is a the very end of the command is NOT because it is linked to --rm , but simply because it is necessary to pass all the options to docker run before specifying which image to run.

Then, let’s run our MySQL container:

docker run -d --name directus_mysql --network directus_test_network -p 3306:3306 -e MYSQL_DATABASE=directus -e MYSQL_ROOT_PASSWORD=root -v data:"$(pwd)/data" --rm mysql:5.7

The only new thing here is the -e option, allowing you to pass an environment variable to the container.

You can see here that we also bind the port 3306 on the host… Why? This allows you to connect you favorite SQL Manager tool (ex: Sequel Pro) to the DB on localhost:3306 and browse your data if need be.

We can see that our containers are running thanks to docker ps , which should give you something like the following:

This is image title

Result of docker ps

You can now go to http://localhost:8000/admin and setup directus :

This is image title

Ready to install!

The first step is to choose your login and password:

Fill the settings for the admin login

Then to specify the database credentials and settings:

This is image title

Fill the database settings

The only parameters to change here are:

  • the host , which is going to be directus_mysql
  • the user and password : root and root

Which is where we see the influence of having the two containers in the same network. Indeed, having them in the same network makes them “aware” of each other, giving access in the MySQL container to the PHP container on the “host name” directus_php and giving the PHP container access to the MySQL one on directus_mysql .

The docker network with default driver actually includes a DNS resolver so the nslookup done to resolve the IP from the hostnames (e.g. directus_mysql) finds the other container within the same subnet based on the same container name.

Submit the login form with the credentials set and BOOM! You’re in!

This is image title

Boom, you’re in!

You can now access the Admin Settings at the bottom left of the screen and get started creating your collections, etc. 🚀

This is image title

Admin settings at the bottom left of the screen

I have to say that after that, Directus gives a great feeling, everything is pretty smooth with a few hiccups, like some buttons not working, but you get it, it’s still a Work in Progress :)

You can find “all of this code” plus a few helpers here if you don’t want to waste your time trying all of that out.

Thank you for reading !

#Docker #Directus #PHP #MySQL #Development

Joe  Hoppe

Joe Hoppe

1595905879

Best MySQL DigitalOcean Performance – ScaleGrid vs. DigitalOcean Managed Databases

HTML to Markdown

MySQL is the all-time number one open source database in the world, and a staple in RDBMS space. DigitalOcean is quickly building its reputation as the developers cloud by providing an affordable, flexible and easy to use cloud platform for developers to work with. MySQL on DigitalOcean is a natural fit, but what’s the best way to deploy your cloud database? In this post, we are going to compare the top two providers, DigitalOcean Managed Databases for MySQL vs. ScaleGrid MySQL hosting on DigitalOcean.

At a glance – TLDR
ScaleGrid Blog - At a glance overview - 1st pointCompare Throughput
ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads. Read now

ScaleGrid Blog - At a glance overview - 2nd pointCompare Latency
On average, ScaleGrid achieves almost 30% lower latency over DigitalOcean for the same deployment configurations. Read now

ScaleGrid Blog - At a glance overview - 3rd pointCompare Pricing
ScaleGrid provides 30% more storage on average vs. DigitalOcean for MySQL at the same affordable price. Read now

MySQL DigitalOcean Performance Benchmark
In this benchmark, we compare equivalent plan sizes between ScaleGrid MySQL on DigitalOcean and DigitalOcean Managed Databases for MySQL. We are going to use a common, popular plan size using the below configurations for this performance benchmark:

Comparison Overview
ScaleGridDigitalOceanInstance TypeMedium: 4 vCPUsMedium: 4 vCPUsMySQL Version8.0.208.0.20RAM8GB8GBSSD140GB115GBDeployment TypeStandaloneStandaloneRegionSF03SF03SupportIncludedBusiness-level support included with account sizes over $500/monthMonthly Price$120$120

As you can see above, ScaleGrid and DigitalOcean offer the same plan configurations across this plan size, apart from SSD where ScaleGrid provides over 20% more storage for the same price.

To ensure the most accurate results in our performance tests, we run the benchmark four times for each comparison to find the average performance across throughput and latency over read-intensive workloads, balanced workloads, and write-intensive workloads.

Throughput
In this benchmark, we measure MySQL throughput in terms of queries per second (QPS) to measure our query efficiency. To quickly summarize the results, we display read-intensive, write-intensive and balanced workload averages below for 150 threads for ScaleGrid vs. DigitalOcean MySQL:

ScaleGrid MySQL vs DigitalOcean Managed Databases - Throughput Performance Graph

For the common 150 thread comparison, ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads.

#cloud #database #developer #digital ocean #mysql #performance #scalegrid #95th percentile latency #balanced workloads #developers cloud #digitalocean droplet #digitalocean managed databases #digitalocean performance #digitalocean pricing #higher throughput #latency benchmark #lower latency #mysql benchmark setup #mysql client threads #mysql configuration #mysql digitalocean #mysql latency #mysql on digitalocean #mysql throughput #performance benchmark #queries per second #read-intensive #scalegrid mysql #scalegrid vs. digitalocean #throughput benchmark #write-intensive

Misael  Stark

Misael Stark

1629190508

Docker Compose To Run Laravel Application Using Nginx, PHP and MySQL

In this article, we are going to use Docker Compose to run our Laravel application using Nginx, PHP, and MySQL. In the end, we will get three separate service containers.

  • An app service container
  • A db service container to run MySQL
  • An nginx service container

#docker #nginx #mysql #laravel #php 

I am Developer

1597487472

Country State City Dropdown list in PHP MySQL PHP

Here, i will show you how to populate country state city in dropdown list in php mysql using ajax.

Country State City Dropdown List in PHP using Ajax

You can use the below given steps to retrieve and display country, state and city in dropdown list in PHP MySQL database using jQuery ajax onchange:

  • Step 1: Create Country State City Table
  • Step 2: Insert Data Into Country State City Table
  • Step 3: Create DB Connection PHP File
  • Step 4: Create Html Form For Display Country, State and City Dropdown
  • Step 5: Get States by Selected Country from MySQL Database in Dropdown List using PHP script
  • Step 6: Get Cities by Selected State from MySQL Database in DropDown List using PHP script

https://www.tutsmake.com/country-state-city-database-in-mysql-php-ajax/

#country state city drop down list in php mysql #country state city database in mysql php #country state city drop down list using ajax in php #country state city drop down list using ajax in php demo #country state city drop down list using ajax php example #country state city drop down list in php mysql ajax

Haylie  Conn

Haylie Conn

1619603280

Creating A Simple PHP-FPM, Nginx and MySQL Application with Docker Compose

You can use example below if you want to create a simple PHP-FPM, Nginx and MySQL application with docker compose.

Structure

api$ tree
.
├── docker
│   ├── nginx
│   │   └── default.conf
│   └── php
│       ├── Dockerfile
│       └── www.conf
├── .env
├── docker-compose.yml
├── index.html
├── index.php
└── connect.php

#docker #linux #nginx #mysql #php-fpm