DEV Community

Oluwajubelo
Oluwajubelo

Posted on

Introduction to PHP

I'll be writing about the series of events we're conducting in the TechHaven Mentorship Program for Backend Engineers here. This being the first week, we walked through how to install PHP and VSCode (Visual Studio Code) on Windows and macOS systems.

For Windows Users
Step 1: Download XAMPP

  • Visit this website to download: https://www.apachefriends.org.

  • Choose the XAMPP version that supports PHP 8.2. Look for entries
    like XAMPP for PHP 8.2.x.

  • Click the download link for your preferred version (Windows).

  • Save the installer file to your computer.

Step 2: Install XAMPP

  • Run the Installer:
  • Navigate to the folder where you downloaded the XAMPP installer (e.g., xampp-windows-x64-8.2.x-installer.exe).
  1. Double-click the installer to start the setup process.
  • Choose Installation Components:
  1. During the setup wizard, select the components you want to install. By default, essential components like Apache, MySQL, PHP, and phpMyAdmin are selected. Ensure PHP and phpMyAdmin are checked.

  2. Click Next to proceed

  • Select Installation Folder:
  1. Choose the folder where you want to install XAMPP (default is
    C:\xampp). You can change this if needed.

  2. Click Next.

  • Start Installation:
  1. Click Next to confirm your choices and start the installation.

  2. Wait for the installation process to complete. This may take a few
    minutes.

  • Finish Installation:
  1. Once the installation is done, you’ll see a confirmation screen. Check the box to launch the XAMPP Control Panel and click Finish.

Step 3: Configure and Verify Installation

  • Open XAMPP Control Panel:
  1. Launch the XAMPP Control Panel from your Start Menu or the installation directory.
  • Start Apache and MySQL:
  1. In the control panel, click Start next to Apache and MySQL.

  2. Ensure both services turn green, indicating they’re running.

  • Verify PHP Version:
  1. Open a browser and navigate to http://localhost/dashboard.

  2. To verify PHP 8.2 is installed, create a phpinfo.php file:

  • Navigate to C:\xampp\htdocs.

  • Create a new file named phpinfo.php and add the following
    content:

<?php
    phpinfo();
 ?>
Enter fullscreen mode Exit fullscreen mode

Step 4: Add PHP to System PATH (Optional)

  • Access Environment Variables:
  1. Press Win + S, type Environment Variables, and select Edit the system environment variables.

  2. In the System Properties window, click Environment Variables.

  • Add PHP Path:
  1. Under System Variables, find the Path variable and click Edit.

  2. Click New and add the path to the PHP folder, e.g., C:\xampp\php.

  • Save Changes:
  1. Click OK to save and close all windows.

  2. Restart your system and open your terminal, then type php -v , you should see something like this as response

PHP 8.2.0 (cli) (built: Nov 29 2023 12:00:00) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies

Enter fullscreen mode Exit fullscreen mode

For MacOS users:

Older macOS versions (prior to macOS Monterey) include PHP by default. However, the version might be outdated.
Checking if PHP is Installed: Open the Terminal (Command + Space, type Terminal, and hit Enter) and run:

php -v
Enter fullscreen mode Exit fullscreen mode
  • If PHP is installed, this will show the PHP version.

  • If not, you’ll get a message like command not found.

If PHP is Not Installed
If your Mac does not have PHP (common in newer macOS versions), you can easily install it using tools like Homebrew.

Installing PHP Using Homebrew

  1. Install Homebrew (if not already installed): Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode
  1. Install PHP: Run the following command to install the latest version of PHP:
brew install php 
Enter fullscreen mode Exit fullscreen mode

if you want to install a specific version of PHP, use this command

brew install php@version
Enter fullscreen mode Exit fullscreen mode
  1. Verify Installation: After installation, verify the PHP version:
php -v
Enter fullscreen mode Exit fullscreen mode
  1. Add PHP to PATH (if needed): Homebrew automatically adds PHP to your PATH, but if it doesn't work, add the following line to your ~/.zshrc file (for Zsh shell, default on macOS):
 export PATH="/usr/local/opt/php@<version>/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Then reload your shell configuration:

source ~/.zshrc  # or source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

To install MySQL, follow commands below

  1. Install the MySQL package:
brew install mysql
Enter fullscreen mode Exit fullscreen mode

if you want to install a specific version of PHP, use this command

brew install mysql@version
Enter fullscreen mode Exit fullscreen mode
  1. Once installation is complete, start the MySQL service:
brew services start mysql
Enter fullscreen mode Exit fullscreen mode

Verify MySQL Installation:

  1. Check the MySQL version to confirm installation:
mysql --version
Enter fullscreen mode Exit fullscreen mode

Example output:

mysql  Ver 8.0.x for osx on x86_64 (Homebrew)

Enter fullscreen mode Exit fullscreen mode
  1. Log in to MySQL as the root user:
mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Stop/Restart MySQL Service (Optional):

  1. To stop the MySQL service:
brew services stop mysql
Enter fullscreen mode Exit fullscreen mode
  1. To restart the MySQL service:
brew services restart mysql
Enter fullscreen mode Exit fullscreen mode

Configure PATH (if necessary)

Add the MySQL binary to your PATH (if not automatically added). Open your shell configuration file (e.g., ~/.zshrc or ~/.bash_profile) and add:

export PATH="/usr/local/opt/mysql/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Reload the shell configuration:

source ~/.zshrc  # or source ~/.bash_profile

Enter fullscreen mode Exit fullscreen mode

To Install VSCode on your system, kindly follow the steps below:
Step 1: Download the Installer

  • Visit the official VS Code website.

  • Click the Download for Windows/MacOS button. This will download the appropriate installer for your system.

Step 2: Run the Installer

  • Locate the downloaded file (e.g., VSCodeSetup-x64-.exe for windows users, .dmg file for macos users) and double-click to run it.

  • Follow the installation wizard:

  1. Accept the license agreement.

  2. Choose the installation location (default is fine for most users).

  3. Select additional options, such as:

  • Adding VS Code to your system PATH (recommended).

  • Creating a desktop shortcut.

Step 3: Launch VS Code

  • Once the installation is complete, open VS Code by clicking the shortcut or searching for "Visual Studio Code" in the Start menu.

For MacOS users:
After downloading the .dmg file
Step 2: Install VS Code

  • Open the downloaded .dmg file.

  • Drag and drop the Visual Studio Code icon into the Applications folder.

Step 3: Add VS Code to PATH (Optional)
To use VS Code from the terminal:

  • Open VS Code.

  • Press Cmd + Shift + P to open the Command Palette.

  • Type Shell Command: Install 'code' command in PATH and select it.

  • Restart your terminal and verify by typing:

code
Enter fullscreen mode Exit fullscreen mode

Top comments (0)