Lecture 16: Intro to PHP

To-do for today’s class

  1. Download starter file: lect16-intro-php/ (Dropbox)
  2. Download MAMP (for both Mac and Windows): https://www.mamp.info/en/downloads/
    1. Both MAMP PRO and MAMP may be downloaded but we will only be using MAMP (the free version). MAMP PRO is not required for this class.
  3. After opening MAMP, select PHP version 7.4.* on the bottom of the main panel.
  4. Click on the “Preferences” gear icon on the top left of the main panel.
  5. In the “General” tab, select the dropdown next to PHP-cache and select “off”. This will prevent MAMP from caching and allow you to see instant updates.
  6. Click on the “Server” tab.
  7. Change the Document root folder to the folder that contains all your ITP 303 files. Click on “Choose” button to navigate to the folder and select it.
  8. Locate the php.ini file, which is a configuration file that allows you to configure many aspects of PHP.
    1. Mac: /Applications/MAMP/bin/php/php{version_num}/conf/php.ini
    2. Windows: C://MAMP/conf/php{version_num}/php.ini
  9. Search for display_errors. You will see a few results. Look for a statement that reads display_errors = Off, which is around line 472.
  10. Change this line so that it reads display_errors = On. Note the capital “O” on On. This will make PHP show errors on the browser while you write PHP. This is super helpful during development.
  11. You will need to restart the server if you already started the server. If you have never started the server before, click the “Start” icon on the top right of the main panel.
  12. Give it a few minutes to boot a simulated web server. You will notice a browser tab open up with the URL set to localhost.
  13. Refer to the official PHP documentation here: http://php.net

Slides

Link to download PDF version.

Resources

Completed files