Efficient PHP Usage in the ServBay Local Environment
PHP (Hypertext Preprocessor) is a widely-used open-source scripting language, especially well-suited for web development and can be embedded directly into HTML. Thanks to its flexible syntax (drawing from languages like C, Java, and Perl), PHP is easy to learn and use, and seamlessly integrates with a variety of database systems and services.
As a powerful local web development environment, ServBay provides macOS developers with a convenient way to install, configure, and manage PHP and its related components—enabling you to efficiently develop and test PHP applications locally.
ServBay’s PHP Support
ServBay offers broad PHP version support, from legacy compatible versions to the latest stable releases, ensuring you can choose the most suitable PHP environment for your project’s development and deployment needs. ServBay supports the following PHP versions:
- PHP 5.6
- PHP 7.0
- PHP 7.1
- PHP 7.2
- PHP 7.3
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
TIP
ServBay includes Composer out of the box—no separate installation required.
Installation Method
You can easily install and manage PHP packages via the ServBay GUI panel. Here are the steps to install PHP through the ServBay GUI:
- Open the ServBay GUI panel.
- Navigate to the
Packages
-PHP
section in the left sidebar. - Look for the PHP version you need in the list.
- Click the green
Install
button next to that version, and wait for the installation to complete.
Managing and Switching PHP Versions
One of ServBay’s key advantages is its ability to quickly switch between different PHP versions. If you have multiple PHP versions installed, you can set one as the currently active PHP version via the right-side button in the ServBay GUI panel’s Packages
– PHP
section.
Once you set the active version, ServBay will use that specific PHP version to run your web applications.
Included Modules
ServBay provides multiple commonly used PHP modules, giving you the flexibility to extend PHP’s capabilities. Many core modules are installed and enabled by default, requiring no extra configuration. Other modules can be enabled as needed.
Here are some of the PHP modules bundled with ServBay:
- GD: A library for image processing (e.g., creating, manipulating, or outputting various image formats). Installed and enabled by default—no additional setup needed.
- IMAP: A library for handling email, supporting IMAP, POP3, and NNTP protocols. Installed and enabled by default.
- Imagick: The ImageMagick PHP extension for advanced image processing. Installed and enabled by default.
- Memcache: The client library for the Memcache in-memory object caching system. Installed and enabled by default.
- Memcached: The client library for the high-performance distributed in-memory object caching system Memcached. Installed and enabled by default.
- MySQL: PHP extension to connect to and operate MySQL databases (typically
mysqli
ormysqlnd
). Installed and enabled by default. - OpenLDAP: PHP extension for Lightweight Directory Access Protocol (LDAP), used to interact with LDAP servers. Installed and enabled by default.
- PgSQL: PHP extension for connecting to and working with PostgreSQL databases. Installed and enabled by default.
- Redis: PHP extension to connect to and operate Redis key-value storage systems. Installed and enabled by default.
- SQLite 3: PHP extension for working with SQLite databases. Installed and enabled by default.
- Sodium: Library for cryptographic operations, providing strong modern encryption. Installed and enabled by default.
- cURL: Library for making network requests and transferring data, supporting various protocols (such as HTTP, HTTPS, FTP, and more). Installed and enabled by default.
- MongoDB: PHP extension for interacting with MongoDB databases. For enabling instructions, see How to enable the MongoDB module included with ServBay.
- OPcache: Bytecode caching module to speed up PHP script execution. See How to enable the OPcache module in ServBay for instructions.
- Phalcon: High-performance PHP framework extension provided as a C extension. See How to enable the Phalcon module in ServBay.
- SCWS: PHP extension for Chinese text segmentation. See How to enable the SCWS module in ServBay.
- Swoole: High-performance PHP asynchronous, coroutine, and parallel network communication framework extension. See How to enable the Swoole module in ServBay.
- Xdebug: Powerful extension for PHP debugging and code analysis. See How to enable the Xdebug module in ServBay.
For detailed usage tutorials, refer to the following links:
- GD
- IMAP
- Imagick
- Memcache
- Memcached
- MySQL
- OpenLDAP
- PgSQL
- Redis
- SQLite 3
- Sodium
- cURL
- MongoDB
- OPcache
- Phalcon
- SCWS
- Swoole
- Xdebug
How do you verify if a module is enabled?
You can create an info.php
file in your website’s root directory containing <?php phpinfo(); ?>
, then access this file in your browser. Search the resulting page to see all modules installed and enabled in the current ServBay active PHP version, along with their detailed configuration.
Configuring PHP (php.ini)
The behavior of PHP can be finely tuned using the php.ini
file, for example, adjusting memory limits, error reporting levels, upload file sizes, and more. ServBay generates a corresponding php.ini
file for every installed PHP version.
The simplest way to locate the php.ini
file for your currently active PHP version is to look for the “Loaded Configuration File” entry on the phpinfo()
output page.
You can quickly open and edit the php.ini
file for the current active version via the ServBay GUI panel:
- Open the ServBay GUI panel.
- Go to the
Packages
-PHP
section. - Find the currently active (green-marked) PHP version.
- Click the configuration (gear) icon next to that version and select "Edit php.ini".
After editing php.ini
, you will usually need to restart ServBay or at least restart the web server (such as Caddy or Nginx) for changes to take effect.
Basic Usage Example: Running Your First PHP Script
Running PHP scripts with ServBay is extremely easy. Follow these steps to create a simple "Hello, World" example:
- Ensure you have installed and started at least one PHP version and a web server (such as Caddy or Nginx) in ServBay.
- Open your ServBay website root directory. By default, this directory is usually
/Applications/ServBay/www
. - Create a new subfolder under that directory, for example,
php-demo
. The full path will be/Applications/ServBay/www/php-demo