Signup/Sign In

How to install PHP Redis extension in macOS or Macbook?

Posted in Programming   MARCH 14, 2023

    If you are using MAMP server for PHP development in your Macbook (M1/M2 chip or older intel chip), and you want to install PHP redis extension to start working with Redis server in your application, then follow these steps and you shouldn't face any trouble.

    We will use pecl to install PHP redis extension. Open the terminal and run the below command to download and install the redis extension for PHP:

    pecl install redis

    You can add sudo before the command to install using the root user.

    This command downloads the redis extension, so it will take some time to complete, and you will see a lot of logs being printed on the terminal.

    At last you will see this,


    Build process completed successfully
    Installing '/Applications/MAMP/bin/php/php7.4.33/lib/php/extensions/no-debug-non-zts-20190902/redis.so'
    install ok: channel://pecl.php.net/redis-5.3.7
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=redis.so" to php.ini

    This means the extension was successfully downloaded and installed, now you just have to add the extension=redis.so configuration in your php.ini file.

    In the output above you will get the path of the PHP installation where the redis extension is installed. So go to that path:

    cd /Applications/MAMP/bin/php/php7.4.33/

    Then go inside the conf/ directory available here,

    cd conf

    Now open the php.ini file using any editor, you can use vi or nano to open it, and add the text extension=redis.so to the file and close the file.

    Restart your MAMP server, and you should be good to go.

    You can run the following code in your PHP to see all the extensions installed.

    <?php
    
    echo phpinfo();
    
    ?>

    Conclusion:

    If you want to utilize Redis cache in your PHP application, then to successfully connect to the redis server using PHP you need the PHP redis extension. There is no other way of doing it.

    I hope this article will help you install the PHP redis extension easily.

    About the author:
    I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight
    Tags:redisphpinstallation-guide
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS