Learn Coding #1 - Installing the Apache Server & quickstart in coding php
As told in my introduction post I am a programmer.
I want to start a series about learning to code php. Starting now with installing the Apache Server. Actually I am mainly coding PHP, that is why I decided on making a "Learn Coding php" series. Starting today...
When do I want to use PHP?
Instead of using HTML for static webpages we use a combination of PHP and HTML to craft dynamic webpages. For example guestbooks, log ins or content management systems. We also have the possibility to connect to a database and use its data via PHP.
You also have the chance to make dynamic websites with JavaScript, but other than PHP, JavaScript is executed on the clients computer instead on a server. But to fetch data from a database you would still need to use PHP. At last you can combine (or better "should" combine) PHP, JavaScript and HTML to create a website.
It is possible to code some small applications in PHP (like I said, guestbooks f.e.), but it is also possible to code more complex applications (Whole websites. Your own social network maybe? ;)). For that it is recommended to use frameworks. A good example for a PHP Framework is the Yii Framework. I don't want to get detailed about that right now because I want to keep this as simple as possible for beginners. But as soon as we hit "object-oriented-programming" with php I will tell you something about those Frameworks. (As @ninjamike replied, there are also Frameworks like Spring (Java) or Ruby on Rails, they can also be used to create dynamic webpages. When it comes to frameworks in this tutorial series I will pick them up again. If not, I hope that ninjamike will remind me.)
But befor we can go any further with coding PHP, we need an Apache Server...
What exactly is an Apache Server?
The Apache Server is used to "execute" the php code and send the result via http back to the requesting user. Other than html php has to be compiled first so that it can be send to the users browser afterwards.
So how do I install an Apache Server on my mashine?
Just for development and our purpose here you can install "XAMPP" from their website. XAMPP is available for Windows, Linux and OS X.
It includes:
- Apache
- PHP
- Perl
- MariaDB (which we will be definitly needing in the course of this tutorial series)
When installing you should use the folder provided by the installer. I already ran into funny errors when doing otherwise.
Installation is completed, what do?
When the installation is finished you should open the XAMPP Control Panel.
On Windows Mashines you can find it here:
C:\xampp\xamp-control.exe
Once opened you can see the modules, one of it is our needed Apache.
If it is not started already then do so by clicking on the start button on the button panel right next to "Apache". (If there is already a port declared or a button reads stop then everything is good so far.)
To test if the Apache is running, open your favourite web browser and enter localhost as URL.
A XAMPP Page should open. If not, maybe your Apache Server is not started yet.
Now up to the first programming steps...
The folder where the php magic happens is:
C:\xampp\htdocs
You will find some files in there. They can stay there. What you should do is create a new folder inside the htdocs folder named tutorial.
Well you can name it whatever you want. :-D
Inside of this folder create a file. for now we will call it test.php
Once created, open this file inside of any text editor.
At first we enter our php code as following:
<?php
echo "It works!!!";
?>
To open our creation inside a webbrowser we have to input the URL as this:
localhost/tutorial/test.php
You have to use folder and filename what you have chosen to call them.
When you did everything right, your browser should now show "It works!!!".
Well that's enough for the first post.
In the next post I would like to tell you something about variables and types. And start working with them.
If there are any questions then feel free to state them as a reply to this post.
So if you want to keep in touch then follow @smooms. I appreciate every upvote and resteem.
Have fun and till then.
One idea I had is that you could provide some background on PHP for us. I think knowing when and why PHP is used would help better motivate me to learn it. What type of websites would you use a language like PHP or Python for and which ones would you use a framework like Spring or Ruby on Rails?
That's a good point you have there. All I wanted to do till now was to provide a tutorial even for beginners. I planed on writing about frameworks later on. But I think it is important to know something about object oriented programming first. So I want to take this thing one step at a time. When and why php is used should be cleared up too. I think you are right on that one. I think I will update that tomorrow after all my daylies are done.
So you potentialy are interested in learning a programming language?
Thank you for the constructive criticism. I realy appreciate that.
I learned JSP and Servlets in college but they aren’t that practically useful in the real world. They are really best just for educational purposes. Picking up a language like PHP which is more commonly used could be useful for me.
Soooo, I updated the post. I never did tutoring before. And, to top it all off, english is not my native language. I hope that I am not butchering this tooooo much. :-D
But if you have questions, then feel free to state them. It's a good way for me to grow into this as well. :)
Thanks, for your hard work. This helped clear it up for me and I think it is well written.