Skip to content

VuFind with Up to date MariaDB, PHP and Apache on macOS Using Homebrew

Ere Maijala edited this page Aug 22, 2024 · 14 revisions

Installation

These instructions are quite generic, but there are a couple of notes for VuFind configuration.

Note: Most of the paths below expect that Homebrew is installed in /opt/homebrew, but it could be /usr/local for Intel Macs, or something else for custom installs. Adjust as necessary.

  1. Install XCode command line tools:

    xcode-select --install
    
  2. Install Homebrew:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    
  3. Install dependencies:

    brew install openssl
    
  4. Install and start MariaDB:

    brew install mariadb
    brew services start mariadb
    

    Note that by default you can use mysql without a username and password. However, you need to create a suitable account for VuFind. For example to create a database and account for VuFind, start mysql and execute the following commands (adjust paths as necessary):

    create database vufind;
    use vufind;
    source src/NDL-VuFind2/module/VuFind/sql/mysql.sql
    source src/NDL-VuFind2/module/Finna/sql/mysql.sql
    grant all on vufind.* to `vufind`@`localhost` identified by 'password';
    flush privileges;
    exit
    
  5. Install Apache:

    brew install httpd
    

    Logs will be in /opt/homebrew/var/log/httpd, configuration in /opt/homebrew/etc/httpd.

  6. Install php 7.4.x:

    brew install php@7.4
    

    And/or PHP 8:

    brew install php
    

    You can always switch between versions (remember to change the version Apache uses as well, see further below):

    brew unlink php; brew link php@7.4
    brew unlink php; brew link php@8
    
  7. Install additional PHP modules (e.g. xdebug, memcached, xhprof). Make sure to do this for all PHP versions you use:

    pecl install xdebug
    

    If you encounter "fatal error: 'pcre2.h' file not found", try the following (verify the homebrew installation directory):

    CPPFLAGS="-I/opt/homebrew/include" pecl install xhprof
    
  8. Add the following additional PHP configuration to /opt/homebrew/etc/php/[version]/conf.d/local.ini:

    memory_limit = 2048M
    error_reporting = E_ALL
    display_errors = On
    sendmail_path = "env -i /usr/sbin/sendmail -t -i"    
    date.timezone = "Europe/Helsinki"
    error_log = /Users/[your id]/Library/Logs/php_errors.log
    
    [XDebug]
    xdebug.mode=debug
    xdebug.start_with_request=yes
    xdebug.client_host=127.0.0.1
    xdebug.client_port=9003
    xdebug.show_exception_trace=0
    xdebug.log=/dev/null
    
  9. Copy VuFind's local/httpd-vufind.conf.sample to /opt/homebrew/etc/httpd/extra/httpd-vufind.conf and modify the paths in it accordingly.

  10. Add /opt/homebrew/etc/httpd/extra/disable-keepalive.conf with the following contents:

    # Disabling KeepAlive prevents random 5 second delay with static files
    KeepAlive Off
    
  11. Modify Apache config file /opt/homebrew/etc/httpd/httpd.conf and add the following at the end of the file:

    LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
    #LoadModule php7_module /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so
    LoadModule php_module /opt/homebrew/opt/php@8.2/lib/httpd/modules/libphp.so
    
    AddType application/x-httpd-php .php .phtml     
    
    <IfModule dir_module>
        DirectoryIndex index.php index.html
    </IfModule>
    
    Include /opt/homebrew/etc/httpd/extra/httpd-vufind.conf
    Include /opt/homebrew/etc/httpd/extra/disable-keepalive.conf
    
  12. Start Apache:

    brew services start httpd
    
  13. Check log for any startup errors:

    tail /opt/homebrew/var/log/httpd/error_log
    

Notes

Remember to restart Apache if you change PHP configuration:

brew services restart httpd

Services started with brew services are automatically restarted when the system starts.

Potential Issues

If you encounter "fatal error: 'pcre2.h' file not found" with pecl install, try the following (verify the homebrew installation directory):

CPPFLAGS="-I/opt/homebrew/include" pecl install [...]

Optional Features

Memcached Support

  1. Install prerequisites:

    brew install autoconf pkg-config libmemcached memcached zlib
    
  2. Configure memcached to allow larger packets

    Edit /opt/homebrew/Cellar/memcached//homebrew.mxcl.memcached.plist or /usr/local/Cellar/memcached//homebrew.mxcl.memcached.plist and add the -I 16m parameter like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>KeepAlive</key>
            <true/>
            <key>Label</key>
            <string>homebrew.mxcl.memcached</string>
            <key>LimitLoadToSessionType</key>
            <array>
                    <string>Aqua</string>
                    <string>Background</string>
                    <string>LoginWindow</string>
                    <string>StandardIO</string>
                    <string>System</string>
            </array>
            <key>ProgramArguments</key>
            <array>
                    <string>/opt/homebrew/opt/memcached/bin/memcached</string>
                    <string>-l</string>
                    <string>localhost</string>
                    <string>-I</string>
                    <string>16m</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
            <key>WorkingDirectory</key>
            <string>/opt/homebrew</string>
    </dict>
    </plist>
    
  3. Install memcached with pecl:

    For Apple Silicon, run the following command, and enter /opt/homebrew/opt/zlib when it asks for zlib location:

    PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig" pecl install memcached
    

    For Intel silicon, run the following command, and enter /usr/local/opt/zlib when it asks for zlib location:

    PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig" pecl install memcached