Web Programming TutorialsIntroduction to PHP

Introduction to PHP

We will have some introduction to PHP and learn the installation of PHP in this Introduction to PHP tutorial.

  • What is PHP?
    • PHP stands for PHP Htpertext Preprocessor.
    • PHP was developed by Rasmus Lerdorf in 1995.
    • PHP was developed to make dynamic and interactive websites quickly.
    • PHP is a server side scripting language, it means that PHP requires a server for execution.
    • It is a free and open source scripting language.
    • The PHP code is executed on server and the result is returned to the browser in the form of plain HTML.
    • PHP works with almost all databases. Mostly it is used with MYSQL database.
    • It is a loosely typed language. It means there is no need to define a datatype for a variable in PHP. The variable itself decides its datatype according to the value assigned to it.
    • PHP works on many platforms like Windows, Unix, Linux etc.
    • HTML is used for designing a website and PHP is used to write logic to make the website interactive with user.
    • PHP code is written inside

      . This tag is called as PHP tag. The PHP code is embedded in HTML using this PHP tag.

    • Programs written in PHP are saved with .php extension.
    • PHP is compatible to most of the servers used today such as Xampp, Apache, IIS etc.
    • Since PHP is compatible with most of the servers, platforms, databases; it is widely used in creation of web based applications.
  • Uses of PHP
    • PHP is used to create a user friendly interface.
    • Along with websites it can also be used to built desktop applications.
    • PHP generates web content/HTML.
    • You can use command line scripting with PHP.
    • It can be used in an object oriented or procedural manner.
    • It can create, open, read, write and delete files on server.
    • It can restrict unauthorized users to access some webpages in a website using sessions.
    • It can also be used to encrypt the data.
    • It can be used to perform all the database operations.
    • It is more secure, more usable and easy to learn language.
  • Installation
    • We now know that PHP is a server side scripting language and so we will require a server to run PHP programs.
    • You can use your host server or a platform like xampp/wamp server which provides apache server.
    • We don’t have to do anything to install PHP. The only thing is to install a server. Similar to javascript, PHP programs can be written in a text editor like notepad or notepad++ with .php extension.
    • And these written PHP programs have to be placed on server for execution.
    • We will download xampp server and install it on our PC, after which we will be able to run our PHP programs.
    • Follow the steps one by one to download and install the xampp server:
      1. Open your browser and go to apachefriends.org. Following page will open:
      2. xampp_server_website
        fig 1

      3. Now click on Download tab above in the horizontal menu bar. The following page will appear:
      4. xampp_download_page
        fig 2

      5. Download the setup by clicking on the download button and save it.
      6. Start the setup installation by double clicking on it. Following window will appear.
      7. Run_window
        fig 3

      8. Click on the Run button shown by the red arrow in the above figure.
      9. Wait for some time, after which following Setup window will appear:
      10. Setup_window
        fig 4

      11. Click on Next button as shown by the red arrow in the above figure. The following Select Components window will appear.
      12. Select_components_window
        fig 5

        8) Select the components you want to install and deselect those you don’t want to install in the list shown by the red arrow and then click on Next button. The following Installation Folder window will appear:

        fig 6

      13. You can choose the folder to install Xampp by your own by clicking the button shown by arrow. By default it selects C drive. Then click on Next button. The following Ready to Install window will appear:
      14. Ready_to_install_window
        fig 7

      15. Click on Next button. The following Bitnami for Xampp window will appear:
      16. Bitnami_for_Xampp_window
        fig 8

      17. Click on Next button. The following window appears:
      18. installation_begins
        fig 9

      19. The installation starts. Wait till the progress bar completes. After installation it will automatically show the next Completing the XAMPP Setup Wizard window as shown below:
      20. finish_setup
        fig 10

      21. Click on Finish button. Your Xampp installation is complete. After this immediately the following window will appear:
      22. xampp_control_run_dialog
        fig 11

      23. This window is asking if you want to run the xampp_control.exe or save it. Click on Run button as shown in the figure above. The following Xampp Control Panel will appear:
      24. xampp_control_panel
        fig 12

      25. This xampp server contains Apache, MYSQL, FileZilla server, etc. We need only Apache and MYSQL for PHP. It will work only when we start the Apache and MYSQL.
      26. We can allow the Apache and MYSQL to start along with windows by clicking on the cross sign besides it as shown below:
      27. start_apache_with_windows
        fig 13

        • When you click on the cross shown by the arrow, a dialog box appears asking you to Click Yes to install the Apache service.
        • So click on the Yes button and the red cross sign will change to the green color tick mark sign as shown below:
        • cross_changed_to_tick
          fig 14

        • Follow the same process for MYSQL to start it with windows.
      28. You can also start it by clicking on the Start button in front of Apache and MYSQL. When you click on it, the text of the button will change from Start to Stop and vice-versa. Just see in the figure below:
      29. apache_&_mysql_started
        fig 15

        • You can see the text changed from Start to Stop as shown by arrow. This means our apache and MYSQL has been started.
      30. Now close the xampp control panel.
      31. We know that there should be a password for a database for security purpose. We have MYSQL in Xampp, so we will be using it with PHP. But MYSQL do not have password by default. So let us set a password for MYSQL. Follow the steps:
        1. Open the browser and type localhost in the address bar.
        2. A splash.php page will be opened, which is inside the xampp folder as shown below:
        3. xampp_running_in_browser
          fig 16

          • This shows that now our xampp is successfully installed without any error.
        4. Next step is giving password to MYSQL.
        5. Click on the English link shown in the above figure. Following page will appear:
        6. index_page_from_xampp
          fig 17

        7. In the page appeared click on Security which is shown using the black color arrow in the above figure. Following page will appear:
        8. page_appeared_after_selecting_Security
          fig 18

          • In this page above you will notice the statement, The MYSQL admin user root has NO password.
        9. Now click on the link http://localhost/security/xamppsecurity.php which is placed at the lower side of the page shown above.
        10. After clicking on the link following page will open which will allow you to set the password:
        11. password_window
          fig 19

        12. Enter your password in the above fields for new password and repeat password as shown in the above figure and then click on Password changing button.
        13. After you click on the Password changing button you will get a message saying The root password was successfully changed. Please restart MYSQL for loading these changes!
        14. For this just open the xampp control panel. Click on the Stop button in front of the MYSQL to stop the MYSQL service and again click on the Start button in front of the MYSQL to again start the MYSQL service.
        15. Thus we have successfully changed the MYSQL password and restarted it.
      32. Let us just see the folder where we have to place the PHP programs for execution.
        • Just go to your xampp folder in C drive or where you have stored the xampp folder by giving path during installation and open it.
        • You will find the htdocs folder inside xampp folder as shown below:
        • xampp_folder
          fig 20

        • You need to place your PHP program inside this htdocs folder for execution.
        • We will run a simple program in next lesson.

    Thus we completed installation of xampp as well as provided security to MYSQL by setting its password in this Introduction to PHP tutorial thus creating an environment suitable to run PHP programs.

Previous articleMY TASKS Project Part – 1
Next articlePHP Basics


Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article


More article

- Advertisement -