Martian Defense NoteBook
  • Martian Defense Notebook
  • Training and Career
    • Keeping it Real for Beginners
    • Reading and Repos
    • Media
    • Guides
      • Cybersecurity Roadmaps
      • Cybersecurity Training Topics
      • AppSec Training Pathway
      • Interview Checklist
    • Platforms
      • General
      • Offensive Security
      • Defensive Security
      • CTF Sites
      • Live Vulnerable Sites
    • Entrepreneurship Roadmaps
      • Consulting
      • Starting a Business
  • Technical Resources
    • Offensive-Cybersecurity
      • Application Security
      • General
      • Recon + OSINT
      • Infrastructure Pentesting
      • Cloud Pentesting
      • Wordlists
      • Social Engineering
      • Mobile Pentesting
      • Container Security
      • Blockchain
    • Defensive-Cybersecurity
    • General Cybersecurity
      • Cybersecurity Operating Systems
    • Coding/Programming
    • Reverse Engineering
    • AI and ML
  • Notes
    • Product Security Engineering
      • DevSecOps
        • Docker
          • How to Dockerize Applications with Docker Compose (Using SQLite and Flask)
      • SAST/SCA
        • How to setup a GitHub Action for Code Security analysis
        • JavaScript Security Analysis
        • Java Security 101
        • Tools
        • CodeQL for Beginners
      • Product Security Hardening
      • Threat Modeling
      • PHP Security
    • AppSec Testing
      • Checklists
        • WEB APP PENTESTING CHECKLIST
        • API Testing Checklist
        • Android Pentesting Checklist
        • IoS Pentesting Checklist
        • Thick Client Pentesting Checklist
        • Secure Code Review Checklist
      • Targeted Test Cases
        • Part 1
        • Part 2
      • Common Web Attack and Prevention List
      • Ports and associated Vectors
      • DNS
      • Web Tools
      • Command Injection Testing
      • JWTs and JSON
    • Security Research
      • Publishing CVEs
      • Threat Intelligence
      • Shodan Dork Cheatsheet
      • Github Dorks
      • Bug Bounty
        • Bug Bounty Programs
      • Forums
    • Coding/Programming
      • Secure Coding Practices Checklist
      • JavaScript
      • Python
        • Quick Notes
        • Python Basics for Pentesters
        • Python Snippets
        • XML Basics with Python
      • Golang
        • Theory
        • Security
        • Modules
        • Entry Points
        • File Forensics
        • Cryptography and Encoding
        • Golang Snippets
      • PHP
        • Setup
        • Syntax
        • Variables and Data Types
        • Control Structures
        • Arrays
        • Functions
        • OOP Concepts
        • Database Integration
        • Handling HTTP Methods
        • Session Management
        • File Uploads
        • Email Function
        • Error Handling
        • Advanced Topics and Best Practices
    • Network Security
      • Domain Trust Enumeration
      • Bleeding Edge Vulnerabilities
      • Post-Exploitation
      • Access Control Lists and Entries (ACL & ACE)
      • Credentialed Enumeration
      • Password Attacks
        • Internal Password Spraying
        • Remote Password Attacks
        • Linux Local Password Attacks
        • Windows Local Password Attacks
        • Windows Lateral Movement
      • PowerView
      • Pivoting, Tunneling and Forwarding
        • Advanced Tunneling Methods
        • Dynamic Port Forwarding (SSH + Socks)
        • Port Forwarding Tools
        • SoCat
      • Linux Privilege Escalation
      • Windows Privesc
        • OS Attacks
        • Windows User Privileges
        • Windows Group Privileges
        • Manual Enumeration
        • Credential Theft
      • Kerberos Attacks
        • Kerberos Quick Reference Sheet
    • Cloud Security Testing
    • Defensive Security
      • Splunk
        • Basic Queries
        • Dashboards
      • Forensics
        • Volatility
      • WireShark filters
    • Governance, Risk, Compliance
      • Vulnerability Management Lifecycle
    • Capture-the-Flag Training
      • Vulnerable Machine Checklist
      • Reverse Engineering Checklist
      • Mobile Checklist
      • Forensics Checklist
      • Binary Exploitation
      • Cryptography Checklist
    • Reporting
    • PowerShell
    • Linux Basics
    • Basic IT Tasks
  • Digital Privacy and Hygiene
    • Personal Information Removal Services
    • De-Googling Android
    • DNS Services
    • Privacy References
    • Opsec
  • RedPlanet Labs
    • PyGOAT
    • OWASP Juice Shop
Powered by GitBook
On this page
  1. Notes
  2. Coding/Programming
  3. PHP

Setup

PreviousPHPNextSyntax

Last updated 5 months ago

Before we start writing PHP code, it's necessary to set up a proper environment for developing, running, and testing our PHP scripts. Here are the basic components we need:

  • Web Server: A software that can serve our PHP pages. Apache and Nginx are two popular options.

  • PHP Processor: This interprets our PHP code and transforms it into HTML that the web server can serve to users' browsers.

  • Database Server (Optional): While not mandatory for all PHP development, a database server such as MySQL or PostgreSQL is essential for dynamic, data-driven websites.

There are two primary ways you can set up your PHP development environment:

Option 1: Local Installation

You can install a web server, PHP, and a database server individually on your own computer.

  • For Windows users, you can download and install each component individually. The links for downloading these components are:

    • Apache:

    • PHP:

    • MySQL: Alternatively, you can use a pre-packaged software stack like or , which include all three components.

  • For macOS users, PHP and Apache are pre-installed on your machine, and you only need to install MySQL:

  • For Linux users, you can install each component using your package manager. For example, on a Ubuntu-based system, you could use the following commands:

    sudo apt-get update
    sudo apt-get install apache2
    sudo apt-get install php
    sudo apt-get install mysql-server

Option 2: Using Docker

docker pull tomsik68/xampp:8

Here's a simple docker-compose.yml file for a basic PHP development environment:

version: '3'
services:
  web:
    image: php:apache
    volumes:
      - ./:/var/www/html/
    ports:
      - 8080:80
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: test_db
      MYSQL_USER: test_user
      MYSQL_PASSWORD: test_pass

You can start your environment with the command docker-compose up, and then access your PHP site at http://localhost:8080.

No matter which method you choose for setting up your environment, ensure that everything is set up correctly before you start developing with PHP.

Useful VSCode Extensions:

PHP Intelliphense

Live Server

PHP Server

If you want to avoid manually managing individual components on your system, you can use . Docker allows you to create containers that bundle all the software you need.

You can find pre-made Docker images for PHP development environments on .

An example of how to pull Docker is here:

Apache HTTP Server
PHP for Windows
MySQL for Windows
XAMPP
WampServer
MySQL for macOS
Docker
Docker Hub
PHP 8 XAMPP