Monday, 16 May 2022

Building Container for PHP 5.6 and Mysql 5.7

  Docker- Definition

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allows you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way.

Docker Advantages

You will be having projects developed in different PHP versions. Sometimes some of applications you dint want to upgrade but still you need to run on your local. What you will do? suppose you have  projects in php version 5.3. 5.6 and 7.3, 8 , running this simultaneously  in your local server or machine wont be possible as the wamp or xamp wont support it. So if you are running latest version of Wamp and you try to run projects in 5.6, it wont work. This is one of the many use cases of a Docker. You can google it for other advantages.

In this article , I will be giving instructions on how to build a container in PHP 7.3 and Mysql.

First Step is to Install Docker in your computer

Folder Structure




In Our Main Folder , first we have to create a file called docker-compose.yml

in this file we have to define the commands. Commands in the sense, the Docker image to use for PHP and MySQL. means all the configurations which  is needed for the site to work. By adjusting this file, we create containers for each versions. So For latest PHP version copy this code into the file.

version: '3.8'

services:

    php-apache-environment:

        container_name: php-apache2

        build:

            context: ./php

            dockerfile: Dockerfile

        depends_on:

            - db2

        volumes:

            - ./php/src:/var/www/html/

        ports:

            - 8009:80

    db2:

        container_name: db2

        image: mysql:5.7

        restart: always

        environment:

            MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD

            MYSQL_DATABASE: MYSQL_DATABASE

            MYSQL_USER: MYSQL_USER

            MYSQL_PASSWORD: MYSQL_PASSWORD

        ports:

            - "9909:3306"

    phpmyadmin:

        image: phpmyadmin/phpmyadmin

        ports:

             - '8083:80'

        restart: always

        environment:

            PMA_HOST: db2

            UPLOAD_LIMIT: 200M

        depends_on:

                  - db2                

 Here you can see its mentioning the php latest Image.then in the context defining the folder to search for file Docker file. Then you can see it maps the port 8009 for 80. This is because normally the apache opens port 80 for web service. so here it points to 8009. so localhost:8009 will be assigned to this project. Next is it defines the mysql image and naming as a container. Also its providing the username and password for mysql to create. Here also you can see the port 3306 is mapped to 9909. For accessing phpmyadmin, it maps port 80 to 8083. Then in environment we can set the resource limits. Here am setting the upload limit to 200 MB.

Now next step is to create the file Dockerfile inside the php folder as defined in the context attribute.


In the Dockerfile Put contents like this:-

FROM php:5.6-apache

RUN docker-php-ext-install mysql && docker-php-ext-enable mysql

RUN apt-get update && apt-get upgrade -y

RUN a2enmod rewrite


Here You can see its asking for the php:7.3 version image. Then enabling the mysql extension. Iam also enabling the rewrite access so that .htaccess will be working for our project.


Now next step is to put our working files inside the php/src/ folder , so that the scripts starts executing. This path is defined in docker-composer.yml. Its mapping the var/www/html to our specified directory.


Now for testing purpose we can put php info printing code inside the index.php file. So we can check which version of PHP installed in the project.

So our Project scripting is over. lets see how this will work..

Now You have to open the command prompt or terminal and navigate to the project folder.

type docker-compose up command


If its first time, it will create the container for you. It will take some seconds to install all the things.

If you want to rebuild the entire container if you changed some version numbers in the config files.

Then you can use the command docker-compose up --build . This will rebuild the container and will

 start working. Now if you access the url http://localhost:8004 as mentioned in the docker-compose.yml

 file. you can access the site.






So accessing http://localhost:8004, you will get:-






You can see the Php version is 8.0. Here you can put your project files and run using the url.

Now to access PHPmyadmin, go to url: http://localhost:8089






You can login using username:root, password: MYSQL_ROOT_PASSWORD. After login you can see the phpmyadmin dashboard just like default.



You can create database of your wish and import it. Connect it and it will start working. In MYSQL connect settings, you can create your own user and give permission to access the database if you want.

You can create a new db user by following this:-

Click on User accounts Menu


Scroll down list of users, you can see link to create new user


In top of page, give username and a strong password.


Set all the permission.  and create user.


Now when you are defining the connection settings to the site in the host name filed you have to put the db instance name which we defined in docker-composer.yml file and same you can see at hostname of phpmyadmin also.











Now your environment will be ready. You can see your container running in docker dashboard.


Now try this and of you have any queries comment below.

You can access Github code here:- https://github.com/litto/docker-php-56-mysql





Building Docker Container for PHP 7.3 and Mysql

 Docker- Definition

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allows you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way.

Docker Advantages

You will be having projects developed in different PHP versions. Sometimes some of applications you dint want to upgrade but still you need to run on your local. What you will do? suppose you have  projects in php version 5.3. 5.6 and 7.3, 8 , running this simultaneously  in your local server or machine wont be possible as the wamp or xamp wont support it. So if you are running latest version of Wamp and you try to run projects in 5.6, it wont work. This is one of the many use cases of a Docker. You can google it for other advantages.

In this article , I will be giving instructions on how to build a container in PHP 7.3 and Mysql.

First Step is to Install Docker in your computer

Folder Structure




In Our Main Folder , first we have to create a file called docker-compose.yml

in this file we have to define the commands. Commands in the sense, the Docker image to use for PHP and MySQL. means all the configurations which  is needed for the site to work. By adjusting this file, we create containers for each versions. So For latest PHP version copy this code into the file.

version: '3.8'

services:

    php-apache-environment:

        container_name: php-apache3

        build:

            context: ./php

            dockerfile: Dockerfile

        depends_on:

            - db3

        volumes:

            - ./php/src:/var/www/html/

        ports:

            - 8004:80

    db3:

        container_name: db3

        image: mysql:8.0

        restart: always

        environment:

            MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD

            MYSQL_DATABASE: MYSQL_DATABASE

            MYSQL_USER: MYSQL_USER

            MYSQL_PASSWORD: MYSQL_PASSWORD

        ports:

            - "9907:3306"

    phpmyadmin:

        image: phpmyadmin/phpmyadmin

        ports:

             - '8084:80'

        restart: always

        environment:

            PMA_HOST: db3

            UPLOAD_LIMIT: 300M

        depends_on:

                  - db3  

 Here you can see its mentioning the php latest Image.then in the context defining the folder to search for file Docker file. Then you can see it maps the port 8004 for 80. This is because normally the apache opens port 80 for web service. so here it points to 8000. so localhost:8000 will be assigned to this project. Next is it defines the mysql image and naming as a container. Also its providing the username and password for mysql to create. Here also you can see the port 3306 is mapped to 9907. For accessing phpmyadmin, it maps port 80 to 8084. Then in environment we can set the resource limits. Here am setting the upload limit to 300 MB.

Now next step is to create the file Dockerfile inside the php folder as defined in the context attribute.


In the Dockerfile Put contents like this:-

FROM php:7.3-apache

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

RUN apt-get update && apt-get upgrade -y

RUN a2enmod rewrite


Here You can see its asking for the php:7.3 version image. Then enabling the mysqli extension. Iam also enabling the rewrite access so that .htaccess will be working for our project.


Now next step is to put our working files inside the php/src/ folder , so that the scripts starts executing. This path is defined in docker-composer.yml. Its mapping the var/www/html to our specified directory.


Now for testing purpose we can put php info printing code inside the index.php file. So we can check which version of PHP installed in the project.

So our Project scripting is over. lets see how this will work..

Now You have to open the command prompt or terminal and navigate to the project folder.

type docker-compose up command


If its first time, it will create the container for you. It will take some seconds to install all the things.

If you want to rebuild the entire container if you changed some version numbers in the config files.

Then you can use the command docker-compose up --build . This will rebuild the container and will

 start working. Now if you access the url http://localhost:8004 as mentioned in the docker-compose.yml

 file. you can access the site.




So accessing http://localhost:8004, you will get:-




You can see the Php version is 8.0. Here you can put your project files and run using the url.

Now to access PHPmyadmin, go to url: http://localhost:8084




You can login using username:root, password: MYSQL_ROOT_PASSWORD. After login you can see the phpmyadmin dashboard just like default.



You can create database of your wish and import it. Connect it and it will start working. In MYSQL connect settings, you can create your own user and give permission to access the database if you want.

You can create a new db user by following this:-

Click on User accounts Menu


Scroll down list of users, you can see link to create new user


In top of page, give username and a strong password.


Set all the permission.  and create user.


Now when you are defining the connection settings to the site in the host name filed you have to put the db instance name which we defined in docker-composer.yml file and same you can see at hostname of phpmyadmin also.







Now your environment will be ready. You can see your container running in docker dashboard.


Now try this and of you have any queries comment below.

You can access Github code here:- https://github.com/litto/docker-php-73-mysql





Building Docker Container Script For PHP 8.0 and Mysql

Docker- Definition

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allows you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way.

Docker Advantages

You will be having projects developed in different PHP versions. Sometimes some of applications you dint want to upgrade but still you need to run on your local. What you will do? suppose you have  projects in php version 5.3. 5.6 and 7.3, 8 , running this simultaneously  in your local server or machine wont be possible as the wamp or xamp wont support it. So if you are running latest version of Wamp and you try to run projects in 5.6, it wont work. This is one of the many use cases of a Docker. You can google it for other advantages.

In this article , I will be giving instructions on how to build a container in PHP 8 and latest version of Mysql.

First Step is to Install Docker in your computer

Folder Structure


In Our Main Folder , first we have to create a file called docker-compose.yml

in this file we have to define the commands. Commands in the sense, the Docker image to use for PHP and MySQL. means all the configurations which  is needed for the site to work. By adjusting this file, we create containers for each versions. So For latest PHP version copy this code into the file.

version: '3.8'

services:

    php-apache-environment:

        container_name: php-apache

        build:

            context: ./php

            dockerfile: Dockerfile

        depends_on:

            - db

        volumes:

            - ./php/src:/var/www/html/

        ports:

            - 8000:80

    db:

        container_name: db

        image: mysql

        restart: always

        environment:

            MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD

            MYSQL_DATABASE: MYSQL_DATABASE

            MYSQL_USER: MYSQL_USER

            MYSQL_PASSWORD: MYSQL_PASSWORD

        ports:

            - "9906:3306"

    phpmyadmin:

        image: phpmyadmin/phpmyadmin

        ports:

             - '8080:80'

        restart: always

        environment:

            PMA_HOST: db

            UPLOAD_LIMIT: 300M

        depends_on:

                  - db   

 Here you can see its mentioning the php latest Image.then in the context defining the folder to search for file Docker file. Then you can see it maps the port 8000 for 80. This is because normally the apache opens port 80 for web service. so here it points to 8000. so localhost:8000 will be assigned to this project. Next is it defines the mysql image and naming as a container. Also its providing the username and password for mysql to create. Here also you can see the port 3306 is mapped to 9906. For accessing phpmyadmin, it maps port 80 to 8080. Then in environment we can set the resource limits. Here am setting the upload limit to 300 MB.

Now next step is to create the file Dockerfile inside the php folder as defined in the context attribute.


In the Dockerfile Put contents like this:-

FROM php:8.0-apache

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

RUN apt-get update && apt-get upgrade -y

RUN a2enmod rewrite


Here You can see its asking for the php:8.0 version image. Then enabling the mysqli extension. Iam also enabling the rewrite access so that .htaccess will be working for our project.


Now next step is to put our working files inside the php/src/ folder , so that the scripts starts executing. This path is defined in docker-composer.yml. Its mapping the var/www/html to our specified directory.


Now for testing purpose we can put php info printing code inside the index.php file. So we can check which version of PHP installed in the project.

So our Project scripting is over. lets see how this will work..

Now You have to open the command prompt or terminal and navigate to the project folder.

type docker-compose up command


If its first time, it will create the container for you. It will take some seconds to install all the things.

If you want to rebuild the entire container if you changed some version numbers in the config files.

Then you can use the command docker-compose up --build . This will rebuild the container and will

 start working. Now if you access the url http://localhost:8000 as mentioned in the docker-compose.yml

 file. you can access the site.


So accessing http://localhost:8000, you will get:-


You can see the Php version is 8.0. Here you can put your project files and run using the url.

Now to access PHPmyadmin, go to url: http://localhost:8080


You can login using username:root, password: MYSQL_ROOT_PASSWORD. After login you can see the phpmyadmin dashboard just like default.



You can create database of your wish and import it. Connect it and it will start working. In MYSQL connect settings, you can create your own user and give permission to access the database if you want.

You can create a new db user by following this:-

Click on User accounts Menu


Scroll down list of users, you can see link to create new user


In top of page, give username and a strong password.


Set all the permission.  and create user.


Now when you are defining the connection settings to the site in the host name filed you have to put the db instance name which we defined in docker-composer.yml file and same you can see at hostname of phpmyadmin also.



Now your environment will be ready. You can see your container running in docker dashboard.


Now try this and of you have any queries comment below.


You can check Github code here:- https://github.com/litto/docker-php-8-mysql




Monday, 7 February 2022

Publishing your own packages globally to Install via Composer for the Projects Easily

 Version Controlling using Git is now an essential part of the development. But many of people will be unaware of the steps where their publish public repos can be installed via a composer command anywhere without any hassle. For eg: if your repo is located at https://github.com/gitusername/mylib, it can be make in a way for anyone to install in their application by simply typing  

composer require  gitusername/mylib:version

STEPS TO FOLLOW

1) Make sure you have made the package as a public repo in your gitaccount

2) Put readme.md file and try to at least define how to install your package, how to use .etc...

3) Now create composer.json file in the root of the repo

4) In composer.repo, please put the following script and make changes based on your requirement:-

{
"name": "gitusername/packagename",
"description": "Package description",
"type": "library",
"require": {
"php": ">=5.3.6"
},
"autoload": {
"psr-4": {
"Message\\": "src"
}
},
"license": "proprietary",
"minimum-stability": "dev",
"authors": [
{
"name": "Your Name",
"email": "Your Email "
}
]
} If you want to install additional packages along with this package u can mention in require section. for eg:-
"require": {
"phpunit/phpunit": "^6.5",
"squizlabs/php_codesniffer": "^3",
"php-coveralls/php-coveralls": "^2.2"
},

5)Now Put your library files inside src folder

6) Commit Everything and make sure your package is complete. Now in next step we are going to publish for composer installation

7) Now next step is to create a Tag and Release for the package.

8)For Creating tag and Release follow these steps:-

  Go Down your repo, you can see Release option like this:-



After that Click on Create a New Release option, following window will open








Put your version number v1.0 as per your choice, make sure select that create tag on publish 

Now Fill in the title field same version number v1.0








Fill Title, Description and then go down and select publish release






9) After the release is done, next step is we have to register our package to https://packagist.org/

10) Go to https://packagist.org/ and create one account for you

11) Then Click on submit on top






12) Now Copy paste the Public repo URL in this one and submit








13) After this for the repo to get all push changes we have to add a webhook into our Github Repo


14)Go to Settings-> Webhooks in the Github repo













15) Click create Webhook







16)In the Create Webhook Page fill the Url, Secret we get from packagist profile and save it









17) The Payload URL  Can be seen in the Packagist page https://packagist.org/about#how-to-update-packages











Copy this URL and paste in Payload url field in the webhook window


18) Now for getting secret, Go to Packagist profile


After Clicking Show Api token, it will show. Paste same to webhook field and create it


19) Now Final step is, go to the project.. Initiate the composer and type 

composer require  gitusername/packagename:version

Now the package will be installed auto...