How to start programming in PHP, configuring Apache

Are you wondering how to start programming in PHP? You are in the right place. In this tutorial I am going to explain how to configure your computer with the necessary tool to start programming PHP now.

Let’s start with the concept of web server. Specifically, I will talk about:

  • What is Apache and why is it vital to be able to execute PHP code
  • How to install Apache using XAMPP
  • How to configure XAMPP in a basic way so that you can start programming from now on.
  • Where to put PHP scripts
  • How to view and execute your php code
  • Fix possible XAMPP errors

Content

  • Why a server?
  • Install Apache on Windows
  • Where to download the server?
  • Installation of Apache and other components
  • How is XAMPP used?
    • 1. Server boot
    • 2. Placement of files
  • Possible errors when installing XAMPP

Why a server?

When working with php, and running for example your first Hello World! script, you will need software that can read and execute that code. This software is none other than the server, which has as one of its main functions to interpret the PHP code.

As a server, to test and develop our php scripts we will choose Apache serversince it is free and will work on Windows, Mac or GNU/Linux.

He apache http server is an open source webHTTP server, for Unix (BSD, GNU/Linux, etc.), Microsoft Windows, Macintosh and other platforms, which implements the HTTP/1.1 protocol and the notion of virtual site.

Install Apache on Windows

Well, although I have commented that it is possible to install Apache on either Linux or Mac, I am going to focus on explaining the installation process on Windows.

For install apache under Windows, I am going to do it through free software. Thus we have 2 possibilities, WAMP or XAMPP. Both one distribution and the other come with a fairly complete configuration panel, with WAMP being the one with most of the configuration parameters that is most accessible, but which will be equally configurable with either of the two options. Manually configuring a module or server parameter is as easy as using a text editor like notepad, or even better Notepad++ (a wonderful tool, by the way).

Where to download the server?

As easy as going to the XAMPP website and downloading the latest version available. In the case of our example we will download the version indicated for PHP 7.0.4.

Installation of Apache and other components

The installation of XAMPP is the typical installation, which is practically based on pressing next (in this case next) until it is finished. But I do think it is convenient to stop and comment on the component selection section. We should only install what is just and necessary to work on the development of our websites, and the essential components for this are:

  1. Apache, is the core of the system and it won’t even let us uncheck it.
  2. Filezilla, the FTP client to upload files to a future paying server to a hosting vendor.
  3. MySQL, which will allow us to host our database for more complex web applications.
  4. phpMyAdmin. A php application that is a graphical interface for the administration of our databases

How is XAMPP used?

Using xampp requires very little knowledge and starts in a minute. The first thing you should do after installation is to find the XAMPP shortcut on the desktop or start menu. So that? Well, to be able to start Apache in the first instance if what you want is simply to run the PHP language, or start the service of other components or programs for more advanced use.

1. Server boot

In the XAMPP panel we will start the Apache server. A colored rectangle will indicate if everything went well or if, on the contrary, a problem has arisen:

  1. Green will indicate that everything has gone well and is ready to be used.
  2. Yellow requires our attention, and it may be, for example, that the port is occupied by another service on our PC.
  3. Red means a more serious error and in most cases the quickest solution will be a restart of the PC, or in the worst case a reinstallation of XAMPP after having made the corresponding copy of our files.

2. Placement of files

To execute our hello world in php we just have to place the file that contains it in the folder that the XAMPP installation has created for us in the path c:/xampp/htdocs/. After this, we will go to the browser and write the address of our file so that the server reads the code and shows us the result. The address will always start with localhost/ and then the route will go to the file that we want to see. For a basic index.php file it would be localhost/index.php.

On Windows, Apache may not start and a port change is required on our part. A recommended port will be 8080 or another that is not in use.

Possible errors when installing XAMPP

Although XAMPP installations are simple and usually work the first time on any Windows or Mac installation, it is possible that you have a problem starting it and it stops again.

The most common error in XAMP startups is caused by problems with apache port.

By default Apache uses port 80, this is a port commonly used in certain Windows software like Skype or other programs. You can search the internet for more information to see all the programs that conflict with this port.

If you want to solve it, you will have to change the XAMPP port or, what is the same, change the Apache port.

A commonly used port to replace port 80 is 8080, although you can choose whatever you see fit.

Leave a Reply