New Posts  All Forums:Forum Nav:

PHP tutorial #1.

post #1 of 6
Thread Starter 
PHP class 1 :: Setting up the server & Testing.


This article only supports Windows and Linux OS (I don't have a MAC)


Welcome to my PHP class. If you haven't noticed some of my other tutorials, check this thread out here.

I have a new color code for my tutorials:

HTML

CSS

PHP





As with the HTML guides we are going to jump right into the code. But wait. PHP requires a server. So, go and buy a shared server from a reputable vender Install a server on your machine.

The server we are going to use is known as a WAMP/LAMP/MAMP stack. Windows Apache MySQL and PHP. L = for Linux systems and M = for Mac OS systems.

Windows servers:

There are a lot for windows, and I recommend XAMPP and WAMP. A simple web search will throw this up. Just make sure to install everything like Tomcat and Filezilla as a service. To install on Windows is really easy (just make sure you get the right architecture!)

For Linux, it's a bit more complicated, though. As this is a webserver I assume lots of machines will be running Linux. This guide is based on Ubuntu/ Debian and for other OS you should check the documentation or the net.
Linux install: (Click to show)
APACHE
1. Open up the terminal and paste this into it:
Code:
sudo apt-get install apache2
2. Put a STRONG password in.
3. Not to test apache. Open any web browser and navigate to the following address; http://localhost and you should be met with something like "yay, it works!"

PHP
Now we need to install PHP.
1. Open up the terminal and enter the following:
Code:
sudo apt-get install php5 libapache2-mod-php5
2. In order for Apache to recognise PHP, and thus make it work, we need to restart it. Type:
Code:
sudo /etc/init.d/apache2 restart
3. Now we will test PHP to make sure it works. Type:
Code:
sudo gedit /var/www/testphp.php
into the terminal to edit the default test page for PHP.
4. In gedit, type:
Code:
<?php phpinfo(); ?>
5. Now, save it.
6. Navigate to it in browser, @ http://localhost/testphp.php and you should see a page of PHP info. You have successfully just used PHP and made a page!

We have now installed WAMP (for Windows users) or apache and PHP (for Linux users)

Note to Linux users: if you want to use MySQL DB's you will need to install that also. It is not essential here so I will leave it out.

Right, we now have a server. We can now go about and tell people we use a server! tongue.gif

PHP class 1 :: Creating our first PHP file


First things first open file manager (or explorer for Windows users) and navigate to where the contents of your web server are:

WINDOWS

C:/productname/www

With 'product name' obviously being the program you installed ie XAMPP, WAMP

LINUX

File system/Var/www

Now, right click and create a new empty file. Name it testfile2.php

.php is essential as it tells the browser that it's dealing with a PHP file and telling the server it needs to execute it, too.

Open the file and paste this into it:
Code:
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>

Line 1 is telling the browser that it's dealing with a HTML doc
Line 2 is starting the header of the doc
Line 3 is the page title (remember from the first HTML tutorial)
Line 4 ends the head and
Line 5 starts the main content of the page.
Line 6 is where it gets interesting.
echo is print, anything after it will be presented on screen.
The P tags are HTML paragraph tags
And the ?> ends the PHP

All words which will be printed need to be inside ' these' or it will not work. Now just save the file.

Now, lets call it up in browser. Navigate to:



You should see Hello world printed in the top left of the screen.

This is the end of the first tutorial, if people like it maybe I will make more.

Questions, comments etc? Just post them here or PM me.

Thanks,

Josh
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
post #2 of 6
Awesome man, great to see you doing these, would have helped me last Monday when I started my website haha.

Great nonetheless thumb.gif
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel i5-4570s Asus H97M-Plus AMD R9 280 G.Skill RipjawsX 16 GB (2x8) 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 240 GB Kingston 3 TB USB 3.0 Drive Custom Loop 
OSMonitorKeyboardPower
Windows 10 Preview BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Fractal Design Core 1000 Mionix Castor Monoprice XXL JL Amps + Custom Morel Bookshelf speakers 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel i5-4570s Asus H97M-Plus AMD R9 280 G.Skill RipjawsX 16 GB (2x8) 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 240 GB Kingston 3 TB USB 3.0 Drive Custom Loop 
OSMonitorKeyboardPower
Windows 10 Preview BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Fractal Design Core 1000 Mionix Castor Monoprice XXL JL Amps + Custom Morel Bookshelf speakers 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
post #3 of 6
Thread Starter 
Thanks Axi! Check out my other guides, although they are probably a little too basic for you if you have already built your own site thumb.gif
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
post #4 of 6
No problem, and you can see my site in a zip file on the post below. If you don't mind, could you take a quick look at it and give me some tips from a code stand-point, I've already got tons of design feedback and have made some changes, but the code itself hasn't really changed. I would appreciate it biggrin.gif

http://www.overclock.net/t/1234650/looking-for-someone-to-help-with-a-personal-website-design/0_50#post_16820103
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel i5-4570s Asus H97M-Plus AMD R9 280 G.Skill RipjawsX 16 GB (2x8) 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 240 GB Kingston 3 TB USB 3.0 Drive Custom Loop 
OSMonitorKeyboardPower
Windows 10 Preview BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Fractal Design Core 1000 Mionix Castor Monoprice XXL JL Amps + Custom Morel Bookshelf speakers 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel i5-4570s Asus H97M-Plus AMD R9 280 G.Skill RipjawsX 16 GB (2x8) 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 240 GB Kingston 3 TB USB 3.0 Drive Custom Loop 
OSMonitorKeyboardPower
Windows 10 Preview BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Fractal Design Core 1000 Mionix Castor Monoprice XXL JL Amps + Custom Morel Bookshelf speakers 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
post #5 of 6
Great tutorial.
Will you be doing any classes on MySQL?
I've used it a bit when making my first website but i would like to get a bit more experienced with it.
Skylake
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 6700k Gigabyte Z170X - Gaming 7 EVGA GTX 780 SC ACX Corsair Vengeance LPX 32GB (2400MHz) 
Hard DriveHard DriveHard DriveCooling
Samsung 840 250GB Samsung 850 Evo 500GB Western Digital 1TB XSPC Raystorm + EX240 Radiator 
OSMonitorKeyboardPower
Windows 10 Pro Dell U2414H x 2 Logitech G510 Corsair RM650 
CaseMouse
Fractal Design Define R5 Corsair M60 
  hide details  
Reply
Skylake
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 6700k Gigabyte Z170X - Gaming 7 EVGA GTX 780 SC ACX Corsair Vengeance LPX 32GB (2400MHz) 
Hard DriveHard DriveHard DriveCooling
Samsung 840 250GB Samsung 850 Evo 500GB Western Digital 1TB XSPC Raystorm + EX240 Radiator 
OSMonitorKeyboardPower
Windows 10 Pro Dell U2414H x 2 Logitech G510 Corsair RM650 
CaseMouse
Fractal Design Define R5 Corsair M60 
  hide details  
Reply
post #6 of 6
Thread Starter 
Quote:
Originally Posted by Kieran View Post

Great tutorial.
Will you be doing any classes on MySQL?
I've used it a bit when making my first website but i would like to get a bit more experienced with it.

Thanks for the comment. I've not really used MySQL a lot, but have a book on it. I will use it for a few days and then see what I can do smile.gif
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
Main Rig.
(14 items)
 
Battlefield 2 review.
Battlefield 2 PC Game EA
 
CPUMotherboardGraphicsRAM
Bulldozer FX4100 Gigabyte GA-M68MT-S2 MSI 7770 Kingston Hyper X | 2 x 2 GB 
Hard DriveOptical DriveCoolingOS
WD 2 TB  LiteON DVD/CD R-W Drive AMD Standard cooler Windows 7 Ultimate 
MonitorKeyboardPowerCase
32' Luxor Full HD TV Microsoft comfort curce Antec 450 Watt OcUK Value case 
MouseAudio
Microsoft wireless mouse Logitech speakers & Bass 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding