📖 Intro to PHP
PHP is a widely-used open-source programming language designed for creating dynamic web pages. PHP code is embedded within special <?php ?>
tags to interact with HTML and can perform various tasks such as:
- Making decisions through conditional statements
- Performing calculations
- Interacting with databases
- Writing HTML dynamically
Using PHP
Unlike front-end languages (like HTML, CSS, and JavaScript), PHP is a server-side scripting language. This means the code is executed on the server before the output is sent to the client's browser. As a result, only the processed HTML, CSS, and JavaScript are visible to the user—PHP code is not.
To ensure your PHP files are processed correctly, they must have a .php
extension. Here's a basic example of how PHP code is embedded within HTML:
<?php
echo "Hello, World!";
?>
This will display the text "Hello, World!" in the browser. You can also use PHP to output more complex HTML:
<?php
echo "<h1>Welcome to My Website</h1>";
echo "<p>This is a paragraph of text.</p>";
?>
Working with MySQL Databases
MySQL
is an open-source database management system that works seamlessly with PHP. It allows you to store, retrieve, update, and delete data using SQL (Structured Query Language)
. PHP scripts can interact with a MySQL database to manipulate this data efficiently.
If you're new to MySQL or SQL, don't worry—we will cover the essentials in this course. However, if you are unfamiliar with SQL, I recommend concurrently taking ITSE 1303 - Introduction to MySQL to deepen your understanding of database queries and management.
Running PHP
As PHP is a server-side language, it must be executed on a web server to function. For this course, you will upload your PHP files to a dedicated class server where they can be run and graded. You are welcome to test your pages directly on this server, but keep in mind that every time you make a change, you'll need to upload the updated file to see the result.
Alternatively, many students find it more convenient to test their PHP code locally on their own computers. To do this, you'll need to install a web server environment that can process PHP code. Popular software bundles like XAMPP (for multiple operating systems), WAMP (for Windows), and MAMP (for Mac) come with everything you need, including Apache (a web server), MySQL, and PHP, all in one package. Another option is UWAMP, which runs off a USB stick for portability.
Web Server Options
- XAMPP
- Compatible with multiple operating systems. Includes Apache, MariaDB (a MySQL replacement), and PHP.
- WAMP
- A Windows-specific stack that includes Apache, MySQL, and PHP.
- MAMP
- A Mac-specific stack that includes Apache, MySQL, and PHP.
- UWAMP
- A USB-compatible version for Windows that runs Apache, MySQL, and PHP.
PHP Editors
To write PHP code effectively, it's recommended to use a text editor that provides useful features like syntax highlighting and error detection. While PHP code can be written in any basic text editor, using an editor like VS Code can significantly enhance your coding experience.
- VS Code
- A versatile editor by Microsoft that works on Windows, Linux, and Mac. It includes a wide range of extensions for PHP, HTML, and more, including debugging tools and integrated version control with Git.
FTP Client Software
To upload your PHP files to the class server for submission, you'll need an FTP client
. This software allows you to transfer files between your local machine and the remote server. Many FTP client options are available, but I recommend Filezilla, an open-source FTP client that's widely used and reliable.
Even if you test your PHP code locally, you will still need an FTP client to submit your assignments. Here's a link to download Filezilla.
Summary
- PHP is a server-side language, meaning code is processed on the server before being sent to the browser.
- You can choose to run PHP on a local server using software bundles like XAMPP or directly on the class server.
- PHP works hand-in-hand with MySQL to interact with databases. If you're new to MySQL, consider additional SQL study to reinforce these concepts.
- Use VS Code to make your coding experience more efficient.
- Finally, use an FTP client like Filezilla to upload your files to the class server for grading and testing.