<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Development Archives - Chief of Stack</title>
	<atom:link href="https://www.chiefofstack.com/category/php-development/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.chiefofstack.com/category/php-development/</link>
	<description>Full Stack Creative Works by Jay Acab</description>
	<lastBuildDate>Thu, 15 Sep 2022 08:41:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.2</generator>

<image>
	<url>https://www.chiefofstack.com/wp-content/uploads/2020/05/cropped-logo-32x32.jpg</url>
	<title>PHP Development Archives - Chief of Stack</title>
	<link>https://www.chiefofstack.com/category/php-development/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Easily create a local Laravel development environment with Docker in Windows</title>
		<link>https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=easily-create-a-local-laravel-development-environment-with-docker-in-windows</link>
					<comments>https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/#respond</comments>
		
		<dc:creator><![CDATA[Jay Acab]]></dc:creator>
		<pubDate>Fri, 11 Jun 2021 22:00:42 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.chiefofstack.com/?p=2824</guid>

					<description><![CDATA[<p>This article is meant to be a short walkthrough on how to quickly setup a local development environment using Docker, a better alternative to installing a full LAMP stack such as XAMPP on your machine.... </p>
<p class="more"><a class="more-link" href="https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/">Read More</a></p>
<p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/">Easily create a local Laravel development environment with Docker in Windows</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This article is meant to be a short walkthrough on how to quickly setup a local development environment using Docker, a better alternative to installing a full LAMP stack such as XAMPP on your machine. This is not a full tutorial on Docker though, I just find this method works the best for me when developing Laravel apps.</p>



<p>Here&#8217;s the GitHub repo for all the code below, you can clone it for easier deployment. <a href="https://github.com/chiefofstack/docker-boilerplate">https://github.com/chiefofstack/docker-boilerplate</a></p>



<h3>What is Docker and what are we going to create anyway?</h3>



<p><em>&#8220;Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.&#8221;</em><br>&#8211; opensource.com</p>



<figure class="wp-block-image size-large"><img width="1024" height="818" src="https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker.jpg" alt="What is Docker" class="wp-image-2878" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker-300x240.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker-768x614.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker-550x439.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/06/what-is-docker-626x500.jpg 626w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Apps and services like PHP can be packaged and deployed easily.<br>Photo from: <a rel="noreferrer noopener" href="https://www.docker.com/resources/what-container" target="_blank">docker.com</a></figcaption></figure>



<p>In a nutshell, we can think of Docker as a lightweight virtual machine that can be easily deployed across any environment together with all the configurations. This guarantees that your application will run precisely how it&#8217;s intended whether it is in production, staging or in a development environment.</p>



<p>That&#8217;s it, we will create service containers for our entire stack. Let&#8217;s get started!</p>



<h3>Step 1. Install Docker Desktop</h3>



<p>If you are a Windows user, download and install Docker for Windows using this <a href="https://docs.docker.com/docker-for-windows/install/" target="_blank" rel="noreferrer noopener">link</a>. Docker Desktop has a built in tool called <strong>docker-compose</strong> which we will utilize to link our services/containers together.</p>



<p><em>&#8220;Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.&#8221; </em><em><br></em>&#8211; docker.com</p>



<p>Note that you need WSL 2 configured on your Windows machine before you can install this app.</p>



<h3>Step 2:&nbsp; Create individual containers for each of our services</h3>



<p>Cd into your project directory and run the following commands in your terminal (for this example I used /home/myuser/Sites/awesomeproject.com). these are basically all the files/folders that we need:</p>



<pre class="wp-block-code">$ touch docker-compose.yml
$ touch Dockerfile
$ mkdir src
$ mkdir mysql
$ mkdir nginx
$ touch nginx/default.conf</pre>



<p>Your file structure should look like this.</p>



<figure class="wp-container-2 wp-block-gallery-1 wp-block-gallery has-nested-images columns-default is-cropped">
<figure class="wp-block-image size-large"><img data-id="2842"  src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/step-2-file-our-structure.jpg" alt="" class="wp-image-2842"/></figure>
</figure>



<p>Edit docker-compose.yml and define our networks</p>



<pre class="wp-block-code">version: '3'
networks:
    laravel: </pre>



<p>Next we define the services we will use for our stack. For NGINX add the following code, this will make the server accessible through port 1010. We also mapped the configuration file to default.conf file found in our nginx folder.:</p>



<pre class="wp-block-code">services:
    nginx:
        image: nginx:stable-alpine
        container_name: nginx_awesomeproject.com
        ports:
            - "1010:80"
        volumes:
            - ./src:/var/www/html
            - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php
            - mysql
            - phpmyadmin
        networks:
            - laravel</pre>



<p>Then edit nginx/default.conf and add the following code:</p>



<pre class="wp-block-code">server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}</pre>



<p>For PHP edit docker-composer.yml again and add the following code. Like the NGINX service above, we prepend the service name php_ for our container_name, used a unique port 1000 so it doesn’t interfere with other local ports in our system and linked it to our container using the ‘laravel’ network. We also added a custom docker file ‘Dockerfile’:</p>



<pre class="wp-block-code">   php:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: php_awesomeproject.com
        volumes:
            - ./src:/var/www/html
        ports:
            - "1000:9000"
        networks:
            - laravel</pre>



<p>Edit Dockerfile and add the following code, this will install php: 7.4-fpm-alpine and also install php extensions.</p>



<pre class="wp-block-code">FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql</pre>



<p>For MySQL add the following to docker-composer.yml.  Here we defined the MySQL credentials that we will use in our Laravel installation. And just like with the previous two service, we linked them up using the “laravel” network</p>



<pre class="wp-block-code">    mysql:
        image: mysql:5.7.22
        container_name: mysql_awesomeproject.com
        restart: unless-stopped
        tty: true
        ports: 
            - "1306:3306"
        volumes:
            - ./mysql_awesomeproject.com:/var/lib/mysql
        environment:
            MYSQL_DATABASE: homestead
            MYSQL_USER: homestead
            MYSQL_PASSWORD: secret
            MYSQL_ROOT_PASSWORD: secret
            SERVICE_TAGS: dev
            SERVICE_NAME: mysql
        networks:
            - laravel</pre>



<p>There you go, if all you want is a basic LEMP stack you can skip to the next step. But in order to make our dev environment even more complete I recommend you go ahead and install the following tools.</p>



<p>We will configure Artisan, the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application.:</p>



<pre class="wp-block-code">    artisan:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: artisan_awesomeproject.com
        volumes:
            - ./src:/var/www/html
        depends_on:
            - mysql
        working_dir: /var/www/html
        entrypoint: &#91;'/var/www/html/artisan']
        networks:
            - laravel</pre>



<p></p>



<p>We will add Composer, a dependency manager for PHP:</p>



<pre class="wp-block-code">    composer:
        image: composer:latest
        container_name: composer_awesomeproject.com
        volumes:
            - ./src:/var/www/html
        working_dir: /var/www/html
        depends_on:
            - php
        networks:
            - laravel</pre>



<p>Next we add Node Package Manager. NPM is a package manager for JavaScript.</p>



<pre class="wp-block-code">    npm:
        image: node:13.7
        container_name: npm_awesomeproject.com
        volumes:
            - ./src:/var/www/html
        working_dir: /var/www/html
        entrypoint: &#91;'npm']
        networks:
            - laravel</pre>



<p>I also love to use PHPMyAdmin, a free and open source administration tool for MySQL and MariaDB.</p>



<pre class="wp-block-code">    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: phpmyadmin_awesomeproject.com
        restart: always
        depends_on:
            - mysql
        ports:
            - 1011:80
        environment:
            PMA_HOST: mysql
            PMA_USER: root
            PMA_PASSWORD: secret            
            PMA_ARBITRARY: 1
        networks:
            - laravel</pre>



<p>Your docker-compose.yml file should look like this.&nbsp;</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="796" src="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-1024x796.jpg" alt="docker-compose.yml" class="wp-image-2863" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-1024x796.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-300x233.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-768x597.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-1536x1194.jpg 1536w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-1060x824.jpg 1060w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-550x427.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-643x500.jpg 643w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_-1390x1080.jpg 1390w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose.yml_.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>With this file we were able to link our containers using the network &#8220;laravel&#8221;, added volumes to each of our containers and defined the images to be used when we run it later. Those images are available from the Docker library. We were also able to install tools necessary for a better Laravel development experience.</p>



<h3>Step 3: Run the containers and access it locally&nbsp;</h3>



<p>In your terminal run the following in your project folder, this will build and run the containers all in one go. Note that Artisan will fail to run but we will solve that on the next step:</p>



<pre class="wp-block-code">~ docker-compose up -d --build</pre>



<figure class="wp-block-image size-large"><img loading="lazy" width="806" height="453" src="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose-up-d-build.jpg" alt="" class="wp-image-2870" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose-up-d-build.jpg 806w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose-up-d-build-300x169.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose-up-d-build-768x432.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-compose-up-d-build-550x309.jpg 550w" sizes="(max-width: 806px) 100vw, 806px" /></figure>



<p>To test, run this command to list all running containers:</p>



<pre class="wp-block-code">~ docker ps/</pre>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="103" src="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-1024x103.jpg" alt="" class="wp-image-2871" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-1024x103.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-300x30.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-768x77.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-1060x107.jpg 1060w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps-550x55.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/06/docker-ps.jpg 1164w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>You can then check http://localhost:1010 to see if the NGINX server is properly running, right now we don’t have a placeholder index.html there so it will naturally return a 404 error</p>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/nginx-localhost-1010.jpg" alt="" class="wp-image-2840"/></figure>



<p>To be able to see the database go to http://localhost:1011, where you will see PHPMyAdmin</p>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/phpmyadmin-localhost-1010.jpg" alt="" class="wp-image-2841"/></figure>



<p>You can connect to mysql through the terminal as well with this code:</p>



<pre class="wp-block-code">~ docker-compose exec mysql mysql -u root -p</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-exec-mysql.jpg" alt="" class="wp-image-2832"/></figure>



<p>Lastly, you can take the containers down using the following commands:</p>



<pre class="wp-block-code">~ docker-compose down</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-down.jpg" alt="" class="wp-image-2831"/></figure>



<h3>Final Step: Install Laravel and test the tools</h3>



<p>If you’ve gone this far you would’ve encountered an error when we ran the artisan container earlier. It’s because we do not have Laravel installed in the /src folder yet. We will do that now,&nbsp; cd into your /src folder and run the following composer command:</p>



<pre class="wp-block-code">~ composer create-project laravel/laravel .</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-create-project-laravel.jpg" alt="" class="wp-image-2830"/></figure>



<p>Configure the .env file to match the MySQL credentials we defined earlier in docker-compose.yml. Your .env file should look like this.<br></p>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/laravel-env-file.jpg" alt="" class="wp-image-2838"/></figure>



<p>To install a Laravel package using Composer run the following command (we’ll install Socialite for this example):</p>



<pre class="wp-block-code">~ docker-compose run --rm composer require laravel/socialite</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-composer-require-laravel-socialite.jpg" alt="" class="wp-image-2829"/></figure>



<p>Let’s now test how to compile assets:</p>



<pre class="wp-block-code">~ docker-compose run -rm npm run dev</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-run-npm-run-dev.jpg" alt="" class="wp-image-2834"/></figure>



<p>Let’s test Artisan by issuing a migrate command:</p>



<pre class="wp-block-code">~ docker-compose run -rm artisan migrate</pre>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/docker-compose-run-artisan-migrate.jpg" alt="" class="wp-image-2833"/></figure>



<p>Go back to your browser to test the Laravel installation:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="679" src="https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-1024x679.jpg" alt="" class="wp-image-2874" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-1024x679.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-300x199.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-768x509.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-1060x703.jpg 1060w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-550x365.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete-754x500.jpg 754w, https://www.chiefofstack.com/wp-content/uploads/2021/06/laravel-installation-complete.jpg 1235w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3>Bonus Step:</h3>



<p>I edited my Linux .bashrc file and added &#8220;dcr&#8221; as an alias for &#8220;docker-compose run -rm&#8221; command.</p>



<figure class="wp-block-image size-large"><img src="https://www.chiefofstack.com/public_html/wp-content/uploads/2021/06/edit-bashrc-file-add-docker-compose-alias.jpg" alt="" class="wp-image-2837"/></figure>



<p>This will make it easier to run the tools using the following shorthand &#8220;dcr npm run dev&#8221;, &#8220;dcr artisan migrate&#8221;, “dcr composer install”.&nbsp;</p>



<p>SOURCES:<br><a href="https://opensource.com/resources/what-docker" target="_blank" rel="noreferrer noopener">https://opensource.com/resources/what-docker</a><br><a href="https://docs.docker.com/compose/" target="_blank" rel="noreferrer noopener">https://docs.docker.com/compose/</a></p>
<p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/">Easily create a local Laravel development environment with Docker in Windows</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chiefofstack.com/2021/06/11/easily-create-a-local-laravel-development-environment-with-docker-in-windows/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Basic AJAX CRUD app using PHP, MySQL and jQuery</title>
		<link>https://www.chiefofstack.com/2021/01/23/basic-ajax-crud-app-using-php-mysql-and-jquery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=basic-ajax-crud-app-using-php-mysql-and-jquery</link>
					<comments>https://www.chiefofstack.com/2021/01/23/basic-ajax-crud-app-using-php-mysql-and-jquery/#comments</comments>
		
		<dc:creator><![CDATA[Jay Acab]]></dc:creator>
		<pubDate>Sat, 23 Jan 2021 23:33:27 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.chiefofstack.com/?p=2797</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2021/01/23/basic-ajax-crud-app-using-php-mysql-and-jquery/">Basic AJAX CRUD app using PHP, MySQL and jQuery</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element " >
		<div class="wpb_wrapper">
			<p>We are going to build a basic AJAX CRUD app from scratch using only PHP, MySQL and jQuery AJAX. CRUD is an acronym for Create, Read, Update, Delete. Basic operations that are at the heart of all web apps.</p>
<p>We will use Bootstrap for the layout and utilize other jQuery plugins for the UI.</p>
<p>But first, the file structure.</p>
<p><strong>/db</strong> &#8211; The directory that has all the server and database related files </p>
<ol>
<li><strong>env.php</strong> &#8211; environment settings for database, server and miscellaneous display options</li>
<li><strong>generate-db.php</strong> &#8211; creates a database based on the details set in the env. file</li>
<li><strong>create-table.php</strong> -creates a table based on the details set in the env. file</li>
<li><strong>connect-db.php </strong>&#8211; global include for databases connection</li>
</ol>
<p><strong>/api</strong> &#8211; The directory that has all endpoint related files </p>
<ol>
<li><strong>create.php</strong> &#8211; all the code and mySQL statements for inserting records</li>
<li><strong>delete.php</strong> &#8211; all the code and mySQL statements  for deleting records</li>
<li><strong>index.php</strong> &#8211; all the code and mySQL statements  for showing rows based on the current page</li>
<li><strong>update.php </strong>&#8211; all the code and mySQL statements  for updating records</li>
</ol>
<p><strong>/js/index.js</strong> &#8211; The file that handles all page events </p>
<ol>
<li><strong>displayBookList() </strong>&#8211; displays the initial list of all books with pagination</li>
<li><strong>displayPageEntries() &#8211;</strong> displays books for the current page</li>
<li><strong>refreshList(data) </strong>&#8211;  universal function to refresh the content of the table, takes in data.</li>
<li><strong>View book</strong> &#8211; has all the code to display a record</li>
<li><strong>Create book</strong> &#8211; code to add a new record</li>
<li><strong>Edit book </strong> &#8211; all the code to fill in the edit form with current data</li>
<li><strong>Update book </strong>&#8211; code to update a record</li>
</ol>
<p><strong> /index.php</strong> &#8211; Is the main file that contains all elements, our app will use modal windows to display the forms. </p>
<figure class="wp-block-image size-large"><img loading="lazy" width="298" height="382" class="wp-image-2799" src="https://www.chiefofstack.com/wp-content/uploads/2021/01/file-structure.jpg" alt="" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/01/file-structure.jpg 298w, https://www.chiefofstack.com/wp-content/uploads/2021/01/file-structure-234x300.jpg 234w" sizes="(max-width: 298px) 100vw, 298px" /></figure>
<p>Let&#8217;s start.</p>
<p><strong>Step 1: Take care of the database. </strong>These files are for global use but create-table.php and generate-db.php are used only once.</p>
<p><em>.env.php</em> </p>
<pre class="wp-block-code">&lt;?php
// Database info
$server = "localhost";
$user = "root";
$pass = "";
$db_name = "awesomedb";
$table_name = "books";

// Server URL
$url = "http://localhost/";

$display_rows = 10;

?&gt;</pre>
<p><em>generate-db.php</em> </p>
<pre class="wp-block-code">&lt;?php
include_once("env.php");

// Create connection
$connection = new mysqli($server, $user, $pass);

// Check connection
if ($connection-&gt;connect_error) {
    die("ERROR: Could not connect " . $connection-&gt;connect_error);
}

// Create new database
$sql = "CREATE DATABASE `$db_name`";

if($connection-&gt;query($sql) === TRUE){
    echo "Database created successfully";
} else {
    echo "ERROR: Unable to execute $sql. " . $connection-&gt;error;
}

// Close connection
$connection-&gt;close();

?&gt;</pre>
<p><em>create-table.php</em> </p>
<pre class="wp-block-code">&lt;?php
include_once("connect-db.php");

// Create new table
$sql = "CREATE TABLE `$table_name` (
            id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            title VARCHAR(191) NOT NULL,
            author VARCHAR(191) NOT NULL,
            published_date DATE,
            last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            status ENUM('active', 'pending', 'deleted')
        )";

if($connection-&gt;query($sql) === TRUE){
    echo "Table '".$table_name."' created successfully";
} else {
    echo "Error creating table: " . $connection-&gt;error;
}
 
// Close connection
$connection-&gt;close();

?&gt;</pre>
<p><em>connect-db.php</em> </p>
<pre class="wp-block-code">&lt;?php
include_once("env.php");

// Create connection
$connection = new mysqli($server, $user, $pass, $db_name);

// Check connection
if ($connection-&gt;connect_error) {
    die("ERROR: Could not connect " . $connection-&gt;connect_error);
}
 

?&gt;</pre>
<p><strong>Step 2: Prepare the endpoints. </strong>These files run the mySQL queries for the operations. This is where the magic actually happens.</p>
<p><em>create.php</em> </p>
<pre class="wp-block-code">&lt;?php
require_once('../db/connect-db.php');

// Add new record
$sql = "INSERT INTO `$table_name` ( `title`, `author`, `published_date`) VALUES ( '".$_POST['title']."', '".$_POST['author']."', '".$_POST['published_date']."')";
$result = $connection-&gt;query($sql);

// Return value
$sql = "SELECT * FROM $table_name ORDER BY id DESC LIMIT 1";
$result = $connection-&gt;query($sql);
$data = $result-&gt;fetch_assoc();
echo json_encode($data);
?&gt;</pre>
<p><em>index.php</em> </p>
<pre class="wp-block-code">&lt;?php
require_once('../db/connect-db.php');
 
$page = (isset($_GET["page"])) ? $_GET["page"] : 1;
$start_from = ($page-1) * $display_rows;

// Get all rows for selected page
$sql = "SELECT * FROM $table_name ORDER BY id DESC LIMIT $start_from, $display_rows";
$result = $connection-&gt;query($sql);
while($row = $result-&gt;fetch_assoc()){
    $json[] = $row;
}
$data['data'] = $json;

// Get total count of all books
$sql = "SELECT COUNT(*) AS total FROM $table_name";
$result = $connection-&gt;query($sql);
$values = mysqli_fetch_assoc($result);
$data['total'] = $values['total'];

// Return books
echo json_encode($data);
?&gt;
</pre>
<p><em>update.php</em> </p>
<pre class="wp-block-code">&lt;?php
require_once('../db/connect-db.php');

// Update record
$sql = "UPDATE `$table_name` SET `title` = '".$_POST['title']."', `author` = '".$_POST['author']."', `published_date` = '".$_POST['published_date']."' WHERE `id` = ".$_POST['id']."";
$result = $connection-&gt;query($sql);

// Return value
$sql = "SELECT * FROM $table_name WHERE `id` = '".$_POST['id']."'";
$result = $connection-&gt;query($sql);
$data = $result-&gt;fetch_assoc();
echo json_encode($data);
?&gt;</pre>
<p><em>delete.php</em> </p>
<pre class="wp-block-code">&lt;?php
require_once('../db/connect-db.php');
$id  = $_POST["id"];

// Delete record
$sql = "DELETE FROM $table_name WHERE id = '".$id."'";

if($connection-&gt;query($sql) === TRUE){
    echo json_encode([$id]);
} else {
    echo "Error deleting record " . $connection-&gt;error;
}

// Close connection
$connection-&gt;close(); 
?&gt;</pre>
<p><strong>Step 3: Design the user interface. </strong>Page elements like lists, pagination, buttons and modal windows allows for user interaction. We used a few jQuery plugins to improve  the UI like twbsPagination, bootstrap-validator, jQueryUI and toast to display notifications </p>
<figure class="wp-block-image size-large"><img loading="lazy" width="1190" height="759" class="wp-image-2806" src="https://i1.wp.com/www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1.jpg?fit=710%2C453&amp;ssl=1" alt="" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1.jpg 1190w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-300x191.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-1024x653.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-768x490.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-1060x676.jpg 1060w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-550x351.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/01/deleted-1-784x500.jpg 784w" sizes="(max-width: 1190px) 100vw, 1190px" /></figure>
<figure class="wp-block-image size-large"><img loading="lazy" width="1184" height="777" class="wp-image-2807" src="https://i1.wp.com/www.chiefofstack.com/wp-content/uploads/2021/01/edit-1.jpg?fit=710%2C466&amp;ssl=1" alt="" srcset="https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1.jpg 1184w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-300x197.jpg 300w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-1024x672.jpg 1024w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-768x504.jpg 768w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-1060x696.jpg 1060w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-550x362.jpg 550w, https://www.chiefofstack.com/wp-content/uploads/2021/01/edit-1-762x500.jpg 762w" sizes="(max-width: 1184px) 100vw, 1184px" /></figure>
<p><em>index.php</em> </p>
<pre class="wp-block-code">&lt;?php require_once("db/env.php"); ?&gt;
&lt;!doctype html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;!-- Meta tags --&gt;
        &lt;meta charset="utf-8"&gt;
        &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;

        &lt;!-- CSS --&gt;
        &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"&gt;
        &lt;link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"&gt;

        &lt;!-- JS --&gt;
        &lt;script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"&gt;&lt;/script&gt;
        &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
        &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"&gt;&lt;/script&gt;
        &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/twbs-pagination/1.4.2/jquery.twbsPagination.min.js" integrity="sha512-frFP3ZxLshB4CErXkPVEXnd5ingvYYtYhE5qllGdZmcOlRKNEPbufyupfdSTNmoF5ICaQNO6SenXzOZvoGkiIA==" crossorigin="anonymous"&gt;&lt;/script&gt;
        &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"&gt;&lt;/script&gt;
	    &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"&gt;&lt;/script&gt;
        &lt;link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet"&gt;

        &lt;!-- Custom JS  --&gt;
        &lt;script type="text/javascript"&gt;
            var url = "&lt;?php echo $url; ?&gt;";
            var display_rows = "&lt;?php echo $display_rows; ?&gt;";

            $(function(){
                $("#published_date").datepicker({ dateFormat: 'yy-mm-dd' });
                $("#published_date_edit").datepicker({ dateFormat: 'yy-mm-dd' });
            });
        &lt;/script&gt;

        &lt;!-- API JS files --&gt;
        &lt;script src="js/index.js"&gt;&lt;/script&gt;

        &lt;title&gt;Trial Project for Worker Bee TV - Submitted by Jay Acab chiefofstack.com &lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class="container"&gt;
            &lt;div class="row mt-4"&gt;
    		    &lt;div class="col-lg-12"&gt;
    		        &lt;div class="float-left"&gt;
    		            &lt;h2&gt;Books&lt;/h2&gt;
    		        &lt;/div&gt;
    		        &lt;div class="float-right"&gt;
        				&lt;button type="button" class="btn btn-success" data-toggle="modal" data-target="#create-book"&gt;
        					Add New Book
        				&lt;/button&gt;
    		        &lt;/div&gt;
    		    &lt;/div&gt;
    		&lt;/div&gt;

    		&lt;table class="table table-bordered table-striped text-muted text-center mt-3"&gt;
    			&lt;thead&gt;
    			    &lt;tr&gt;
        				&lt;th&gt;Date Published&lt;/th&gt;
        				&lt;th&gt;Author name&lt;/th&gt;
                        &lt;th&gt;Book Title&lt;/th&gt;
        				&lt;th&gt;Action&lt;/th&gt;
    			    &lt;/tr&gt;
    			&lt;/thead&gt;
    			&lt;tbody&gt;
    			&lt;/tbody&gt;
    		&lt;/table&gt;

    		&lt;ul id="pagination" class="pagination-sm"&gt;&lt;/ul&gt;
        &lt;/div&gt;

        &lt;!-- View Book Modal --&gt;
        &lt;div id="view-book" class="modal"  tabindex="-1" role="dialog" aria-labelledby="modalLabel"&gt;
            &lt;div class="modal-dialog" role="document"&gt;
                &lt;div class="modal-content"&gt;
                    &lt;div class="modal-header"&gt;
                        &lt;div&gt;
                            &lt;h4 class="modal-title float-left" id="modalLabel"&gt;Book Information&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div&gt;
                            &lt;button type="button" class="close float-right" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;×&lt;/span&gt;&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="modal-body"&gt;
                        &lt;form id="view-book-form" data-toggle="validator" action="api/create.php" method="POST"&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="title"&gt;Title:&lt;/label&gt;
                                &lt;p id="title_view" name="title" class="font-weight-bold" /&gt;&lt;/p&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="author"&gt;Author:&lt;/label&gt;
                                &lt;p id="author_view" name="author"  class="font-weight-bold"/&gt;&lt;/p&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="published_date"&gt;Date Published:&lt;/label&gt;
                                &lt;p id="published_date_view" name="published_date" class="font-weight-bold" /&gt;&lt;/p&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="id"&gt;ID:&lt;/label&gt;
                                &lt;p id="id_view" name="id" class="font-weight-bold" /&gt;&lt;/p&gt;
                            &lt;/div&gt;
                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Create Book Modal --&gt;
        &lt;div id="create-book" class="modal"  tabindex="-1" role="dialog" aria-labelledby="modalLabel"&gt;
            &lt;div class="modal-dialog" role="document"&gt;
                &lt;div class="modal-content"&gt;
                    &lt;div class="modal-header"&gt;
                        &lt;div&gt;
                            &lt;h4 class="modal-title float-left" id="modalLabel"&gt;Add a Book&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div&gt;
                            &lt;button type="button" class="close float-right" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;×&lt;/span&gt;&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="modal-body"&gt;
                        &lt;form id="create-book-form" data-toggle="validator" action="api/create.php" method="POST"&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="title"&gt;Title:&lt;/label&gt;
                                &lt;input type="text" id="title" name="title" class="form-control" data-error="Please enter book title." required /&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="author"&gt;Author:&lt;/label&gt;
                                &lt;input type="text" id="author" name="author" class="form-control" data-error="Please enter the name of the author." required&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="published_date"&gt;Date Published:&lt;/label&gt;
                                &lt;input type="text" id="published_date" name="published_date" class="form-control" data-error="Please enter the date when the book was published." required autocomplete="off"&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group mt-4"&gt;
                                &lt;button type="submit" class="btn submit-book btn-success"&gt;Submit&lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- Edit Book Modal --&gt;
        &lt;div id="edit-book" class="modal"  tabindex="-1" role="dialog" aria-labelledby="modalLabel"&gt;
            &lt;div class="modal-dialog" role="document"&gt;
                &lt;div class="modal-content"&gt;
                    &lt;div class="modal-header"&gt;
                        &lt;div&gt;
                            &lt;h4 class="modal-title float-left" id="modalLabel"&gt;Edit Book&lt;/h4&gt;
                        &lt;/div&gt;
                        &lt;div&gt;
                            &lt;button type="button" class="close float-right" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;×&lt;/span&gt;&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="modal-body"&gt;
                        &lt;form id="edit-book-form" data-toggle="validator" action="api/update.php" method="put"&gt;
                            &lt;input type="hidden" id="id" name="id" class="edit-id"&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="title_edit"&gt;Title:&lt;/label&gt;
                                &lt;input type="text" id="title_edit" name="title" class="form-control" data-error="Please enter book title." required /&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="author_edit"&gt;Author:&lt;/label&gt;
                                &lt;input type="text" id="author_edit" name="author" class="form-control" data-error="Please enter the name of the author." required&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group"&gt;
                                &lt;label class="control-label" for="published_date_edit"&gt;Date Published:&lt;/label&gt;
                                &lt;input type="text" id="published_date_edit" name="published_date" class="form-control" data-error="Please enter the date when the book was published." required autocomplete="off"&gt;
                                &lt;div class="help-block with-errors text-danger"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class="form-group mt-4"&gt;
                                &lt;button type="submit" class="btn submit-book-edit btn-success"&gt;Submit&lt;/button&gt;
                            &lt;/div&gt;
                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Step 4: Handle the events. </strong>This file brings your page to life. It connects page events to the endpoints to complete the operation.</p>
<p><em>index.js</em> </p>
<pre class="wp-block-code">$(document).ready(function() {

/* Initialize the index */
var page = 1;
var current_page = 1;
var total_page = 0;
var display = "list";

/* Display Initial List of Books */
if(display=="list")
    displayBookList();
 
/* View book */
$("body").on("click",".view-book",function(){
    var id = $(this).parent("td").data('id');
    var title = $(this).parent("td").prev("td").text();
    var author = $(this).parent("td").prev("td").prev("td").text();
    var published_date = $(this).parent("td").prev("td").prev("td").prev("td").text();
    display = "details";

    $("#id_view").text(id);
    $("#title_view").text(title);
    $("#author_view").text(author);
    $("#published_date_view").text(published_date);
});

/* Create new book */
$('#create-book-form').on('submit', function(e){
    e.preventDefault();
    var form_action = $("#create-book-form").attr("action");
    var title = $("#title").val();
    var author = $("#author").val();
    var published_date = $("#published_date").val();
    display = "create";

    if(title != '' &amp;&amp; author != '' &amp;&amp; published_date !=''){
        $.ajax({
            dataType: 'json',
            type:'POST',
            url: url + form_action,
            data:{
                title:title,
                author:author,
                published_date:published_date
            }
        }).done(function(data){
            // Reset Form
            $("#title").val('');
            $("#author").val('');
            $("#published_date").val('');

            // Display new item on the list
            displayPageEntries();

            // Hide modal
            $("#create-book").modal('hide');
            toastr.success('Item Created Successfully.', 'Success Alert', {timeOut: 5000});
        });
    }else{
        alert('All fields are required. Please make sure you fill out all fields correctly.')
    }
});

/* Edit book */
$("body").on("click",".edit-book",function(){
    var id = $(this).parent("td").data('id');
    var title = $(this).parent("td").prev("td").text();
    var author = $(this).parent("td").prev("td").prev("td").text();
    var published_date = $(this).parent("td").prev("td").prev("td").prev("td").text();
    display = "edit";

    $("#title_edit").val(title);
    $("#author_edit").val(author);
    $("#published_date_edit").val(published_date);
    $("#edit-book-form").find(".edit-id").val(id);
});

/* Update book */
$('#edit-book-form').on('submit', function(e){
    e.preventDefault();

    var form_action = $("#edit-book-form").attr("action");
    var title = $("#title_edit").val();
    var author = $("#author_edit").val();
    var published_date = $("#published_date_edit").val();
    var id = $("#edit-book-form").find(".edit-id").val();


    if(title != '' &amp;&amp; author != '' &amp;&amp; published_date !=''){
        $.ajax({
            dataType: 'json',
            type:'POST',
            url: url + form_action,
            data:{
                id:id,
                title:title,
                author:author,
                published_date:published_date
            }
        }).done(function(data){
            // Reset Form
            $("#title_edit").val('');
            $("#author_edit").val('');
            $("#published_date_edit").val('');

            // Display new item on the list
            displayPageEntries();

            // Hide modal
            $("#edit-book").modal('hide');
            toastr.success('Item Updated Successfully.', 'Success Alert', {timeOut: 5000});
        });
    }else{
        alert('All fields are required. Please make sure you fill out all fields correctly.')
    }

});

/* Delete book */
$("body").on("click",".delete-book",function(){
    var id = $(this).parent("td").data('id');
    $.ajax({
        dataType: 'json',
        type:'POST',
        url: url + 'api/delete.php',
        data:{ id:id }
    }).done(function(data){
        displayPageEntries();
        toastr.success('Item Deleted Successfully.', 'Success Alert', {timeOut: 5000});
    });
});

/* Display initial list of all books with pagination */
function displayBookList() {
    $.ajax({
        dataType: 'json',
        url: url+'api/index.php',
        data: {page:page}
    }).done(function(data){
    	total_page = Math.ceil(data.total/display_rows);
    	current_page = page;
    	refreshList(data.data);


        $('#pagination').twbsPagination({
	        totalPages: total_page,
	        visiblePages: current_page,
	        onPageClick: function (event, pageL) {
	        	page = pageL;

                    displayPageEntries();

	        }
	    });

    });
}

/* Display books for current page*/
function displayPageEntries() {
	$.ajax({
    	dataType: 'json',
    	url: url+'api/index.php',
    	data: {page:page}
	}).done(function(data){
		refreshList(data.data);
	});
}

/* Refresh table list  */
function refreshList(data) {
	var	rows = '';
	$.each(data,function(key,value) {
	  	rows = rows + '&lt;tr&gt;';
	  	rows = rows + '&lt;td&gt;'+value.published_date+'&lt;/td&gt;';
	  	rows = rows + '&lt;td&gt;'+value.author+'&lt;/td&gt;';
        rows = rows + '&lt;td&gt;'+value.title+'&lt;/td&gt;';
	  	rows = rows + '&lt;td data-id="'+value.id+'"&gt;';
        rows = rows + '&lt;button data-toggle="modal" data-target="#view-book" class="btn btn-primary btn-sm view-book"&gt;View Details&lt;/button&gt; ';
        rows = rows + '&lt;button data-toggle="modal" data-target="#edit-book" class="btn btn-primary btn-sm edit-book"&gt;Edit Book&lt;/button&gt; ';
        rows = rows + '&lt;button class="btn btn-danger btn-sm delete-book"&gt;Delete&lt;/button&gt;';
        rows = rows + '&lt;/td&gt;';
	  	rows = rows + '&lt;/tr&gt;';
	});
	$("tbody").html(rows);
}

});</pre>
<p style="text-align: center;"><a class="button" href="http://projects.chiefofstack.com/ajax-crud/" target="_blank" rel="noopener noreferrer">LAUNCH TEST PROJECT</a></p>
<p>I grouped it into 4 basic steps to make the process of building the app more straight forward. On this test project without using a proper MVC framework (using only PHP, mySQL and jQuery) we have completed an AJAX CRUD app complete with notification and pagination.</p>
<p>This is important because there will be times that a programmer will be limited by the technology he can use and that’s when it pays to know the basics. I hope you enjoyed this tutorial, please share it to someone who might need it. Thanks!</p>
<p> </p>

		</div>
	</div>
</div></div></div></div><p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2021/01/23/basic-ajax-crud-app-using-php-mysql-and-jquery/">Basic AJAX CRUD app using PHP, MySQL and jQuery</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chiefofstack.com/2021/01/23/basic-ajax-crud-app-using-php-mysql-and-jquery/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Install PHP 7 and Composer on Windows 10 through  Ubuntu in WSL</title>
		<link>https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl</link>
					<comments>https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/#respond</comments>
		
		<dc:creator><![CDATA[Jay Acab]]></dc:creator>
		<pubDate>Fri, 05 Jun 2020 20:01:15 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.chiefofstack.com/?p=2610</guid>

					<description><![CDATA[<p>A major advantage of using this setup over the more common XAMPP development environment is that with Ubuntu in WSL, the PHP 7 installation will be the 64 bit variant, as opposed to XAMPP where... </p>
<p class="more"><a class="more-link" href="https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/">Read More</a></p>
<p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/">Install PHP 7 and Composer on Windows 10 through  Ubuntu in WSL</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A major advantage of using this setup over the more common XAMPP development environment is that with Ubuntu in WSL, the PHP 7 installation will be the 64 bit variant, as opposed to XAMPP where PHP is only available at x86. Using 64bit PHP means more memory for running composer for big projects. </p>



<p>Recently one of our projects got too big and I encountered memory allocation error when I ran composer update. I did this as a workaround and fortunately there was no more issues after I&#8217;m done </p>



<p>I assume you already have WSL running on your machine, here are the steps I did to install Composer and PHP 7.0.</p>



<h2>Install PHP inside Ubuntu </h2>



<p>First update the package list. </p>



<p><code>$ sudo apt-get update</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i0.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2612" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/Screenshot_1-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>Then just install php 7.0:  </p>



<p><code>$ sudo apt-get install -y php7.0</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i1.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2614" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>It may take a while to setup some stuff&#8230;</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i0.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2615" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-php-7-ubuntu-wsl2-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>If everything goes well PHP 7.0 will be installed. Verify it by simply running:  </p>



<p><code>$ php -v</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i0.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2616" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/check-php-version-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<h2>Install Composer inside Ubuntu </h2>



<p>To install Composer we follow the official instructions <a rel="noreferrer noopener" href="https://getcomposer.org/download/" target="_blank">here</a>. Run the following commands:</p>



<p><code>$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"</code></p>



<pre class="wp-block-preformatted"><code>$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"</code></pre>



<p><code>php composer-setup.php</code></p>



<p><code>$ php -r "unlink('composer-setup.php');"</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i0.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2617" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>Composer is now installed! test it out by running. </p>



<p><code>$ php composer.phar</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i2.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2618" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl3-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>You can optionally add composer to your global path to make to make it easier to use.   </p>



<p><code>sudo mv composer.phar /usr/local/bin/compose</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1048" height="563" src="https://i2.wp.com/www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4.png?fit=710%2C381&amp;ssl=1" alt="" class="wp-image-2620" srcset="https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4.png 1048w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4-300x161.png 300w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4-1024x550.png 1024w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4-768x413.png 768w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4-550x295.png 550w, https://www.chiefofstack.com/wp-content/uploads/2020/06/install-composer-ubuntu-wsl4-931x500.png 931w" sizes="(max-width: 1048px) 100vw, 1048px" /></figure>



<p>Windows Subsystem for Linux was made for developers and offers all the benefits that comes from using a dedicated Linux machine. With WSL you can run your favorite Windows apps and execute Linux commands natively just like how I installed PHP 7 and Composer inside Ubuntu on our Windows 10 PC. </p>



<p></p>
<p>The post <a rel="nofollow" href="https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/">Install PHP 7 and Composer on Windows 10 through  Ubuntu in WSL</a> appeared first on <a rel="nofollow" href="https://www.chiefofstack.com">Chief of Stack</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chiefofstack.com/2020/06/05/install-php-7-and-composer-on-windows-10-through-ubuntu-in-wsl/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
