<?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 &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sat, 30 Mar 2024 14:05:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to use Docker for WordPress development</title>
		<link>https://codepills.com/how-to-use-docker-for-wordpress-development/</link>
					<comments>https://codepills.com/how-to-use-docker-for-wordpress-development/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 25 Nov 2019 14:12:49 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1036</guid>

					<description><![CDATA[This is a simple tutorial on how to start using Docker for WordPress development. <a href="https://codepills.com/how-to-use-docker-for-wordpress-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article is a simple tutorial on how to start using Docker for WordPress development.</p>
<p><span id="more-1036"></span></p>
<p>In the last couple of months, I had a problem with the XAMPP MySQL database. Without any particular reason, from one day to another, it just failed. XAMPP UI does not show any error.</p>
<p>DB recovery does not help, and it seems that every StackOverflow solution does not work. And digging deeper into the database stack did not bring any working solution.</p>
<p>The only solution which seems to work is to delete the XAMPP entirely and create a fresh new installation. Of course, this is a very tedious and time-consuming solution.</p>
<p>Moreover new MacOS update Catalina just made things worse, and XAMPP MySQL failed instantly. Instead of starting using MAMP, which is just the same way of doing things as XAMPP, I have decided it is the right time to start utilizing the power of Docker for WordPress development.</p>
<h2>Using Docker for WordPress development</h2>
<p>I have decided to create this simple tutorial for WordPress development with Docker for whoever would like to need it. This tutorial is written for macOS/Unix systems based operating systems. However, it is helpful for Windows users as well.</p>
<p>Here is a simple list of steps necessary for starting WordPress development with Docker:</p>
<h2>Step no. 1 &#8211; Install Docker</h2>
<p>Well, of course, the first step is to install Docker itself. I will step over this step while this could be a stand-alone tutorial for that. However, it is super easy, and it can complete even beginner PC user alone.</p>
<h2>Step no. 2 &#8211; Think what do you need for WordPress development</h2>
<p>We will need three containers for WordPress development with Docker. These containers will be:</p>
<ul>
<li>PHP server running WordPress</li>
<li>MySQL or MariaDB database based on your choice</li>
<li>Access to database (over phpMyAdmin GUI)</li>
</ul>
<p>Accessing the database over GUI is optional. Same as selecting the database of your choice. MySQL or MariaDB is up to your preference. So based on what are your needs, you should check the appropriate section in the next step.</p>
<h2>Step no. 2 &#8211; Create docker-compose.yml file</h2>
<p>Create a new directory for a project you want to develop. It will be the location of your choice. This folder should contain single file <code>docker-compose.yml</code>.</p>
<p><b>TIP:</b> There is a nice hack for doing all the steps in one. Just type in your terminal this command <code>mkdir NEW_PROJECT_NAME && cd $_ && touch docker-compose.yml</code> and you will all do this in one line.</p>
<p>Copy code below to <b>docker-compose.yml</b></p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:

  wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
        - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db

  db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_storage:/var/lib/mysql
    ports:
      - 3306:3306
    networks:
      - wp

  phpmyadmin:
    container_name: CUSTOM_PROJECT_NAME_db_gui
    image: phpmyadmin
    restart: always
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
    ports:
      - 8080:80
    networks:
      - wp
    depends_on:
      - db</code></pre>
<p>Let&#8217;s cut down the composer file to pieces and figure out what it does.</p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">version: &#8220;3.1&#8221;</td>
<td>Version of the Compose file format. Version 3 or higher is the most current and recommended to use.</td>
</tr>
<tr>
<td scope="row">networks: wp:</td>
<td>All networks used for the service. We need to create just one custom network for our containers.</td>
</tr>
<tr>
<td scope="row">volumes: db_storage:</td>
<td>All volumes used for the service. We need to create just one custom volume for our containers.</td>
</tr>
<tr>
<td scope="row">services:</td>
<td>All containers used for this service. We need to create just one custom service.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: wordpress</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. To specify custom version of WordPress just add double dot e.g.: wordpress:5.3.0</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; ./:/var/www/html/wp-content</td>
<td>Local folder mapped to container wp-content path. For normal theme or plugin development we do not need to access WordPress core file. <a href="//hub.docker.com/_/wordpress”" rel="”nofollow” noopener" target="”_blank”">Docker WordPress image</a></td>
</tr>
<tr>
<td scope="row">environment:<br />
                WORDPRESS_DB_HOST: db:3306<br />
                WORDPRESS_DB_USER: wordpress<br />
                WORDPRESS_DB_PASSWORD: wordpress<br />
                WORDPRESS_DB_NAME: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 80:80<br />
                &#8211; 443:443</td>
<td>I/O ports for HTTP and HTTPS</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<p><strong>With just a simple change of DB image from MariaDB to MySQL, you can get different database engine according to your needs. Otherwise, everything is the same for both containers.</strong></p>
<pre><code class="language-yml">db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    # image: mysql
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
    volumes:
        - db_storage:/var/lib/mysql
    ports:
        - 3306:3306
    networks:
        - wp
</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: mariadb</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. <a href="//hub.docker.com/_/mariadb/”" rel="”nofollow” noopener" target="”_blank”">Docker MariaDB image</a><br />If you want to MySQL database instead of MariaDB, type just <code><b>image: mysql</b></code> and latest image of MySQL will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; db_storage:/var/lib/mysql</td>
<td>Name volume allow data persistence without bothering where the data are stored.</td>
</tr>
<tr>
<td scope="row">environment:<br />
                MYSQL_ROOT_PASSWORD: password<br />
                MYSQL_DATABASE: wordpress<br />
                MYSQL_USER: wordpress<br />
                MYSQL_PASSWORD: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 3306:3306</td>
<td>Database access ports.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">phpmyadmin:
  container_name: CUSTOM_PROJECT_NAME_db_gui
  image: phpmyadmin
  restart: always
  environment:
    PMA_HOST: db
    MYSQL_ROOT_PASSWORD: password
  ports:
    - 8080:80
  networks:
    - wp
  depends_on:
    - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: phpmyadmin/phpmyadmin</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">  environment:<br />
                PMA_HOST: db<br />
                MYSQL_ROOT_PASSWORD: password</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 8080:80</td>
<td>Connect local 8080 port call to 80 port at Docker service.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<h2>Step no. 3 &#8211; Run Docker with docker-compose up -d</h2>
<p>From now on all will go quickly. Just type <code>docker-compose up -d</code> and after initial download of all dependencies everything goes smoothly. When all your containers will shine as <code>done</code> you are ready to proceed.</p>
<p>If you run <code>docker ps</code>, you should now see three services with the name you defined in the docker-compose.yml file.</p>
<h2>Step no. 4 &#8211; Install WordPress</h2>
<p>You can find the new WordPress installation at <code>http://localhost:8080/</code> address. Just proceed with the installation as usual and create a new WordPress installation in your local directory. From now on, you can access this WordPress installation as usual.</p>
<p>If you want to access database with phpMyAdmin use <code>http://localhost:8080/index.php</code> address. If you do not change password in yaml file, use name:<code>password</code> and password:<code>password</code> as login information.</p>
<p>So remember, to access:</p>
<ul>
<li><code>http://localhost:80/</code> &#8211; WordPress</li>
<li><code>http://localhost:8080/</code> &#8211; phpMyAdmin (name: password, password: password)</li>
</ul>
<h2>Step no. 5 &#8211; Load your Git theme/plugin repository</h2>
<p>Everything works as if you would be developing any other WordPress project now. If you have your project versioned in Git, go to themes or plugin folder and <code>Git clone</code> your project there. Any change made there will reflect as <code>git diff</code> in Git.</p>
<h2>Step no. 6 &#8211; Shutdown the Docker processes when you finished</h2>
<p>Finally, to proceed and stop Docker container lifecycle, you need to learn a few more commands. They are:</p>
<ul>
<li><code>docker-compose up</code> &#8211; run the processes, however they are attached to life of your terminal window. Docker process will be terminated on the terminal window close up.</li>
<li><code>docker-compose up -d</code> &#8211; leaves the processes running without being attached to your terminal window. Use <code>-d</code> as “detach” for Docker to starts the containers in the background and leaving them running, independently on your terminal window life. <a href="//docs.docker.com/compose/reference/up/”" target="”_blank”" rel="”nofollow” noopener">Docker reference for up</a></li>
<li><code>docker-compose stop</code> &#8211; stop the processes</li>
<li><code>docker-compose down</code> &#8211; stop and removes the processes</li>
<li><code>docker-compose rm -v</code> &#8211; docker cleanup</li>
<li><code>CTRL+C</code> &#8211; killing processes, terminal key shortcut</li>
</ul>
<p>I recommend you kill the Docker processes for your theme every time you think you finished the day. It is advice based on experience from life. If you kill the processes the next day, you can be sure they are not working because they are down, but not because something else went wrong. Plus, if you switch often projects as I do, it is good to keep the system utilization low and order everything.</p>
<h2>Known issues</h2>
<p>While dealing with Docker, some things can go wrong. However, we will not go through all of them here. Let&#8217;s take a look only at the most occurring issues.</p>
<h3>Error establishing a database connection</h3>
<p><img fetchpriority="high" decoding="async" src="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png" alt="Error establishing a database connection - WordPress" width="640" height="143" class="size-large wp-image-1150" srcset="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png 1024w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-300x67.png 300w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-768x172.png 768w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1536x343.png 1536w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection.png 1611w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>If you get an error saying <code>Error establishing a database connection</code> check the name interconnecting database credentials and database name between WordPress and database.</p>
<h2>Conclusion</h2>
<p>I hope you liked this simple tutorial explaining how to quickly and effectively set up Docker for WordPress development. If you have any comments or constructive criticism or have other ideas on enhancing this YML file or tutorial, please write me a comment. I will appreciate it.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-use-docker-for-wordpress-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Small ideas &#8211; quick refactoring of legacy code after couple of years</title>
		<link>https://codepills.com/small-ideas-quick-refactoring-of-legacy-code-after-couple-of-years/</link>
					<comments>https://codepills.com/small-ideas-quick-refactoring-of-legacy-code-after-couple-of-years/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Fri, 22 Nov 2019 19:19:09 +0000</pubDate>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1028</guid>

					<description><![CDATA[Recently I have been working on the refactoring of one method when I realized how much I have skilled up as a developer in the last few years.  <a href="https://codepills.com/small-ideas-quick-refactoring-of-legacy-code-after-couple-of-years/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>I have recently been working on a refactoring of a method when I realized how much I have skilled up as a developer in the last few years.</p>
<p><span id="more-1028"></span></p>
<p>Here is a function creating a text snippet describing how to get from the airport to the city, which I wrote approximately three years ago. Immediately I knew how it could be rewritten to a more concise form.</p>
<pre><code class="language-php">public static function howToGetFromCityToAirport(string $airportCode, string $language): string
{
    $title = '';
    $paragraph = '';
    if ($language == 'en') {
        $title = '&lt;h2&gt;How to get on the airport?&lt;/h2&gt;';
        $paragraph = self::cityToAirport($language, $airportCode);
        if (empty($paragraph))
        {
            return '';
        }
    }
    if ($language == 'cz') {
        $title = '&lt;h2&gt;Jak se dostat na letiště?&lt;/h2&gt;';
        $paragraph = self::cityToAirport($language, $airportCode);
        if (empty($paragraph))
        {
            return '';
        }
    }
    if ($language == 'sk') {
        $title = '&lt;h2&gt;Ako sa dostať na letisko?&lt;/h2&gt;';
        $paragraph = self::cityToAirport($language, $airportCode);
        if (empty($paragraph))
        {
            return '';
        }
    }
    return $title . $paragraph;
}</code></pre>
<p>So what I did? I made only few changes:</p>
<ul>
<li>First I extracted the common part and pushed it to <code>$paragraph</code> variable.</li>
<li>Then over ternary decision decided what to return.</li>
<li>If a <code>$paragraph</code> is not zero length then call custom private translation method and build a simple HTML string.</li>
<li>And lastly, I just simplified naming or enforced PHP type safety.</li>
</ul>
<pre><code class="language-php">public static function fromCityToAirport(string $airportCode, string $language): string
{
    $paragraph = self::cityToAirport($language, $airportCode);
    return strlen($paragraph) == 0 ? '' : "&lt;h2&gt;" . self::fromCityToAirport_getTitle($language) . "&lt;/h2&gt;" . $paragraph;
}

private static function fromCityToAirport_getTitle(string $language): string
{
    switch ($language) {
        case 'en':
            return 'How to get on the airport?';
            break;
        case 'cz':
            return 'Jak se dostat na letiště?';
            break;
        case 'sk':
            return 'Ako sa dostať na letisko?';
            break;
    }
}</code></pre>
<p>The result is quite significant. 30 lines of code decreased to 20. Code is not faster. But it is more readable and divided into more cohesive parts reflecting better domain language.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/small-ideas-quick-refactoring-of-legacy-code-after-couple-of-years/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to create a file in a different directory in PHP</title>
		<link>https://codepills.com/how-to-create-a-file-in-a-different-directory-in-php/</link>
					<comments>https://codepills.com/how-to-create-a-file-in-a-different-directory-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Sat, 05 May 2018 12:00:05 +0000</pubDate>
				<category><![CDATA[Language basics]]></category>
		<category><![CDATA[file creation]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://codepills.com/?p=946</guid>

					<description><![CDATA[How to make this file in another folder than the execution file location? This article will help you with a small snippet of code to create a file in a different folder. <a href="https://codepills.com/how-to-create-a-file-in-a-different-directory-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>How to make this file in another folder than the execution file location? This article will help you with a small snippet of code to create a file in a different folder.</p>
<p><span id="more-946"></span></p>
<p>First of lets have a folder structure like this:</p>
<pre><code class="language-bash">root_folder/
root_folder/index.php
root_folder/create/
root_folder/create/page.php</code></pre>
<p>Let&#8217;s imagine I want to create a file in a different folder from the folder of <code><i>php</i></code> execution file.</p>
<p>I am currently in the root folder, executing the <code><i>php</i></code> file in <code>index.php</code>. In this file, I want to run a certain function which will create me a new file in the predefined folder.</p>
<p>If you want to be sure that the folder into which you want to export the file exists, check our recent post about <a href="http://codepills.com/how-to-create-a-folder-in-php-if-it-doesnt-exist/">creating new folders</a>.</p>
<p>Here is a code that will create a new file in a predefined location.</p>
<pre><code class="language-php">$fileContent = 'This is the content in the file.';
$fileName = 'page.txt';
$filePath = './create/'.$fileName;

if (file_put_contents($filePath, $fileContent) !== false) {
    echo "File created (" . basename($filePath) . ").";
} else {
    echo "Cannot create the file (" . basename($filePath) . ").";
}</code></pre>
<h2>Conclusion</h2>
<p>This small article has shown how to create this file in a different folder rather than the execution file location.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-create-a-file-in-a-different-directory-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to create a folder in PHP if it doesn&#8217;t exist</title>
		<link>https://codepills.com/how-to-create-a-folder-in-php-if-it-doesnt-exist/</link>
					<comments>https://codepills.com/how-to-create-a-folder-in-php-if-it-doesnt-exist/#comments</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Fri, 04 May 2018 12:00:18 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[file creation]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://codepills.com/?p=945</guid>

					<description><![CDATA[This article will show you how to create a folder automatically in PHP if it does not exist. <a href="https://codepills.com/how-to-create-a-folder-in-php-if-it-doesnt-exist/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article will show you how to create a folder automatically in PHP if it does not exist. We will see several different approaches to solve this problem in the right way.</p>
<p><span id="more-945"></span></p>
<h2>Creating a new folder in PHP</h2>
<p>The most straightforward solution would be first to ask if the folder exists. If the folder does not exist, then we can create it. However, if it already exists, then we shall do nothing.</p>
<p>Here is a simple example for the custom <code>makeDirectory()</code> function:</p>
<pre><code class="language-php">&lt;?php

function makeDirectory($new_path, $mode) {
    if (!file_exists($new_path)) {
        mkdir($new_path, $mode, true);
        echo "New folder was created.&lt;br&gt;";
    }
}

$new_path = 'my_project/new/directory';
$mode = 0777;

makeDirectory($new_path, $mode); //New folder was created.
</code></pre>
<p>Let&#8217;s stop here for a while and explain a little bit used snippeds of code. The PHP <code>mkdir()</code> function will create a new directory. Its method signature according to the official PHP documentation [<a href="http://php.net/manual/en/function.mkdir.php" rel="nofollow">link</a>] is like this:</p>
<p><code>bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = FALSE [, resource $context ]]] )</code></p>
<p>As we can see only the first parameter <code>$pathname</code> is mandatory. The second parameter <code>$mode</code> is by default set to 0777. It represents default <code>chmod</code> settings for the newly created folder. For now, we only need to know that this number represents various folder access rights in operating systems.</p>
<p>If you want to know more about <code>chmod</code> , check <a href="http://codepills.com/?s=chmod">codepills.com</a> about more <code>chmod</code> articles.</p>
<p>The reason why we used the second parameter <code>chmod</code> is because we wanted to use the third method parameter <code>$recursive</code>. It allows the creation of nested directories, subdirectories, specified in the <code>$pathname</code>.</p>
<p>This code will secure creating a folder on an arbitrary path declared in the <code>$pathname</code> string from the root file where the called function is executed.</p>
<p>If you want to create a folder just in your root directory, you can write instead of the path, just the folder&#8217;s name.</p>
<h2>Creating a new folder in PHP in a defensive way</h2>
<p>A much clever and concise solution against the one we have seen is to use <code>is_dir()</code> instead of <code>file_exists()</code> snippet. <code>file_exists()</code> is method asking if the file or directory exists. <code>is_dir()</code> is optimized just for directories and therefore even faster.</p>
<p>Moreover, we should be sure that the requested path does not already exist before even asking the <code>mkdir()</code> function to do anything. Instead of if-else conditional logic, we can do boolean logic straight on the return.</p>
<pre><code class="language-php">&lt;?php

function makeDirectory($new_path, $mode) {
    return is_dir($new_path) || mkdir($new_path, $mode, true);
}

$new_path = 'my_project/new/directory';
$mode = 0777;

makeDirectory($new_path, $mode);</code></pre>
<p>The code snippet above does not work if there is already a filename with the same name. Otherwise, the code snippet will recursively create a directory path with much less code.</p>
<p>We are using the power of the <code>OR</code> operator. If the first expression is evaluated as true, it means that the folder exists. In <code>OR</code> operator first <code>true</code> evaluation is the reason to stop evaluating whole expression and evaluation do not continue further. It computer science this property of <code>OR</code> operator is better known as <b>short circuit</b>.</p>
<p>However, if the first expression is evaluated as false, <code>OR</code> will ask the second half of the expression for evaluation. Now we know that the folder does not exist, and therefore <code>mkdir()</code> method is called. If the<code>mkdir()</code> function creates the folder without error, it will return true. Therefore, in the end, we get confirmation that the new folder exists.</p>
<pre><code class="language-php">&lt;?php

function makeDirectory($new_path, $mode) {
    $return = mkdir($new_path, $mode, true);
    return $return === true || is_dir($new_path);
}

$new_path = 'my_project/./directory';
$mode = 0777;

$result = makeDirectory($new_path, $mode);
echo($result);
</code></pre>
<p>If we are sure that the directory we want to create will not exist, we can slightly change our custom function and make it in the same way more effective.</p>
<p>But <b>be aware of forbidden characters</b>. <u>Each operating system has some special characters which can not be used for the directory name.</u> For example, Windows operating systems denies using <code>/?&lt;&gt;\:*|"</code> , Unix based systems deny using dot in the folder name.</p>
<h2>Conclusion</h2>
<p>This article has shown how to create a folder automatically in PHP if it does not exist. We have demonstrated several different approaches to solve this problem in the right way.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-create-a-folder-in-php-if-it-doesnt-exist/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to compute distance between 2 GPS points?</title>
		<link>https://codepills.com/compute-distance-2-gps-points/</link>
					<comments>https://codepills.com/compute-distance-2-gps-points/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Thu, 15 Dec 2016 18:05:03 +0000</pubDate>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[direct distance]]></category>
		<category><![CDATA[distance between airports]]></category>
		<category><![CDATA[Earth's surface]]></category>
		<category><![CDATA[geographical calculations]]></category>
		<category><![CDATA[Great Circle distance]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=750</guid>

					<description><![CDATA[This is an algorithm for measuring distance between 2 GPS points.  <a href="https://codepills.com/compute-distance-2-gps-points/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>When working on projects involving geographical calculations, such as determining the direct distance between two airports on a global scale, developers often seek efficient methods to compute such distances accurately. One common approach involves utilizing algorithms derived from the Great Circle distance method, which considers the curvature of the Earth&#8217;s surface.</p>
<p><span id="more-750"></span></p>
<p>In this article, we explore a PHP implementation of this method and propose two simplifications to enhance its efficiency and readability.</p>
<h2>Introduction</h2>
<p>In one of my projects, I was looking for a simple way to compute the direct distance between 2 arbitrary airports in the world.</p>
<p>I was looking for a way to measure the distance between 2 GPS points. Naturally, there are several ways to compute such distances.</p>
<p>After research, I found that many people use algorithms derived from the Great circle distance method [<a href="https://en.wikipedia.org/wiki/Great-circle_distance" title="Great-circle distance" target="_blank" rel="nofollow noopener">wiki</a>].</p>
<p><!--more--></p>
<p>Here is a PHP code:</p>
<pre><code class="language-php">/**
 * Great Circle distance algorithm
 *
 * Notes:
 * - South and West locations are negative, North and East are positive.
 * - Automatically transfer degrees to radians
 * - https://en.wikipedia.org/wiki/Great-circle_distance
 *
 * @param lat1 - latitude of the first point on the sphere
 * @param lon1 - longitude of the first point on the sphere
 * @param lat2 - latitude of the second point on the sphere
 * @param lon2 - longitude of the second point on the sphere
 * @param unit - units for output (miles, kilometers, nautical miles)
 * @return - distance in desired distance units
 *
 */
function GreatCircleDistance($lat1, $lon1, $lat2, $lon2, $unit) {
    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $unit = strtoupper($unit);

    switch ($unit) {
        case 'MI':
            return $miles;
            break;
        case 'KM':
            return ($miles * 1.609344);
            break;
        case 'NM':
            return ($miles * 0.8684);
            break;
    }
}</code></pre>
<p>There are two simple corrections to simplify this algorithm.</p>
<p>First by padding all the sub-results into one big equation.</p>
<p>Second, by ensuring the input units will always be the same (using numbers instead of Strings), the <code>strtoupper()</code> function can be removed.</p>
<h2>Conclusion</h2>
<p>In conclusion, by streamlining the implementation of the Great Circle distance algorithm in PHP, developers can achieve enhanced efficiency and readability in their geographical computations. These simplifications make the code more concise and ensure consistent input handling, contributing to a smoother development process.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/compute-distance-2-gps-points/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Start With Codeception PHP Framework And Selenium</title>
		<link>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/</link>
					<comments>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Wed, 09 Nov 2016 20:12:29 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Composer]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP framework]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[UAT]]></category>
		<category><![CDATA[webdriver]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=625</guid>

					<description><![CDATA[This is a small guide explaining how to start with Codeception PHP test framework and how to integrate it with Selenium for automated tests. <a href="https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Recently I have been working on one job interview with test case requiring to write portion of automatized tests in Codeception PHP framework. Since I didn&#8217;t have any experience with Codeception PHP framework I needed to learn quickly as much as I could.</p>
<p><span id="more-625"></span></p>
<p>This is a small guide explaining how to start with Codeception PHP test framework and how to integrate it with Selenium for automated tests.</p>
<h2>What is Codeception and what is good for?</h2>
<p><a href="http://codeception.com/" target="_blank">Codeception</a> is PHP framework devoted to test PHP code. Installation is very simple and requires only a few steps. It is actually well known for its easy code readability of test units. Codeception PHP framework is used for acceptance testing. Codeception emphasize usage of the variable name $I, so than many lines of code are very descriptive exp. $I want to do this and that, $I expect to see something. etc.</p>
<p>Codeception helps with creating test suites for 3 types of testing:</p>
<ul>
<li>Accaptance</li>
<li>Unit</li>
<li>Functional</li>
</ul>
<h3><strong>What is acceptance testing?</strong></h3>
<p>Acceptance tests are emulating behavior of a real user visiting website.</p>
<blockquote><p>Acceptance testing is formal testing with respect to user needs, requirements, and business processes conducted to determine whether a system satisfies the acceptance criteria and to enable the user, customers or other authorized entity to determine whether or not to accept the system. Acceptance testing is also known as user acceptance testing (UAT), end-user testing, operational acceptance testing or field (acceptance) testing.</p>
<p>Source: Wikipedia</p></blockquote>
<p>First of all I have to recommend to watch first video by Jeffrey Way from EnvatoTuts+ for Codeception series <a title="Modern Testing in PHP with Codeception at EnvatoTuts+" href="https://code.tutsplus.com/courses/modern-testing-in-php-with-codeception" target="_blank" rel="nofollow">Modern Testing in PHP with Codeception</a>. Although the first video is very well narrated and instructive for beginner, rest of the serie is not and I would not recommend to pay for premium account to watch the rest. Jeffrey expect knowledge of many related topics where you can use Codeception (DB connection, Laravel, &#8230;) but do not create simple code snippets for your first test and does not talk much about usage of elemental Codeception functions. Serie is aimed for advanced users.</p>
<h2>1. Download</h2>
<p>You can download Codeception framework out of the box via composer by CLI command <code>$ composer require "codeception/codeception"</code> .</p>
<p>You can also implement it into already existing project updating a composer.json file placing following:</p>
<pre class="lang:js decode:true">{
    "require": {
        "codeception/codeception": "^2.2",
        ...
    }
}
</pre>
<p>For newest version of Codeception please visit and search <a title="PHP packages" href="https://packagist.org/" target="_blank" rel="nofollow">packagist.org</a> . Over CLI just hit composer command in folder of your project: <code>composer update</code> (or <code>composer install)</code>.</p>
<h2>2. Create codeception.yml</h2>
<p>By executing <code>codecept bootstrap</code> Codeception creates the codeception.yml file and bunch of new files for test suites.</p>
<h3>What is test suite?</h3>
<blockquote><p>The test suite is a collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviours. A test suite often contains detailed instructions or goals for each collection of test cases and information on the system configuration to be used during testing. A group of test cases may also contain prerequisite states or steps, and descriptions of the following tests.</p>
<p>Collections of test cases are sometimes incorrectly termed a <span style="text-decoration: underline;">test plan</span>, a <span style="text-decoration: underline;">test script</span>, or even a <span style="text-decoration: underline;">test scenario</span>.</p>
<p style="text-align: left;">Source: <a href="https://en.wikipedia.org/wiki/Test_suite" target="_blank">Wikipedia</a></p>
</blockquote>
<h2>3. Create your first test</h2>
<p>Create your first test by Codeception command:</p>
<p><code>codecept generate:cept acceptance FirstTest</code></p>
<p>Note: Codeception scenario tests are called Cepts.</p>
<h2>4. Setting Acceptance test method</h2>
<p>Basically there are 2 method which I managed to try to in short time &#8211; PHP Browser and Selenium WebDriver:</p>
<ol style="list-style-type: upper-alpha;">
<li>PHP Browser &#8211; works on idea of web scrapper. Code does not emulate real browser but just download HTML code and apply test scenarios on it.</li>
<li><a href="http://www.seleniumhq.org/projects/webdriver/" target="_blank">Selenium WebDriver</a> &#8211; works as &#8220;artificial user&#8221;. PHP test case code emulate real browser and perform actions upon real website in browser.</li>
</ol>
<p>I would recommended to first start with PHP Browser and than try Selenium WebDriver. PHP Browser can check HTML page contents, click links, fill forms, and submit POST and GET requests. Unfortunately PHP Browser have few drawbacks (you can click only on links with valid urls or form submit buttons,  you can’t fill fields that are not inside a form, you can’t work with JavaScript interactions like modal windows or date-pickers) and for more complex tests is necessary to use Selenium WebDriver.</p>
<h3>4.1. PHP Browser</h3>
<p>For setting up PHP Browser just change acceptance.suite.yml to:</p>
<pre class="lang:yaml decode:true">class_name: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
            url: "http://localhost/app"          
        - \Helper\Acceptance</pre>
<h3>4.2. Selenium WebDriver</h3>
<p>For setting Selenium WebDriver you need to make 3 steps.</p>
<p>1) Change acceptance.suite.yml to:</p>
<pre class="lang:yaml decode:true">class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: "http://localhost:8000/app"
            browser: firefox            
        - \Helper\Acceptance</pre>
<p>2) In your .bash_profile you must also set GeckoDriver (drivers emulating Firefox) which you can download from <a href="https://github.com/mozilla/geckodriver/releases" target="_blank">mozilla/geckodriver</a> GitHub page.</p>
<pre class="lang:default decode:true">## Selenium GeckoDriver
export PATH=$PATH:/PATH_TO_GECKODRIVER_FOLDER/</pre>
<p>3) To set Selenium WebDriver is also necessary download <a href="http://www.seleniumhq.org/download/" target="_blank">Selenium Server</a> and run it prior the test. To run Selenium Server change directory to folder where is file located and type server run command <code>java -jar selenium-server-standalone-<em>YOUR.V.NO</em>.jar</code> .</p>
<h2>5 .Writing first PHP test</h2>
<p>Under acceptance folder we will create first test in FirstTest.php file. We will try to check &#8220;Hello World!&#8221; text at homepage:</p>
<pre class="lang:php decode:true">&lt;?php
  $I = new AcceptanceTester($scenario);
  $I-&gt;wantTo('Test Frontpage');
  $I-&gt;amOnPage('/');
  $I-&gt;see('Hello World!', 'h1');
?&gt;</pre>
<h2>6. Running the test</h2>
<p>Running the test case is possible by simple command <code>codecept run</code> . You will write this command often so you can create temporary (alias in your folder) or permanent alias (in .bash_profile) by creating alias exp. <code>alias runtest=vendor/bin/codecept run</code> and than just type your alias.</p>
<p>If you have done everything right, with Selenium you should new see Firefox window executing your first test. After finishing it, browser will close down and terminal shows announcement about Success. PHP Webdriver execute all test just over the terminal info panel.</p>
<h3>6.1 Further use</h3>
<p>To show the list of all available commands you need to type <code>vendor/bin/codecept</code> . It will also handy to create alias for it ( but just for <code>vendor/bin/ </code>and than type<code> codecept</code> ).</p>
<p>Codecept will always by run execute every single test you have wrote all together. It helps to nerrow down only the test suite which we want by selecting test suit in command: <code>codecept acceptance/functional/unit run</code> .</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Project 1Searchform</title>
		<link>https://codepills.com/project-1searchform/</link>
					<comments>https://codepills.com/project-1searchform/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 28 Mar 2016 15:00:33 +0000</pubDate>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[portfolio]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=641</guid>

					<description><![CDATA[Problem description: Different booking portals have different price policies and use different algorithms to provide offers. Sometimes I plan my trips and I search on these booking portals for best (cheapest or fastest) option. It is always very time-consuming search. Solution: So I was thinking &#8230; <a href="https://codepills.com/project-1searchform/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p><strong>Problem description:</strong></p>
<p>Different booking portals have different price policies and use different algorithms to provide offers. Sometimes I plan my trips and I search on these booking portals for best (cheapest or fastest) option. It is always very time-consuming search.</p>
<p><span id="more-641"></span></p>
<p><strong>Solution:</strong></p>
<p>So I was thinking how to save time&#8230; I do not have access to any booking system and this approach would not be even best one since it is not possible to say which travel booking portal is best one. What I can do at least is to access all the websites at once with same search parameters. To have one search form which can pad data to any travel booking portal and than just check the best/cheapest available option.</p>
<blockquote><p>One Searchform to rule them all, One Searchform to find them,<br />
One Searchform to bring them all and in the web bind them.</p></blockquote>
<p><strong>Limitations:</strong></p>
<p>Project is based upon opening new tabs over javascript function for pop-up. Default in many browser is necessary to allow pop-up tabs to show. Project currently support only cities with international airports. Also not all options are available for all the booking portals.</p>
<p><strong>Benefit and case study:</strong></p>
<p>Using this form I can quickly compare many sites. Differences between single offer can be huge. Just simple random example.: normal usual flight between London and Berlin cost on kayak.com 200$. Over google.com/flights cost 194$. It is not a huge difference. But certainly pays for a lunch at the airport or else something small &#8230; <span style="text-decoration: underline;">Different booking portals sell same services and goods.  So why pay extra when you don&#8217;t have to?</span></p>
<p>Just a small comparison of random flight made from Vienna (Austria)[VIE] to Malta[MLA] and back 31.03. &#8211; 24.04.2016 (search made 28.03.2014):</p>
<table class="table table-bordered table-striped table-bordered">
<thead>
<tr>
<td>Portal</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<tr>
<td>Google Flights</td>
<td>219€ &#8211; 245$</td>
</tr>
<tr>
<td>Rome2Rio.com</td>
<td>221€</td>
</tr>
<tr>
<td>SkyScanner.com</td>
<td>231€ &#8211; 258$</td>
</tr>
<tr>
<td>Kayak.com</td>
<td>235€</td>
</tr>
<tr>
<td>SkyPicker.com</td>
<td>266€ &#8211; 315.23$</td>
</tr>
</tbody>
</table>
<p><strong>Development:</strong></p>
<ul>
<li>1st version was created in procedural programing.</li>
<li>Than instead of opening all selected portals in new tabs I tried to open them in new pages in different tabbed iframes. Unfortunately I found of that many of them use iframe protection(fraud protection) and they simple do not render in iframe.</li>
<li>2nd version is made in OOP.</li>
</ul>
<p>If you have any ideas for improvement or comments they are very welcome. Please contact me over Contact page or leave me a comment.</p>
<p><strong><a href="http://projects.codekopf.com/searchform1/">Project link</a></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/project-1searchform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Fixing SimplePie &#8220;./cache is not writeable.&#8221; error</title>
		<link>https://codepills.com/fixing-simplepie-cache-is-not-writeable-error/</link>
					<comments>https://codepills.com/fixing-simplepie-cache-is-not-writeable-error/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Sun, 20 Mar 2016 20:21:18 +0000</pubDate>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=408</guid>

					<description><![CDATA[Switching from EasyPHP to XAMPP as development environment and Windows to OSX I have encounter error regarding cache file in my app based on SimplePie library. Error looked like this: Warning: simplePie/cache is not writeable. Make sure you&#8217;ve set the correct relative or &#8230; <a href="https://codepills.com/fixing-simplepie-cache-is-not-writeable-error/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Switching from EasyPHP to XAMPP as development environment and Windows to OSX I have encounter error regarding cache file in my app based on SimplePie library.</p>
<p><span id="more-408"></span><br />
Error looked like this:</p>
<blockquote><p>Warning: simplePie/cache is not writeable. Make sure you&#8217;ve set the correct relative or absolute path, and that the location is server-writable. in /Applications/XAMPP/xamppfiles/htdocs/xxxxxxxxx/simplePie/library/SimplePie.php on line 1369</p></blockquote>
<p>I browsed internet and first counter measure is to define absolute path to SimplePie cache folder from this:</p>
<pre class="lang:php decode:true">$feed-&gt;set_cache_location('simplePie/cache');</pre>
<p>to this:</p>
<pre class="lang:php decode:true">$feed-&gt;set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/xxxxxxxxx/simplePie/cache/');</pre>
<p>or any other possible way to define absolute path in file.</p>
<p>Second counter measure is to set proper permission on folder where cache is made. I used Double Commander in OSX.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/fixing-simplepie-cache-is-not-writeable-error/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to make a webpage</title>
		<link>https://codepills.com/how-to-make-a-webpage/</link>
					<comments>https://codepills.com/how-to-make-a-webpage/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Wed, 02 Dec 2015 14:59:02 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Learning notes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=421</guid>

					<description><![CDATA[Whatt is necessary for making webpage What is not necessary for making webpage Two steps for creating first webpage Webpage files WYSIWYG HTML editors Writing own HTML code Tutorial for begginers Quickest way how to learn making webpage What is necessary for making &#8230; <a href="https://codepills.com/how-to-make-a-webpage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<ul>
<li><a href="#whatisnecessary">Whatt is necessary for making webpage</a></li>
<li><a href="#whatisnotneeded">What is not necessary for making webpage</a></li>
<li><a href="#twosteps">Two steps for creating first webpage</a></li>
<li><a href="#files">Webpage files</a></li>
<li><a href="#editors">WYSIWYG HTML editors</a></li>
<li><a href="#writing">Writing own HTML code</a></li>
<li><a href="#tutorial">Tutorial for begginers</a></li>
<li><a href="#quickest">Quickest way how to learn making webpage</a></li>
</ul>
<p><span id="more-421"></span></p>
<h2><a name="whatisnecessary"></a>What is necessary for making webpage</h2>
<ul>
<li>First of all it is important to use <strong>logic and brain</strong>. All information system are very rational and thus easy to work with.</li>
<li>At start we will need <strong>any kind of PC which is running basic text editor</strong> (exp. Windows Notepad, TextEdit). Creating websites is possible nowadays even on mobile devices but this something we do not need to concern about now.</li>
<li>We need <strong>internet browser</strong>. All internet browsers are available free of charge. In long-term exist few very popular with huge market share:
<ul>
<li>Internet Explorer &#8211; icon of the blue round E. Default browser for Windows operating systems.</li>
<li>Chrome &#8211; icon of the multicolored ball. Browser provided by company Google.</li>
<li>Firefox &#8211; icon of the red fox. Browser provided by company Mozilla.</li>
<li>Opera &#8211; icon of the red letter O</li>
<li>Safari &#8211; icon of the compass. Default browser for iOS devices.</li>
</ul>
</li>
<li><strong>Internet connection</strong> is not necessary for making website but it is very desirable for quick learning and eventually fast development. Nobody expect you to know everything. And there is lot of information available on the Internet from which you can use as source. Thus having constant internet connection is very handy for quick learning.</li>
<li>It is good to have <strong>idea what you want to make</strong>.</li>
<li>Don&#8217;t try to do anything if you have not <strong>elementary knowledge of work with computer</strong>. Better said, you understand at least what is file, how to work with system files, what is system directory.</li>
</ul>
<h2><a name="whatisnotneeded"></a>What is not necessary for making webpage</h2>
<ul>
<li>As was said earlier internet connection is not directly necessary for creating websites.</li>
<li>You do not need buying expensive licenses for complex code editors. There are plenty of free and simple editors for making websites.</li>
<li>You do not need to know how to program.</li>
<li>You do not need to pay anything for training or learning. Unless you decide you want to have own domain.</li>
</ul>
<h2><a name="twosteps"></a>Two steps for creating first webpage</h2>
<ul>
<ol>
<li>Write webpage = source code saved in HTML file (occasionally with additional other files)</li>
<li>Uploading webpage file on the Internet = copying webpage file on server.</li>
</ol>
</ul>
<p>In this article we will talk about first step, making webpage &#8211; writing its source code. At first, localy, on own discspace.</p>
<h2><a name="files"></a>Webpage files</h2>
<p>Internet webpage is file with file extension html or htm. It is nearly normal text file. Only difference is that text, images, video, all media etc. are formated in signs of HTML language called tags.</p>
<p>File with .html extension on local disk has own icon depicting that it is webpage. It can look like this:</p>
<h3>How to open Webpage</h3>
<ol>
<li>You can look at the webpage as page in browser &#8211; in such case you can not edit it</li>
<li>or you open it as a text (exp. in Notes program), and you will see it&#8217;s source code  (source, code) and you can edit it. This is a way how pages are made.</li>
</ol>
<h3>How to make HTML file</h3>
<ul>
<ol>
<li>You can directly write your own source code in HTML language. Might look hard on first sight. But it is much easier than you think.</li>
<li>Or you can make HTML file by HTML editor. (It is good for beginner to learn principles.)</li>
</ol>
</ul>
<h2><a name="editors"></a>WYSIWYG HTML editors</h2>
<p>HTML editors are program designated for making webpages. For beginners are especially useful WYSIWYG editors &#8211; What You See Is What You Get &#8211; literally used edit webpage as it will be looking and does not bother by writing HTML source code.</p>
<p>In WYSIWYG editor you  can create webpages without knowledge of HTML language. You are normally writing paragraphs, insert images and make other common edits. WYSIWYG editor than save file on disk to file with html extension. Editor also automatically insert all necessary HTML tags into webpage itself.</p>
<p>To WYSIWYG editors belong Dreamweaver, FrontPage 2000 and few others. WYSIWYG editors has certain disadvantages (exp. quality and size of source code)  for which are not deployed.</p>
<p>You can reed more about advantages and disadvantages in <a href="http://codekopf.com/basic-course-making-html-website/html-editors/">article about WYSIWYG editors</a>.</p>
<p>Accept WYSIWYG editors exist also structural editors, in which you can directly writing HTML code with possibility of program helping you (placing ending tags etc.)<br />
Structural editors are: PSPad, Notepad++, jEdit, Code, Sublime Text, etc. and in case of emergency even simple Microsoft Notepad.</p>
<p>You can also use Word or Libre Office for writing webpages.</p>
<h2><a name="writing"></a>Writing own HTML code</h2>
<p>Who wants to have full control  writes own HTML source code from begging in structural editor. She or he need to learn basic HTML tags. Learning HTML basics is fundamental because creating latter more complicated solutions in WYSIWYG editors is not possible.</p>
<p>This is example of basic HTML code structure:</p>
<pre class="lang:xhtml decode:true ">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My first webpage&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;h1&gt;My first webpage.&lt;/h1&gt;
&lt;p&gt;"That's one small step for man, one giant leap for mankind." - Neil Armstrong&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>If you will take this HTML code and open exp. Notepad, place it into editor and save on disk under name example.html you have made your first webpage. You can also open your newly created webpage in the <a href="http://codekopf.com/basic-course-making-html-website/internet-browsers/">browser</a>.</p>
<h2><a name="tutorial"></a>Tutorial for beginners</h2>
<p>How to make HTML file in Windows (one of many ways). (If something would not work, check our more complex tutorial).</p>
<ul>
<ol>
<li>Create on your disk new folder exp. C:test and open it.</li>
<li>Create new text file (right mouse click &gt; New &gt; Text Document)</li>
<li>Rename it as webpage.html (and confirm extension change). File icon will change.</li>
<li>Open file by double click. Blank page will be opened in browser.</li>
<li>Return to folder and click by right click on newly created file &#8211; select Open in program. If Notepad is available, select it. If it is not available you need to find it. Empty text edit will open up.</li>
<li>Now you can write text and add additional HTML tags. You can read more in article about HTML basics.</li>
<li>Hit File &gt; Save.</li>
<li>Flip to opened browser and hit F5 (Refresh page).</li>
<li>Check the differences.</li>
<li>You can experiment like this infinitely.</li>
</ol>
</ul>
<p>For now your page is at your local disk. You can check article about how to copy webpage on server.</p>
<p><b>In file names used for internet never use diacritic and spaces! </b>We recommend write all names lowercase.</p>
<h2><a name="quickest"></a>Quickest way how to learn making webpages</h2>
<p>I believe that the quickest way how to learn making webpages is to use combination of advantages of both kind of editors. :</p>
<ul>
<li>Make webpage in WYSIWYG editor</li>
<li>Check webpage in browser</li>
<li>Analyse HTML code in structural editor. Edit the page and check what will happens.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-make-a-webpage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress 3.2.1 installation PHP warning</title>
		<link>https://codepills.com/wordpress-3-2-1-installation-php-warning-2/</link>
					<comments>https://codepills.com/wordpress-3-2-1-installation-php-warning-2/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Wed, 20 Jul 2011 14:54:58 +0000</pubDate>
				<category><![CDATA[Wordrpress]]></category>
		<category><![CDATA[maintenance mode]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[successfull installation]]></category>
		<category><![CDATA[webhosting provider]]></category>
		<category><![CDATA[websupport.sk]]></category>
		<category><![CDATA[wordpress installation error]]></category>
		<category><![CDATA[wordpress installation problem]]></category>
		<category><![CDATA[wordpress requirements]]></category>
		<category><![CDATA[wordpress server]]></category>
		<category><![CDATA[wordpress update]]></category>
		<category><![CDATA[wordpress version]]></category>
		<category><![CDATA[wordpress webhosting]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=664</guid>

					<description><![CDATA[During upgrade of my WordPress on newer 3.2.1 version I&#8217;ve got an installation error. It was caused by version of used PHP version on side of server. Error looked like this:  An update version of WordPress is available. You cannot update because &#8230; <a href="https://codepills.com/wordpress-3-2-1-installation-php-warning-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>During upgrade of my WordPress on newer 3.2.1 version I&#8217;ve got an installation error. It was caused by version of used PHP version on side of server. <span id="more-664"></span>Error looked like this:</p>
<blockquote><p> <strong>An update version of WordPress is available.</strong></p>
<p>You cannot update because WordPress 3.2.1 requires PHP version 5.2.1 or higher. You are running version 4.4.9.</p>
<p>While your sire is being updated, it will be in maintenance mode. As soon as you updates are complete, your sire will return to normal.</p></blockquote>
<p>I&#8217;ve fixed this issue by simple command. In administration of my webhosting provider I&#8217;ve writen .php in space, which used to be blank (red rectangle). Files of .php are now executed under version of PHP 5.3 .</p>
<p>My webhosting provider is websupport.sk. But I am sure this simple trick will be working everywhere. Even when it looks little bit confusing it works. Upgrade was succesfull.</p>
<p><strong>Additional information</strong><br />
If I delete .php from PHP 5.3 row after successfull installation, I get message on my blog:</p>
<blockquote><p>Your server is running PHP version 4.4.9 but version 3.2.1 requires  at least 5.2.4</p></blockquote>
<p>If it is working, it is O.K.  ;D</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/wordpress-3-2-1-installation-php-warning-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
