ServBay CLI: Installation, Configuration & Usage Guide
ServBay not only provides you with an intuitive graphical user interface (GUI) for managing your local development environment, but also a powerful command line tool. By installing ServBay’s CLI in your terminal (such as bash or zsh), you gain the ability to run various integrated development tools and packages directly from your command line, greatly enhancing your productivity and flexibility.
Prerequisites
Before using the ServBay command line tool, please make sure you have successfully installed and are running ServBay.
Installing the ServBay CLI
Here are the detailed steps to install the ServBay CLI in your terminal environment:
Open the ServBay application.
Click the
Settings
option in the left navigation menu of ServBay.On the settings page, locate the
Command Line Tool
section.Depending on your current terminal environment (macOS uses bash by default, or you might be using zsh), click the corresponding button:
- If you use zsh, click
Install CLI Tool to zsh
. - If you use bash, click
Install CLI Tool to bash
.
- If you use zsh, click
During installation, you will typically be asked to enter your administrator password to modify system environment files (such as
.zshrc
or.bash_profile
). Please authorize the installation.After installation, make sure to close and reopen your terminal window. The ServBay CLI will take effect in new terminal sessions.
Configuring Default Package Versions
ServBay allows you to set global default versions for commonly used packages, such as PHP, Node.js, MySQL, or MariaDB. This means that when you run commands like php
, node
, or mysql
in your terminal, they will use the default versions you’ve specified in the ServBay GUI or set via the command line.
For detailed instructions on setting global default versions, refer to the Setting Default Versions documentation.
Specifying Project-Specific CLI Versions
To better cater to different project dependencies, ServBay supports specifying project-level PHP and Node.js versions by creating a .servbay.config
file in your project’s root directory. This configuration overrides the global setting, ensuring that each project always uses the designated package versions and avoids version conflicts.
The .servbay.config
file allows you not only to specify PHP and Node.js versions, but also to set project-level configurations such as Node.js runtime version, package registry, cache directory, and more.
For detailed guidance on configuration and usage, please see Using the .servbay.config File.
Running Specific Package Versions Directly
Beyond setting default and project-specific versions, ServBay also adds executables for each installed version of major packages (like PHP and Node.js) directly to your system PATH, using the version number as a suffix (for example, php-7.4
, php-8.1
, php-8.3
). This means you can invoke a specific version of an executable in any terminal window without switching your global or project default.
Common Command Line Examples
Once the ServBay CLI is installed, you can directly use various tools and commands integrated with ServBay. Here are some common examples:
Check the current system default PHP version:
bashphp -v
1Check the current system default Node.js version:
bashnode -v
1Run a script using a specific version of PHP:
bashphp-8.3 your_script.php
1You can also replace
php-8.3
with any other installed PHP version in ServBay, such asphp-7.4
orphp-8.1
.Use a specific version of the
phpize
tool:bashphpize-8.3
1The
phpize
tool is used to prepare the build environment for PHP extensions.Connect to a PostgreSQL database:
bashpsql -h localhost -U your_user -d your_database
1Replace
your_user
andyour_database
with your actual database username and database name.Connect to a MySQL database:
bashmysql -h localhost -u your_user -p your_database
1Replace
your_user
andyour_database
with your actual username and database name. You’ll be prompted for your password after running this command.Execute an SQL query:
bashpsql -h localhost -U your_user -d your_database -c "SELECT * FROM your_table;"
1The
-c
flag allows you to run an SQL statement directly from the command line.View Redis server status information:
bashredis-cli info stats
1
These sample commands allow you to efficiently utilize the various packages and services provided by ServBay directly from your command line environment for more productive development and debugging.
Notes
- After installing the CLI, you must reopen your terminal window for the new environment variables to take effect.
- If you change the ServBay package installation path, you may need to reinstall the CLI tool.
Summary
The ServBay command line tool is an essential part of its robust functionality, providing developers with a direct and efficient way to manage and use a variety of tools and packages in the local development environment. With simple installation steps, you can easily access ServBay-integrated services like PHP, Node.js, databases, and more from your terminal. By setting default versions or project-specific configurations, you can adapt to different development needs. Mastering the use of the ServBay CLI will significantly enhance your local development workflow.