Step 1: Install Xcode Command Line Tools
Xcode Command Line Tools are required for various development tasks and are a prerequisite for Homebrew.
xcode-select --install
A dialog will appear prompting you to install the Command Line Tools. Follow the on-screen instructions to complete the installation.
Step 2: Install Homebrew
Homebrew is a package manager for macOS that simplifies the installation of software.
In Terminal, run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 3: Install PHP
With Homebrew installed, you can now install PHP.
In Terminal, run:
brew install php
Homebrew will download and install the latest version of PHP and its dependencies. To verify the installation, check the PHP version:
php -v
You should see the installed PHP version in the output.
Step 4: Check PHP Installation Complete
Verify that PHP is correctly installed.
In Terminal, run:
php -v
You should see something like:
PHP 8.3.10 (cli) (built: Jul 30 2024 13:44:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.10, Copyright (c) Zend Technologies
with Zend OPcache v8.3.10, Copyright (c), by Zend Technologies
Step 5: Install PHP-PEAR (PHP Extension and Application Repository)
Install PEAR, a repository for PHP extensions.
In Terminal, run:
brew install php-pear
Step 6: Update PHP PEAR Channels
Update PEAR channels to ensure you have the latest versions.
In Terminal, run:
pecl update-channels
Step 7: Install Required Libraries for Swoole
Install necessary libraries using Homebrew.
In Terminal, run:
brew install autoconf automake libtool pkg-config libpq c-ares openssl curl brotli iodbc
Step 8: Check GCC Version
Verify that GCC (GNU Compiler Collection) is installed and check its version.
In Terminal, run:
gcc --version
Step 9: Install PostgreSQL (if needed)
If you need PostgreSQL, install it with Homebrew.
In Terminal, run:
brew install postgresql
Link PostgreSQL to make it available in your system.
In Terminal, run:
brew link --force postgresql
Step 10: Find Path of libpq
Locate the path of libpq library.
In Terminal, run:
find /usr/local -name "libpq*"
Example results might include:
/usr/local/include/postgresql@14/internal/libpq-int.h
/usr/local/include/postgresql@14/internal/libpq
/usr/local/include/postgresql@14/libpq-events.h
/usr/local/opt/libpq
/usr/local/Cellar/postgresql@14/14.13/include/postgresql@14/internal/libpq-int.h
/usr/local/Cellar/postgresql@14/14.13/include/postgresql@14/internal/libpq
/usr/local/Cellar/libpq
/usr/local/Cellar/libpq/16.4/.brew/libpq.rb
/usr/local/Cellar/libpq/16.4/include/postgresql/server/libpq/libpq-be.h
/usr/local/Cellar/libpq/16.4/include/postgresql/server/libpq/libpq.h
/usr/local/Cellar/libpq/16.4/include/postgresql/server/libpq/libpq-fs.h
/usr/local/Cellar/libpq/16.4/include/libpq-events.h
/usr/local/Cellar/libpq/16.4/lib/pkgconfig/libpq.pc
/usr/local/Cellar/libpq/16.4/lib/libpq.5.dylib
/usr/local/Cellar/libpq/16.4/lib/libpq.dylib
/usr/local/Cellar/libpq/16.4/lib/libpq.a
/usr/local/Cellar/libpq/16.4/share/doc/postgresql/html/libpq-notify.html
Step 11: Set Environment Variables for libpq
Export the required environment variables for libpq.
In Terminal, run:
export CPPFLAGS="-I/usr/local/Cellar/libpq/16.4/include"
export PKG_CONFIG_PATH="/usr/local/Cellar/libpq/16.4/lib/pkgconfig"
Check pkg-config for libpq flags:
In Terminal, run:
pkg-config --cflags --libs libpq
Example output:
-I/usr/local/opt/libpq/include -I/usr/local/Cellar/openssl@3/3.3.1/include -L/usr/local/opt/libpq/lib -lpq
Step 11: Install Swoole
Use PECL to install the Swoole extension.
In Terminal, run:
pecl install swoole
You will see prompts during the installation for various configurations. Choose the appropriate options, for example:
enable sockets supports? [no] : yes
enable openssl support? [no] : yes
enable mysqlnd support? [no] : yes
enable curl support? [no] : yes
enable cares support? [no] : yes
enable brotli support? [yes] : yes
enable PostgreSQL database support? [no] : yes
enable ODBC database support? [no] :
enable Oracle database support? [no] :
enable Sqlite database support? [no] : yes
The installation process will build Swoole and install it. Ensure that it completes successfully.
Step 12: Verify Installation and Restart Services
Check if Swoole is installed correctly:
In Terminal, run:
php -m | grep swoole
Restart the PHP service to apply the changes:
In Terminal, run:
brew services restart php
Verify PostgreSQL installation:
In Terminal, run:
postgres --version
Step 13: Set Up PostgreSQL
Run PostgreSQL:
In Terminal, run:
brew services start postgresql
Create and configure a PostgreSQL database and user:
In Terminal, run:
psql postgres
Within the PostgreSQL command line, run the following commands:
CREATE DATABASE phpswoole;
CREATE USER phpswoole WITH ENCRYPTED PASSWORD 'phpswoole';
GRANT ALL PRIVILEGES ON DATABASE phpswoole TO phpswoole;
You can use DBeaver or another database management tool to manage your PostgreSQL databases.