When it comes to getting started with web programming there can be a lot of choices to consider, but one of the most popular and easiest to get started with is PHP. I want to write a basic series of tutorials on how to get into PHP programming to build web applications.
Everyone gets started somewhere and whilst I can no long remember the details of how I got started, I am relatively sure that the first step must have been getting a web server and development environment set up.
I am going to offer my thoughts on getting an environment setup for both Windows (WAMP = Windows + Apache + MySQL + PHP) and for Linux (LAMP = Linux + Apache + MySQL + PHP)
Windows
The setup for WAMP is going to be very simple as I am going to recommend the use of a kit called WampServer (http://www.wampserver.com/en/)
"WampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database. Alongside, PhpMyAdmin allows you to manage easily your databases."
It is a simple standard installer. I recommend following the defaults in the install wizard, and in no time you will have a complete WAMP server setup and ready for you to start creating your web apps.
Note : By default WampServer will put it's data and everything relevant into a directory on the main hard drive : C:\wamp\ which will require administrative rights on the PC.
The webroot and the place to start putting your PHP scripts will by default be : C:\wamp\www\
You can test to see if it's running by opening a new tab in your browser and putting localhost in the address bar, and you should get a webpage that looks something like this.
You should also see a small icon added to the Windows system tray. This powerful little tool lets you enable and disable modules and modify the configuration as required. The default settings will work to begin with, but down the track, depending on your requirements it may need to be tweaked.
Note : For advanced users, WampServer has the capability of being setup with multiple versions of Apache2, PHP and MySQL and can switch between them in order to test code compatibility with different versions of PHP and so forth.
If you are a Windows user and have got the WampServer page similar to what is shown above then you are ready to move on to the next step.
Linux
Because of the nature of Linux and the variety of distributions you can choose, the instructions here may differ if you aren't using Ubuntu.
I will assume that if you are setting up a LAMP server on Ubuntu (or other distro) that you are already familiar with basic use of a Linux system and are able to open a terminal emulator and can use sudo.
Ubuntu and Debian based distributions usually have access to an application called tasksel which is the easier way to get a LAMP server installed and the basic configuration done.
Open a terminal and install tasksel by typing : sudo apt-get install tasksel
To install LAMP we then run tasksel and select the LAMP server option from the list of software to install. In the same terminal, type : sudo tasksel
During the installation you will be asked to provide a MySQL root password. This is to protect the MySQL database server from unauthorised access.
Once that is complete, you should have the basic LAMP server installed and running.
Before we close that terminal lets get a basic test to make sure it's working. Run : sudo echo "<?php phpinfo(); ?>" > /var/www/info.php
This should create a test page that will output a whole lot of information about the PHP configuration. Test it by opening a new tab and putting localhost/info.php in the address bar.
Once last step in order to get a similar setup that WampServer provides for the Windows users is to install PhpMyAdmin. You can do this in the terminal by typing : sudo apt-get install phpmyadmin
Once installed it will be available by going to http://localhost/phpmyadmin/ in the web browser and logging in as root with the password you configured during the install a few minutes ago.
Additional Linux Requirements
One difference between the setup on a Windows PC and a Linux PC, especially when it comes to new users to Linux is the issue of permissions.
There are many ways to address this issue but one that I have used in the past for experimenting with PHP on my own Linux machines is to create a directory for my project in the /var/www directory. (For example, in a terminal run : sudo mkdir /var/www/myproject ) Then give my ownership of the directory (sudo chown me:me /var/www/myproject)
Then edit the code in your editor under the directory you just setup.
This is probably not the best way of doing things and it's definitely not what you want on a production machine. This is a quick hack to be able to experiment while learning on your own machine.
Code Editors
Windows
To begin with for Windows users I can recommend Notepad++. It is a lightweight notepad application with basic functions such as syntax highlighting. It is easily extended with plugins and a great way to start before you require a full featured editor with code completion and more.
There are many other full featured editors and IDE's that are great tools for coding PHP. Once I have used quite a lot is Netbeans. Netbeans is a free IDE that uses Java and is an open source project supported by Oracle. It supports many languages including PHP (and Java, C++, etc) and can be extended with plugins. But can be rather heavy on resources.
Otherwise I'm sure a Google search for PHP IDE will turn up a large number of result.
As previously mentioned your php application code will be under c:\wamp\www\ if using the default settings for WampServer.
Linux
For Linux you can get started with the default editors provided by your desktop environment. e.g. Gnome = gedit.
If you require more options you can easily search in the package management tools of your distro (such as the Software Center in Ubuntu) and look for php ide.
It's worth noting that Netbeans should be available or at least capable of being downloaded and run on Linux. Check the package manager tools before downloading it manually.
Soon I will write and publish the next article : Beginning PHP : Basic coding in which I will go through the basics of what you need to understand PHP coding. It will cover variables, flow and the traditional hello world as a precursor to jumping into our first full application.
Stay tuned.
No comments:
Post a Comment