0% found this document useful (0 votes)
12 views

Lab03-PHP01 V1.02 - updated

Uploaded by

Chloe Tee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab03-PHP01 V1.02 - updated

Uploaded by

Chloe Tee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB 03

PHP

Setting up MySQL and Php on Windows with XAMPP


Reference: https://www.wa4e.com/install.php
XAMPP is an abbreviation for cross-platform, Apache, MySQL, PHP and Perl, and it allows
you to build WordPress site offline, on a local web server on your computer.

1. All the labs for this subject will be performed in Windows platform. However, you
are welcome to use any other platform you are familiar or comfortable with.

2. Download XAMPP from the following website,


https://www.apachefriends.org/index.html

3. Once the download has been completed, install the XAMPP with administrator
rights.
4. If you received the following error, please make sure that the installation directory of
XAMPP is C:\xampp
- Reference: https://stackoverflow.com/questions/26208848/xampp-installation-on-
win-8-1-with-uac-warning/26209109
-

5. Double check the installation directory, it should be C:\xampp. Complete the


installation.

6. Skip this step and the following step if you do not have VMware Workstation
installed on your machine. You will receive the following error when you try to start
apache. This happens because the VMware and Apache is using the same port which
would result in the error.
7. To change the port, I would recommend changing the Vmware port instead of the
apache port number. Refer the following reference and make the changes accordingly.
- Reference: https://stackoverflow.com/questions/21182512/how-to-stop-vmware-
port-error-of-443-on-xampp-control-panel-v3-2-1

8. Click Start for Apache and MySQL, you should see “status change detected: running”
for both module/services.
9. To verify the Apache installation, open a browser, type in http://localhost.
Screenshot the output.

10. To verify the MySQL installation, open a browser, type in


http://localhost/phpmyadmin/. Screenshot the output

11. To view the php version and settings installation, create a basic phpinfo.php page
to view the settings of the php installed.

12. Go to the following directory, C:\xampp\htdocs. Create a new file call


phpinfo.php. Open the file with your text editor (Atom, notepad++…).

13. Type in the following code into your notepad.


<?php phpinfo(); ?>

14. To check the settings and version, go to your browser, and type
http://localhost/phpinfo.php If you have done everything correctly, you should see a
page containing all the php information. Screenshot the output
Creating a Basic Php Script

15. Create a simple php script as given below. Replace the name with your own name.

<h1>Hello from Chew html page!</h1>

16. Save the file as firstcode.php in C:\xampp\htdocs\[aProjectName].


Open up a browser, type localhost/[aProjectName]/firstcode.php.
You should see the “Hello….” From your browser. Screen the output.

** Notes: You can insert HTML code in Php, but you cannot insert Php code in HTML.
Reference: https://www.quora.com/Does-PHP-go-into-the-HTML-code

17. You may utilize the previous file, and type in the following code. Replace “chew”
with your own name. Screenshot the output of the following code.

<h1>Hello from Chew html page!</h1>


<?php
echo "<p> Hi there.\n New Line </p>";
//There are actually a new line but not displayed in the
HTML, Use Right click inspect element to check the new line.
$answer = 6 * 7;
echo "<pre>The answer is $answer, what was the question
again?\n</pre>";
?>
<p>Yes another paragraph.</p>

** Note: you will not see a new line from your browser view because the new line is only
generated in the html context, a new line in the html context does not make a different.

** To make the newline visible in the html, you can either use the <br> tag or <pre> </pre>
tag

Reference: https://stackoverflow.com/questions/12410695/new-line-n-in-php-is-not-working

You might also like