PHP is a interpreted scripts language.
It's not like HTML is a hypertext markup language, which will simply run when you open the file.
From the moment that the PHP interpreter starts to act, all the code entered inside the document begins to be processed. This processing generates an HTML file and in that file there will only be HTML tags or any other client-side technology that will be returned to whoever requested the file.
To be able to run files with .php
extension, you must have an Apache web server to turn the computer into a server that will interpret the scripts PHP, and not display the codes on the screen.
Although it is possible to download the "components" (Database, Apache, PHP) individually, it requires a reasonable knowledge to configure them, since it can be extremely difficult to configure them first time.
There are, however, some ready-made alternatives (programs) that are prepared with a default configuration, which comes with what you need, most of which is the PHP language, the MySQL database, and the Apache server. / p>
These programs are known as:
- WAMP's W indows, A pache, M andSQL, P HP)
- LAMP's L inux, A pache, M and HP, HP
- MAMP's M a, A pache, M andSQL, HP
You can see more information on these programs here .
Your problem
After reading this introduction and having the installed programs of your choice, when you start Windows, you need to "start" the server (in my case WAMP).
You click on the icon (on the desktop or the start menu or in the installation directory) and when it becomes "green" you can open a new tab of your browser and type in the address bar your configuration is the default) localhost or 127.0.0.1 .
Important: It is necessary for you to move the files (from your project) to the folder within your web server program (if you are using one of the programs mentioned above), such as XAMPP - htdocs folder - or WAMP - in the www folder - or create an alias
en .
Remember , PHP is an interpreted server-side scripting language, then open the files as HTML:
file:///C:/testes/meuarquivo.php
It will result in your code being displayed on the screen instead of being interpreted, regardless of what your browser is. So you should open it with the server protocol, something like:
http://localhost/testes/meuarquivo.php
Another important thing that I forgot to mention: If you are experiencing problems such as opening an unexpected page, or not opening anything, it is because (probably) you have some program you are using port 80 (default).
Programs installed such as Skype, or IIS (which is usually installed on most development machines) can cause this. Then you need to change the server port.
You can see more related information on the official website (in my case Wamp in ), or more information here .
I'll leave here a brief solution if you're using WAMP:
- Click the WAMP server icon > Apache > httpd.conf, then change the Listen 80 line to Listen 8080 or whatever port you want.
- If you can not access through the icon, go to the directory under C: \ wamp \ bin \ apache \ apache2.4.23 \ conf > httpd.conf and do what was said above.
You can watch this video also, which was indicated in the response that was linked above, answered in our Big Brother SO .