- Instant help with your Php coding problems

PHP for Dummies

What is PHP

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP is similar to Perl and C and is one of the most popular web programming languages.

The history of PHP begins in 1995 and the first main version PHP3 was released in 1998. The actual version is PHP8. However, a lot of web-server still use PHP7 which is supported only until the end of 2020.

You can run PHP on various operating systems as: Windows, Linux, Unix, Mac OS

And PHP supports a lot of web servers as well: Apache, Microsoft IIS, Personal Web Server,  omniHTTPd,...

How PHP works

You can use PHP if you want to create web pages with dynamic content. For example, if you want to display a welcome message depending on the time. You can not do this with a simple HTML as if you navigate to an html site the web-server just sends the content of the page to your browser without any modification.

However, if you create a PHP site and navigates to it your web-server will first forward the file to the PHP interpreter. Then the page/code will be analyzed and depending on the code a pure html output will be sent to your browser. Of course, your web server needs to be configured correctly to handle PHP scripts.

Install PHP for dummy

To install PHP is not a complicated task, however, it can take a long time for absolute beginners. If you want to set up a complete environment with database support you need to install more software on your server.

First of all, you need to install a web-server that is responsible to process user requests. There is a lot of web-server software on the market but Apache and Microsoft IIS are the most popular. Nowadays PHP is installed more often with Apache.

The second software is the PHP interpreter itself. Usually, you only need to copy the files anywhere and set the web-server and php configuration files correctly.

The last one can be a database server like MySQL. It is not necessary but usually, dynamic web pages use databases to generate content. For example, CMS, forums all use databases to store user information, posts, articles in the DB. 

Besides this, you can install other 3rd party tools but they are out of the scope of this article.

As installation and configuration of the web-server, PHP interpreter and database can be a bit difficult for a beginner it makes sense to install the complete system with an all-in-one installer like XAMPP. With this tool, you can install all of the components at once and you don't have to worry about the configuration. Besides this, you only need to download one file and it contains all necessary components. You can find detailed installation instructions here: Install XAMPP

After some time, if you will be familiar with web-servers and PHP you can choose the PHP manual installation process to have better control over your system.

Now you should have a working web server on your machine it's time to create your first dynamic website with PHP.

First steps with PHP

If you use PHP you need to write your code between special tags which tells the interpreter that this part must be analyzed. These tags are the <?php  as opening and the ?>  as a closing tag. You can write your code between them. Each statement of the code must be separated by a semicolon ;

So to get information about your actual PHP settings and write your first PHP code you can create a file let's say info.php with the following content:

<?php
   phpinfo();
?>

Save the file, upload it to your web-server document root folder, and navigate to it with your browser. If everything was set up correctly then you will get a quite big table with a lot of information about your actual PHP settings.

In the next step, you need to learn about variables, PHP conditional statements, functions, sessions, and so on. You can find more tutorials about this topic on this site.

 

Share "PHP for Dummies" with your friends