PHP

PHP Installation

Installation

macOS

Install PHP 8.2 for a stable development environment:

> brew install php@8.2
> brew link --overwrite --force php@8.2

Install redis support for PHP:

> pecl install redis

Windows

  1. Download PHP from windows.php.net

  2. Extract the downloaded file to C:\php

  3. Setup system environment variables

    • Open the System Properties dialog (press Win and enter env)
    • Click on the "Advanced" tab
    • Click on the "Environment Variables" button
    • Under "System variables", click on "New"
    • Add the following variables:
      • Variable name: PHP_HOME
      • Variable value: C:\php
    • Under "System variables", select the Path variable and click on "Edit"
    • Add the following value: %PHP_HOME%
  4. Edit the php.ini file

    • Open C:\php\php.ini in a text editor
    • Uncomment the following extensions:
      • extension=curl
      • extension=fileinfo
      • extension=gd2
      • extension=mbstring
      • extension=openssl
      • extension=pdo_mysql
      • extension=pdo_sqlite
      • extension=sqlite3
      • extension=zip
  5. Install unzip

    • Download the latest version of unzip from PECL
    • Extract the downloaded php_zip.dll file to C:\php\ext
    • Add extension=php_zip.dll to the php.ini file

> php -v
  1. Open the PHP directory and rename the file php.ini-development to php.ini.

Ubuntu

Dependencies

$ sudo apt update
$ sudo apt install -y build-essential libxml2-dev libssl-dev \
libcurl4-openssl-dev pkg-config libjpeg-dev libpng-dev \
libonig-dev libmcrypt-dev libreadline-dev libsqlite3-dev \
libzip-dev libonig-dev libmcrypt-dev libreadline-dev \
libgd-dev libpng-dev libjpeg-dev libfreetype6-dev libwebp-dev \
libmysqlclient-dev libpq-devcurl

PHP 8.2.13

$ cd ~
$ wget https://www.php.net/distributions/php-8.2.13.tar.gz
$ tar -xvf php-8.2.13.tar.gz
$ cd php-8.2.13
$ ./configure --prefix=/usr/local/php8.2 --with-openssl --with-curl \
--enable-mbstring --with-pdo-sqlite --with-readline --with-sqlite3 \
--with-zip --enable-xml --enable-mbstring --enable-gd --with-jpeg \
--with-webp --with-freetype --with-zlib --enable-soap \
--with-mysqli --with-pdo-mysql --with-pgsql --with-pdo-pgsql
$ make
$ sudo make install

PHP 8.1.14

$ cd ~
$ wget https://www.php.net/distributions/php-8.1.14.tar.gz
$ tar -xvf php-8.1.14.tar.gz
$ cd php-8.1.14
$ ./configure --prefix=/usr/local/php8.1 --with-openssl --with-curl \
--enable-mbstring --with-pdo-sqlite --with-readline --with-sqlite3 \
--with-zip --enable-xml --enable-mbstring --enable-gd --with-jpeg \
--with-webp --with-freetype --with-zlib --enable-soap \
--with-mysqli --with-pdo-mysql --with-pgsql --with-pdo-pgsql
$ make
$ sudo make install

Recompiling PHP

$ cd ~/php-8.x.x
$ make clean

Add PHP to the PATH

$ sudo apt install nano
$ nano ~/.bashrc

Add the following lines to the end of the file:

export PATH="/usr/local/php8.1/bin:$PATH"
$ source ~/.bashrc

(Optional) Add PHP’s Directory to the Global PATH

$ sudo nano /etc/profile
$ export PATH="/usr/local/php8.1/bin:$PATH"
$ source /etc/profile

(Optional) Move the PHP Binary to a Standard Directory

$ sudo ln -s /usr/local/php8.1/bin/php /usr/bin/php
Previous
UV