Code

PHP from Scratch for Beginners: A Self-Study Guide for Dummies with a Scripting Example

PHP from Scratch for Beginners: A Self-Study Guide for Dummies with a Scripting Example

Learn: PHP Developer from Scratch to Pro

Learn More

Today we'll discuss the PHP programming language, which combines ease of use with powerful capabilities. We'll look at its attractive features, salary levels for entry-level PHP developers, and career paths in web development. We'll show you how to create a simple script from scratch, which will be useful for beginners looking to master this language. PHP remains one of the most in-demand languages ​​in web development, and mastering its basics opens the door to a variety of career opportunities.

  • What is written in the PHP programming language?
  • Why is PHP in demand and popular in web development?
  • How much do beginner and experienced developers earn?
  • What you need to know and how a beginner can advance in the profession?
  • What books to read for self-study of PHP?
  • How to write a simple script and website?

What is written in PHP?

The PHP programming language is widely used for developing websites and web applications, especially in the field of backend development. It is a powerful tool that allows you to create dynamic and interactive web solutions. PHP provides efficient interaction with databases and serves as the basis for many popular platforms and frameworks, such as WordPress, Laravel, and Symfony. Thanks to its simplicity and flexibility, PHP remains one of the most popular programming languages ​​in web development.

All websites consist of two main components: the frontend and the backend. The frontend includes all the elements visible to the user, such as animations, sliders, drop-down menus, and other interactive elements. Designers create website layouts, and developers convert these layouts into code using HTML, CSS, and JavaScript. Proper integration of the frontend and backend ensures the functionality and visual appeal of the website, which in turn affects user experience and SEO rankings in search engines.

The backend platform provides communication between the website and internal server systems. It processes user requests, interacts with the database, and transmits results to the frontend. PHP is most often used for backend development, as it is effective for creating dynamic web applications and managing server logic. PHP allows developers to create complex functionality while ensuring high performance and application security.

In our article "Frontend vs. Backend - Using Website Creation as an Example," we examine the differences between these two web development approaches in detail. This material will be especially useful for those who have not yet decided on a programming language or technology to learn, be it PHP, HTML, CSS, or JavaScript. Find out what is right for you and take your first step into the world of web development.

Why PHP Continues to Be in Demand and Relevant

PHP has been around for over 20 years. This programming language was created by Dane Rasmus Lerdorf in 1994. Initially, it was developed as a tool to display the number of visits to Rasmus's personal web page and was called Personal Home Page. Over time, PHP has evolved to become a powerful server-side platform for building dynamic websites and applications, gaining widespread popularity among developers due to its simplicity and flexibility.

The PHP programming language is constantly evolving. In 2004, PHP 5 was released, gaining popularity among web developers due to its efficient implementation of object-oriented programming. In December 2015, PHP 7 was released, enabling the creation of faster and more performant applications. November 2020 marked the release of PHP 8, which offered new features and improvements. PHP 8.2 is expected to be released on November 24, 2022, continuing the trend of improving the performance and functionality of the language.

For more detailed information on the key features and versions of the PHP programming language, we recommend reading the article "The PHP Programming Language: From Its Origins to the Present." In it, you'll find up-to-date information on the language's development, its functionality, and its application in modern web development.

According to W3Techs, PHP is used on approximately 80% of websites, making it one of the most popular programming languages ​​for backend development. This is because well-known content management systems (CMS) such as WordPress and Drupal are written in PHP. Furthermore, a number of major platforms, such as Facebook, VKontakte, Yahoo search, and Wikipedia, also use this language. A significant portion of Google services are developed using PHP, and in Russia, the popular CMS 1C-Bitrix is ​​also based on this language. The use of PHP in web development makes it an essential tool for creating modern and functional websites.

The world's largest companies that use PHP Image: Skillbox Media

PHP is a popular programming language that is often taught from scratch due to its low entry barrier. In just one month of training, you'll be able to create simple websites. As your skills develop, you'll gain the opportunity to develop high-load systems for large companies, opening up broad prospects in web development. Learning PHP not only teaches you the basics of programming but also allows you to delve deeper into topics such as working with databases, creating dynamic content, and optimizing application performance. Despite predictions of PHP's imminent demise, this programming language remains one of the most in-demand. Jobs requiring PHP knowledge account for 24.6% of all job postings. Java ranks second with 24.1%. C# lags far behind, accounting for only 9.8%. This confirms that PHP still plays a key role in web application development and maintains high competitiveness among other programming languages.

PHP, Java, and C# are the most popular languages ​​among employersImage: Skillbox Media

The popularity rating of programming languages ​​is based on the analysis Job openings on Russian-language career platforms. The structure of this ranking is likely to remain stable over the next five years.

If you want to learn a programming language from scratch, the article "Learning PHP: Tips and Advice for Beginners" will provide you with clear and structured advice to help you avoid common mistakes. This resource will become your guide to the world of PHP, allowing you to effectively master key concepts and practical programming skills.

Salary Levels for PHP Developer Jobs

According to HeadHunter, the maximum salary for a PHP programmer in Russia reaches $10,000. If we consider salaries by levels of professional development, they are distributed as follows:

  • Junior Developer — from 40 thousand rubles per month. Just entering the profession, knows how to work with legacy code and write simple scripts, has commercial programming experience of about 2-3 months.
  • Middle Developer — from 100 thousand rubles per month. Can independently cope with 90% of the tasks and has programming experience from six months to a year.
  • Senior Developer — from 150 thousand rubles per month. Can solve any problem in PHP, design a solution, architecture, select code and train a junior or middle programmer to perform these tasks.

In 2022, there was a noticeable increase in salaries of PHP developers in Russia, which exceeded the increase in incomes of programmers in other programming languages. Beginning specialists (juniors) are now offered salaries starting at 60,000 rubles per month, while experienced developers (seniors) can expect to earn 400,000 rubles. This trend highlights the growing demand for PHP developers in the country and confirms the importance of PHP programming skills for career advancement in IT.

What skills should a web developer have?

A beginner backend developer should master the key technologies necessary for success in this field. The most important of these are programming languages ​​such as Python, Java, PHP, and JavaScript. These languages ​​allow you to create server-side logic, process requests, and interact with databases.

Working with frameworks, which speed up development and simplify the code structure, is equally important. Popular frameworks include Django for Python, Spring for Java, and Laravel for PHP. They offer ready-made solutions for creating web applications.

Knowledge of database management systems such as MySQL, PostgreSQL, and MongoDB also plays a vital role. Ability to work with SQL and NoSQL databases will allow you to effectively store and process information.

In addition, a novice backend developer should be familiar with RESTful APIs and the principles of their development, which will ensure interaction between the client and server parts of the application.

Skills in working with version control systems such as Git, which allow you to track changes in code and facilitate teamwork, are also necessary.

Understanding the basics of application security is an important aspect to protect user data and prevent possible attacks.

Thus, mastering these technologies will help a novice backend developer successfully start their career and effectively solve problems related to the development of the server side of web applications.

  • HTML and CSS are page markup languages. They are most often used by frontend developers, but you need to know and understand the basics, since you will have to work with ready-made markup.
  • JavaScript is code executed on the client (browser) side. It defines the mechanics of the page. You need to be able to read it and understand the purpose of each section.
  • PHP is the core of a website, a scripting language that operates at the server level and interacts with the server structures on which the web project is built.
  • SQL is a structured query language used to manage databases, for example, in the MySQL DBMS.
  • Linux - yes, Linux. Windows is not intended to be used as a server operating system, although PHP can run on both Windows and Linux. While training doesn't require using Linux, it's important to know that in real-world projects, servers typically run on this operating system.

Oleg Shabashov, a developer at Searchanise, shares recommendations for the professional development of PHP programmers. He emphasizes the key skills and knowledge necessary for a successful career in this field, as well as common mistakes to avoid.

To successfully advance in the profession, it is important for a PHP programmer to constantly update their knowledge of modern technologies and frameworks, such as Laravel and Symfony. Database skills, as well as knowledge of software design and architecture principles, also play a vital role.

In addition to technical skills, Oleg emphasizes the importance of developing soft skills, such as communication and teamwork. This will help not only in solving current problems but also in career advancement.

By following these recommendations, PHP programmers will be able to develop effectively and avoid common mistakes in their professional work.

PHP Books

There are many popular and proven books that cover in detail the basics of the markup language, principles of working with web technologies, as well as the interaction between the backend and frontend. These books cover key web programming concepts and will help you gain a deeper understanding of the structure and functionality of modern web applications.

  • "PHP 7. In the Original" by Dmitry Koterov, Igor Simdyanov.
  • "Learning PHP 7. A Guide to Building Interactive Websites" by David Sklar.
  • "Building Dynamic Websites with PHP, MySQL, JavaScript, CSS, and HTML5" by Robin Nixon.
  • "PHP. Objects, Patterns, and Programming Techniques" by Matt Zandstra.
  • "Developing Web Applications with PHP and MySQL" by Luke Welling, Laura Thomson.

To successfully master the profession of a programmer, knowledge of a programming language alone is not enough. It is important to develop the ability to think like a programmer and constantly expand your knowledge. 16 recommended books will help you with this, which will become a valuable resource for your professional growth and deepen your understanding of programming. Reading these books will not only help you improve your coding skills but also learn new methodologies and approaches to software development.

Creating a Simple PHP Script from Scratch

We'll create a simple website for finding information about the quantity of products in stock. We'll focus on interacting with PHP and HTML without delving into the details of syntax and operator purposes. First, we need to install a server and a compiler that will process user requests. This will allow us to effectively work with data and provide up-to-date information about inventory.

Instructions are provided for Windows, Linux, and macOS operating systems. These guides will help you effectively interact with various functions and programs on each platform, ensuring quick and easy setup. No matter which operating system you use, you'll find useful steps and tips to optimize your workflow.

You can download PHP for Windows from the official website by selecting the required language version and operating system. In this case, we'll install PHP 8.1 for a 64-bit system. The installation process is similar for other PHP versions. Make sure you select the correct distribution to avoid compatibility issues.

When choosing the required PHP version, we recommend choosing the VS16x64 Thread Safe option. This will ensure compatibility with your projects and improve performance when working with multithreaded applications. Make sure you download the version that meets your requirements to optimize the performance of your web application.

Download the latest version of PHP from the official website of the language Screenshot: Skillbox Media

To install PHP, you need to unzip the archive to any convenient location on your hard drive and remember the path to this folder. In this example, we'll unzip the archive to the C:\Program Files\php-8.1.0 directory. This will provide access to PHP for further configuration and use. Make sure that the path to the installed folder is correctly specified in the system variables to avoid problems when running PHP.

Unpack the archive to any convenient location on the hard drive. Screenshot: Skillbox Media

After installing PHP, you need to notify the system of its presence. To do this, right-click on "This PC", select "Properties", then go to "Advanced system settings" and open the "Environment Variables" section.

Screenshot: Skillbox Media

Select «Path» at the top and bottom of the menu and click "Edit". A window will open in which you need to click "New" in the right menu. Then, specify the path to the folder with PHP installed, for example, C:\Program Files\php-8.1.0. Complete the process by clicking «OK».

Here we enter the path to the folder where PHP is located. Screenshot: Skillbox Media

To make sure that PHP is installed on your computer, open the command line and enter the command php -v. This command will display the current PHP version, confirming successful installation. If the PHP version is displayed correctly, you're ready to develop applications in this language. Otherwise, you may need to install or reinstall PHP.

If PHP is installed correctly, you will see something like thisScreenshot: Skillbox Media

To run PHP code, you need to create a text file with the .php extension and add the appropriate code to it. For example, you can use the following code:

We created a file with the .php extension and wrote code in it that displays "Hello world!"Screenshot: Skillbox Media

Go to the folder where this file is located. Right-click and select "Open PowerShell window here." This will launch PowerShell directly in the desired directory, making it easier to run commands and work with files in that folder.

Open PowerShell to run the PHP codeScreenshot: Skillbox Media

In the window that opens, enter the command php test.php. After executing this command, your string should be displayed in the console. Make sure you have PHP installed and the runtime environment configured correctly to avoid potential errors.

If the line appears, then PHP is working. Screenshot: Skillbox Media

Before starting the installation, be sure to update your operating system. This will help avoid potential errors and failures during the installation process. Keeping your system up-to-date ensures stable operation of your software and improves its compatibility with new versions. Make sure all necessary updates are installed before proceeding with the installation.

First, install PHP. This is necessary for your web application to function and handle dynamic content. Make sure you have the latest version of PHP installed that meets your project's requirements. After installation, verify that it works correctly by running a test script. Remember to consider PHP configuration settings, such as memory parameters and execution time, to ensure the stable operation of your application.

We have installed the latest version of the language, but to use its features, you must additionally install the repository. This will allow you to access all the new features and improvements offered by the updated version. Make sure you follow the installation instructions to get the most out of the update.

First, we need to install the prerequisites. This is an important step that will help ensure that all subsequent steps are performed correctly. Properly configuring the initial settings will help avoid potential errors and will significantly simplify the process. Ensure that all necessary components and resources are available and ready to use.

Reworking the text with SEO in mind requires emphasizing keywords and improving readability. Here is the adjusted version:

—

Next, it is necessary to consider the repository itself. The repository is an important element for storing and managing code. It enables collaboration on projects, tracking changes, and simplifies the development process. It is important to properly organize the repository structure to ensure easy access to the necessary files and documents. Regularly updating the repository and using a version control system will help maintain order in the project and prevent conflicts between development participants. It is also recommended to use clear and descriptive names for files and folders so that other developers can quickly navigate the contents.

Don't forget the importance of documentation, which should be available in the repository. It will help new project participants quickly understand its structure and functions. Thus, effective repository management is a key aspect of successful software development.

Let's update local packages to ensure the added repository can be used. This will allow you to access the latest software versions and improve system functionality. Regularly updating packages is an important part of maintaining optimal performance in your environment. Ensure all changes are applied to avoid incompatibilities and errors in the future.

Downloading PHP from the official website on a MacBook is impossible without installing additional programs. To do this, you need to install Homebrew, a package manager that simplifies the installation of various developer utilities. Homebrew allows you to easily manage software and install the necessary tools for working with PHP and other programming languages.

Go to the official website and copy the suggested command.

Screenshot: Skillbox Media

Open the terminal by going to the applications menu and By selecting the "Other" folder, then clicking "Terminal." Enter the following command in the window that opens.

Installation instructions will appear in the terminal. You'll need to add brew to your system path. Find the specified line and copy all the commands starting from it.

After that, return them back to the terminal, and the Homebrew installation will be complete.

To install PHP, use the brew install php command. This will allow you to quickly and conveniently install the latest version of PHP on your system. Make sure that Homebrew is already installed and updated to avoid possible dependency issues. Once the installation is complete, you can easily set up and use PHP to develop web applications.

Screenshot: Skillbox Media

To check that PHP is installed correctly, enter the php -v command in the terminal. This command will display the current PHP version, which will help you ensure that the environment has been successfully configured and is working correctly. Make sure you see the current version without errors to ensure all components are installed and functioning properly.

Screenshot: Skillbox Media

The console will display the language version you just installed. Verify that the installation was successful and the version matches the expected results. This will help you confirm that all settings are correct and you are ready to continue working with the programming language.

To write the code, we use the Sublime Text 3 text editor, which can be downloaded for free from the official website. We recommend creating a folder called Server in any convenient location on your hard drive and adding three files to it: index.html, handler.php, and styles.css. These files are essential for developing web applications and will help you organize the project structure.

The code for the main index.html page will be presented as follows:

This code is a form with a text field and a button. The action attribute of the tag defines the name and path to the script file that will process the entered data. In this case, it is the handler.php file. The method attribute specifies the data transfer method; in this case, the GET method is used. These methods are part of the HTTP protocol, which ensures interaction between websites and browsers. Correct use of the action and method attributes is essential for the correct functioning of forms on web pages.

Read also:

HTTP, or Hypertext Transfer Protocol, is the primary protocol used to transfer data on the Internet. It provides a standard way to exchange information between web servers and clients such as browsers. HTTP allows you to load web pages, images, and other resources, providing users with access to information in a convenient and structured form.

The HTTP protocol operates on a request-response principle: the client sends a request to the server, and the server returns a response with the required data. This makes HTTP a key element of web technologies, allowing users to interact with various sites and services. Modern versions of the protocol, such as HTTP/2 and HTTP/3, offer improved characteristics, including faster page loading and efficient use of network resources.

HTTP also supports various request methods, such as GET, POST, PUT, and DELETE, allowing you to perform various operations with web resources. Understanding how HTTP works is important for developers, SEO specialists, and anyone looking to optimize web content to improve user experience and increase visibility in search engines.

Let's create code for the handler.php script. This file will process incoming data and perform the necessary actions. It is important to organize the code so that it is understandable and easy to modify. Compliance with security standards and performance optimization also play a key role in development.

The first step will be connecting the necessary libraries and configuring the database connection parameters. Then, we will process the data received from the user, checking its correctness. Using prepared statements will help avoid SQL injections and ensure the security of the application.

After validating the data, you can proceed to basic actions, such as adding, updating, or deleting records in the database. Don't forget to handle possible errors so that the user receives clear messages in case of failure.

Finally, the script should return the processing result, informing the user of the actions performed. Proper code structure and competent data handling will make your handler.php script a reliable and effective tool.

At this point, I would like to draw attention to current events and their impact on society. It is important to understand how various factors, including economic, social, and political aspects, shape our perception of reality. By analyzing current events, we can identify key trends and predict possible scenarios. This allows us to make more informed decisions and build a strategy for the future. It is important to stay abreast of changes in order to effectively respond to the challenges of the times.

  • In line 1, we insert the link tag into the page's HTML code using the echo operator.
  • In lines 3–5, three arrays are created that contain information about fruits, vegetables, and berries. This type of data should be stored in a database and then retrieved from it, but for the sake of this example, we entered it manually.
  • In line 7, the $searchText variable is created, which contains the value entered in the text field. This value is taken from the $_GET array, in square brackets of which the name of the text field, which we defined in the index.html file, is indicated. This array is initialized when the form is submitted.
  • Lines 9–15 check whether the searchSubmit form button has been clicked. Then the entered value is checked and, depending on the type of product entered by the user, an array with the product data is set to the $products variable.
  • Lines 17–28 display the array as a table. As you can see, PHP distinguishes HTML tags from regular strings and displays the HTML table in the browser window using the echo function.
  • Line 22 iterates over our products array using the foreach loop.

To improve the appearance of the table, we need to create a stylesheet named styles.css. This file is included in the code of the handler.php file on the second line. Proper styling of the table with CSS will significantly improve its aesthetic appeal and usability.

The styles.css code is a stylesheet used to style web pages. It allows you to define various visual characteristics of HTML elements, including color, font, size, margins, and much more. Using CSS (Cascading Style Sheets) makes web design more flexible and manageable, allowing developers to separate the document structure from its visual presentation. Properly formatted styles.css is essential for improving the user experience. Optimized CSS code helps pages load quickly and improves their indexing in search engines. To achieve this, it is important to avoid redundant styles and use only the necessary rules. Furthermore, using media queries allows the design to adapt to different devices, which is an important aspect of modern web development. It is also important to remember the semantic formatting of CSS code. A clear structure and comments will help other developers quickly understand the logic of the styles. This is especially important when working in a team or when handing over a project. It is important to keep the styles used up-to-date and regularly update the file to comply with modern web design standards.

Thus, the styles.css file is a key component of web development, ensuring not only the visual appeal but also the functionality of the website.

Now you're ready to launch the web server. To do this, open a terminal and navigate to the directory where your files are located. To do this, enter the cd command, specifying the full path to your file folder, for example, C:\Program Files\Server on Windows. On macOS, the command will look like this:

Screenshot: Skillbox Media

To run the built-in PHP server on the local host, open the console and enter the command php -S 127.0.0.1:8000. This command will launch a server on IP address 127.0.0.1 with port 8000, allowing you to test your PHP applications and web pages locally. Make sure you have PHP installed on your computer to run this command successfully. After the server starts, you can open a browser and go to http://127.0.0.1:8000 to access your project.

Screenshot: Skillbox Media

The server has been successfully launched. Now open your browser and navigate to http://127.0.0.1:8000/. You'll then be able to see your website.

Enter "Fruits" in the field and click the "Search" button. This will give you access to a wealth of information about fruits, their health benefits, recipes, and more. Use search for up-to-date fruit-related data and recommendations.

Screenshot: Skillbox Media

The main page index.html has loaded. The web server redirected us to execute the handler.php script, which displays the fruit table on the screen. Pay attention to the address bar:

This is what our get-request looks likeScreenshot: Skillbox Media

After the question mark, the name of the parameter is indicated, for example, the name of the searchText field, after which its value is determined using the equal sign (=). If necessary, you can pass multiple "name=value" pairs, separated by an ampersand (&). However, it is not recommended to use the GET method for transferring large amounts of text or sensitive information, such as a username and password. In such cases, it is better to use the POST method, which provides greater security and allows you to transfer data without size limits.

Through in-depth study, for example, as part of the "PHP Developer from Scratch" course from Skillbox, you will gain the necessary knowledge about PHP interaction with databases. You will become familiar with the basics of the object model, learn how to execute asynchronous requests without reloading the page, and master the principles of designing the architecture of high-load systems. This course will provide you with all the key skills for successful PHP development.

Conclusion

PHP continues to be one of the most popular programming languages ​​in modern web development. If you're still unsure whether to start learning PHP, know that this language offers numerous opportunities for career advancement and project development. Proficiency in PHP will open doors to the world of web development, allowing you to create dynamic and interactive websites. Success in mastering PHP depends on your desire and effort.

See also:

  • 13 Tools of a Great Backend Developer
  • Test. Can you speak the same language as a web developer?
  • How to sort an array in PHP in thirteen ways: instructions with examples

The profession of PHP developer from scratch to PRO

You will learn from scratch how to program websites and web applications in PHP, Master the Laravel framework, build cloud storage, and develop a hotel booking service. You could land a Junior Developer position.

Find out more