Recompiling Software Using ServBay
ServBay provides macOS users with a robust and complete local web development environment that includes a wide collection of software packages and tools. While ServBay offers pre-installed package versions, developers may sometimes need to recompile packages for specific requirements, such as:
- Enabling certain compilation options for a package.
- Adding modules or extensions not included by default in ServBay (e.g., new PHP extensions or PostgreSQL modules).
- Compiling against library versions different from ServBay’s defaults.
- Customizing and modifying ServBay’s provided packages.
ServBay offers the necessary compilation environment and toolchain to help users easily accomplish these tasks.
To successfully recompile software, users should be familiar with the basics of Unix/Linux software compilation (e.g., configure
, make
, make install
).
Prerequisites
Before you begin recompilation, make sure the following prerequisites are met:
Install ServBay Development Library: This is a core dependency for recompilation. The package contains all development resources necessary for compilation within the ServBay environment, such as libraries (
.so
,.a
) and headers (.h
). You can find and install it from the Packages panel in the ServBay application interface.Install Xcode Command Line Tools: This is Apple’s suite of essential developer tools for macOS, including compilers (Clang), linkers, and more. Open the Terminal and execute:
bashxcode-select --install
1If already installed, you’ll see a system prompt.
Install Additional Build Tools: Most open-source software requires
autoconf
,automake
,libtool
, and similar tools for compilation. You can typically install them via Homebrew package manager:bashbrew install autoconf automake libtool cmake
1If you don't have Homebrew installed, please refer to the official Homebrew website for installation instructions.
Setting Up the Build Environment
After installing the ServBay Development Library and the required tools, you need to initialize the compilation environment in your terminal. This mainly involves configuring environment variables (PATH
, CFLAGS
, LDFLAGS
, CPPFLAGS
, etc.) to let the compiler and build system know where ServBay’s libraries, headers, and binaries are located so dependencies are found and linked correctly.
ServBay’s runtime environment differs based on your Mac’s CPU architecture: Intel (x86_64) or Apple Silicon (Arm64). You need to select the corresponding initialization command based on your current ServBay runtime architecture.
Check the CPU Architecture of ServBay Runtime
You can check the architecture by inspecting any executable in ServBay’s bin
directory. For example, check bison
:
# Run this command in the terminal
$ file /Applications/ServBay/bin/bison
/Applications/ServBay/bin/bison: Mach-O 64-bit executable arm64
2
3
# Run this command in the terminal
$ file /Applications/ServBay/bin/bison
/Applications/ServBay/bin/bison: Mach-O 64-bit executable x86_64
2
3
Once you confirm the architecture, choose the appropriate environment initialization script.
Initialize Build Environment Variables
Open a new terminal window and copy-paste the script corresponding to your CPU architecture below. This will set all necessary paths and flags for the ServBay build environment.
# Set CPU core count for parallel compilation
CPU_NUMBER=$(sysctl -n hw.ncpu)
# ServBay installation base path
SERVBAY_BASE_FULL_PATH="/Applications/ServBay"
# Package directory name
SERVBAY_PACKAGE_DIR_NAME="package"
# Full package path
SERVBAY_PACKAGE_FULL_PATH="${SERVBAY_BASE_FULL_PATH}/${SERVBAY_PACKAGE_DIR_NAME}"
# ServBay binary paths
SERVBAY_BIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/bin"
SERVBAY_SBIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/sbin"
# ServBay configuration file path
SERVBAY_ETC_PATH="${SERVBAY_PACKAGE_FULL_PATH}/etc"
# ServBay variable data path
SERVBAY_VAR_PATH="${SERVBAY_PACKAGE_FULL_PATH}/var"
# ServBay Development Library installation path
SERVBAY_COMMON_PATH="${SERVBAY_PACKAGE_FULL_PATH}/common"
# ServBay Development Library include path
SERVBAY_COMMON_INCLUDE_PATH="${SERVBAY_COMMON_PATH}/include"
# ServBay Development Library library path
SERVBAY_COMMON_LIB_PATH="${SERVBAY_COMMON_PATH}/lib"
SERVBAY_COMMON_LIBEXEC_PATH="${SERVBAY_COMMON_PATH}/libexec"
SERVBAY_COMMON_SHARE_PATH="${SERVBAY_COMMON_PATH}/share"
SERVBAY_COMMON_MAN_PATH="${SERVBAY_COMMON_PATH}/man"
SERVBAY_COMMON_DOC_PATH="${SERVBAY_COMMON_PATH}/doc"
# Current build directory
SERVBAY_BUILD_DIR=$(pwd)
SERVBAY_BUILD_SRC_DIR=${SERVBAY_BUILD_DIR}/src
# OpenSSL version info
OPENSSL_SELECTED_VERSION="3.2"
OPENSSL_VERSION="3.2.1"
# Minimum build target OS version
BUILD_OS_MIN_VERSION="12.00" # macOS Monterey or newer
# Build CPU architecture flag
BUILD_CPU_ARCH="-arch arm64"
BUILD_CPU_ARCH_CMAKE="arm64"
BUILD_MACOS_TARGET="" # Arm64 usually does not need -target flag
# Set C compiler flags: optimization, min macOS version, architecture
export CFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set linker flags: rpath, library paths (-L), min macOS version, architecture
export LDFLAGS="-Wl,-rpath -Wl,${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_PACKAGE_FULL_PATH} -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set C preprocessor and CXX flags: include paths (-I)
export CPPFLAGS="-I${SERVBAY_COMMON_INCLUDE_PATH}"
# Set C++ compiler flags: same as CFLAGS
export CXXFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set executable search paths: give priority to ServBay's bin/sbin
export PATH="${SERVBAY_BIN_PATH}:${SERVBAY_SBIN_PATH}:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
# Set pkg-config search paths for finding compilation info for libraries
export PKG_CONFIG_PATH="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
# Specify pkg-config tool path
export PKG_CONFIG="${SERVBAY_BIN_PATH}/pkg-config"
# Set pkg-config lib directory
export PKG_CONFIG_LIBDIR="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
# Add system and Homebrew bin/sbin to PATH as backup
export PATH=$PATH:"/usr/local/bin:/usr/local/sbin"
export PATH=$PATH:"/opt/homebrew/bin/" # Default Homebrew installation path
# Add OpenSSL library and include paths to LDFLAGS and CPPFLAGS
export LDFLAGS="-L${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib ${LDFLAGS}"
export CPPFLAGS="-I${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/include ${CPPFLAGS}"
# Add OpenSSL pkgconfig path
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
# Once set up, you can compile in this terminal window
echo "ServBay Arm64 build environment initialized."
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Set CPU core count for parallel compilation
CPU_NUMBER=$(sysctl -n hw.ncpu)
# ServBay installation base path
SERVBAY_BASE_FULL_PATH="/Applications/ServBay"
# Package directory name
SERVBAY_PACKAGE_DIR_NAME="package"
# Full package path
SERVBAY_PACKAGE_FULL_PATH="${SERVBAY_BASE_FULL_PATH}/${SERVBAY_PACKAGE_DIR_NAME}"
# ServBay binary paths
SERVBAY_BIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/bin"
SERVBAY_SBIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/sbin"
# ServBay configuration file path
SERVBAY_ETC_PATH="${SERVBAY_PACKAGE_FULL_PATH}/etc"
# ServBay variable data path
SERVBAY_VAR_PATH="${SERVBAY_PACKAGE_FULL_PATH}/var"
# ServBay Development Library installation path
SERVBAY_COMMON_PATH="${SERVBAY_PACKAGE_FULL_PATH}/common"
# ServBay Development Library include path
SERVBAY_COMMON_INCLUDE_PATH="${SERVBAY_COMMON_PATH}/include"
# ServBay Development Library library path
SERVBAY_COMMON_LIB_PATH="${SERVBAY_COMMON_PATH}/lib"
SERVBAY_COMMON_LIBEXEC_PATH="${SERVBAY_COMMON_PATH}/libexec"
SERVBAY_COMMON_SHARE_PATH="${SERVBAY_COMMON_PATH}/share"
SERVBAY_COMMON_MAN_PATH="${SERVBAY_COMMON_PATH}/man"
SERVBAY_COMMON_DOC_PATH="${SERVBAY_COMMON_PATH}/doc"
# Current build directory
SERVBAY_BUILD_DIR=$(pwd)
SERVBAY_BUILD_SRC_DIR=${SERVBAY_BUILD_DIR}/src
# OpenSSL version info
OPENSSL_SELECTED_VERSION="1.1.1u"
OPENSSL_VERSION="1.1.1u"
# Minimum build target OS version
BUILD_OS_MIN_VERSION="12.00" # macOS Monterey or newer
# Build CPU architecture flag
BUILD_CPU_ARCH="-arch x86_64"
BUILD_CPU_ARCH_CMAKE="x86_64"
# Target platform flag (usually needed for Intel)
BUILD_MACOS_TARGET="-target x86_64-apple-macos${BUILD_OS_MIN_VERSION}"
# Set C compiler flags: optimization, min macOS version, architecture, platform
export CFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set linker flags: rpath, library paths (-L), min macOS version, architecture, platform
export LDFLAGS="-Wl,-rpath -Wl,${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_PACKAGE_FULL_PATH} -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set C preprocessor and CXX flags: include paths (-I)
export CPPFLAGS="-I${SERVBAY_COMMON_INCLUDE_PATH}"
# Set C++ compiler flags: same as CFLAGS
export CXXFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
# Set executable search paths: give priority to ServBay's bin/sbin
export PATH="${SERVBAY_BIN_PATH}:${SERVBAY_SBIN_PATH}:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
# Set pkg-config search paths for finding compilation info for libraries
export PKG_CONFIG_PATH="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
# Specify pkg-config tool path
export PKG_CONFIG="${SERVBAY_BIN_PATH}/pkg-config"
# Set pkg-config lib directory
export PKG_CONFIG_LIBDIR="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
# Add system and Homebrew bin/sbin to PATH as backup
export PATH=$PATH:"/usr/local/bin:/usr/local/sbin"
export PATH=$PATH:"/opt/homebrew/bin/" # Default Homebrew installation path
# Add OpenSSL library and include paths to LDFLAGS and CPPFLAGS
export LDFLAGS="-L${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib ${LDFLAGS}"
export CPPFLAGS="-I${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/include ${CPPFLAGS}"
# Add OpenSSL pkgconfig path
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
# Once set up, you can compile in this terminal window
echo "ServBay x86_64 build environment initialized."
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Important Note: These environment variables only apply to the current terminal session. If you close the terminal or open a new window, you must rerun the relevant script to set up the compilation environment again.
Compilation Examples
With the build environment set up in your terminal, you can now download and compile source code. Here are some typical examples:
Compiling ImageMagick
ImageMagick is a powerful image processing library and a dependency for the PHP imagick
extension. ServBay already includes ImageMagick by default, so manual compilation is not usually necessary. The example here simply demonstrates how to compile a typical Autotools-based project (configure
/make
) using the ServBay environment.
Download and extract the ImageMagick source code:
bash# Replace with the latest version as needed wget https://imagemagick.org/archive/releases/ImageMagick-7.1.1-33.tar.gz tar zxvf ImageMagick-7.1.1-33.tar.gz cd ImageMagick-7.1.1-33
1
2
3
4Run the
./configure
script: Run the configure script with the environment variables set above. Use--prefix
,--libdir
,--includedir
, etc. to specify installation paths pointing to the ServBay Development Library’s common directory${SERVBAY_COMMON_PATH}
and subdirectories. This ensures the generated libraries and headers are available for other software within the ServBay environment—such as the PHPimagick
extension. Adjust other options as needed according to ImageMagick’s requirements.bash./configure \ --prefix=${SERVBAY_COMMON_PATH} \ --libdir=${SERVBAY_COMMON_LIB_PATH} \ --includedir=${SERVBAY_COMMON_INCLUDE_PATH} \ --oldincludedir=${SERVBAY_COMMON_INCLUDE_PATH} \ --bindir=${SERVBAY_BIN_PATH} \ --sbindir=${SERVBAY_SBIN_PATH} \ --sysconfdir=${SERVBAY_ETC_PATH} \ --datarootdir=${SERVBAY_COMMON_SHARE_PATH} \ --enable-osx-universal-binary=no \ --disable-silent-rules \ --disable-opencl \ --enable-shared \ --enable-static \ --with-freetype=yes \ --with-gvc=no \ --with-modules \ --with-webp=yes \ --with-heic=no \ --without-gslib \ --with-fpx=no \ --without-openexexr \ --with-raw=yes \ --without-lqr \ --without-djvu \ --without-fftw \ --without-pango \ --without-wmf \ --without-x \ --with-gs-font-dir=${SERVBAY_COMMON_SHARE_PATH}/ghostscript/10.02.1/Resource/Font
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30Run
make
andmake install
:make
compiles executables and libraries. The-j ${CPU_NUMBER}
flag uses multiple CPU cores for faster builds.make install
installs the compiled files to the ServBay Development Library directory specified by--prefix
.bashmake -j ${CPU_NUMBER} make install
1
2
Building Packages with cmake
For packages using cmake
as their build system, compilation is somewhat different. The following uses protobuf
(Protocol Buffers) as an example.
Download the protobuf source code and enter the directory.
Configure the project using
cmake
:-S .
sets the source directory as the current folder;-B builddir
places build files inbuilddir
. The-DCMAKE_INSTALL_PREFIX
and related options specify installation paths to the ServBay Development Library. The other-D
options are package-specific settings forprotobuf
.-DCMAKE_MACOSX_RPATH=1
and-DCMAKE_INSTALL_RPATH
ensure that libraries can find other ServBay libraries at runtime.bash# Assuming you are in the protobuf source directory cmake -S . -B builddir \ -DCMAKE_INSTALL_PREFIX=${SERVBAY_COMMON_PATH} \ -DCMAKE_INSTALL_LIBDIR=${SERVBAY_COMMON_LIB_PATH} \ -DCMAKE_INSTALL_INCLUDEDIR=${SERVBAY_COMMON_INCLUDE_PATH} \ -DCMAKE_INSTALL_BINDIR=${SERVBAY_BIN_PATH} \ -DCMAKE_INSTALL_SBINDIR=${SERVBAY_SBIN_PATH} \ -DCMAKE_INSTALL_SYSCONFDIR=${SERVBAY_ETC_PATH} \ -DCMAKE_INSTALL_DATAROOTDIR=${SERVBAY_COMMON_SHARE_PATH} \ -DCMAKE_MACOSX_RPATH=1 \ -DCMAKE_INSTALL_RPATH=${SERVBAY_COMMON_LIB_PATH} \ -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE \ -DCMAKE_PREFIX_PATH=${SERVBAY_COMMON_PATH} \ -DBUILD_SHARED_LIBS=ON \ -Dprotobuf_BUILD_LIBPROTOC=ON \ -Dprotobuf_BUILD_SHARED_LIBS=ON \ -Dprotobuf_INSTALL_EXAMPLES=OFF \ -Dprotobuf_BUILD_TESTS=OFF \ -Dprotobuf_ABSL_PROVIDER=package \ -Dprotobuf_JSONCPP_PROVIDER=module \ -DCMAKE_CXX_STANDARD=17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Run
cmake --build
andcmake --install
:cmake --build builddir
builds the project in thebuilddir
directory.cmake --install builddir
installs the compiled files to the designated ServBay Development Library location.bashcmake --build builddir -j ${CPU_NUMBER} cmake --install builddir
1
2
Compiling PHP Modules
If you need to compile additional extension modules (like swoole
, redis
, mongodb
, etc.) for a specific PHP version in ServBay, please refer to the dedicated documentation:
Compiling PostgreSQL Modules
If you need to compile extra modules for a specific PostgreSQL version in ServBay, please refer to the dedicated documentation:
How to Compile PostgreSQL Modules
Summary
With the ServBay Development Library and comprehensive environment variables, developers can easily recompile and customize software packages on macOS. This provides a high degree of flexibility to meet specific project requirements or use the latest library versions. Be sure to carefully read any official compilation guides for the packages you wish to build and adjust configuration steps as needed.