Giter VIP home page Giter VIP logo

sphp.sh's Introduction

sphp.sh

Shell script for switching between Brew-installed PHP versions, as featured in the popular macOS Apache + PHP series on https://getgrav.org.

The code has been moved from the original gist to a proper repository, to better allow for pull requests and issues.

Installation

Intel Macs:

Install various versions of PHP per macOS Apache + PHP series using Homebrew.

curl -L https://raw.githubusercontent.com/rhukster/sphp.sh/main/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp

Apple Silicon Macs:

curl -L https://raw.githubusercontent.com/rhukster/sphp.sh/main/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp

Usage

To switch your current PHP installation to PHP 8.2, simply enter this command in the terminal:

โžœ sphp 8.2

Result:

Switching to [email protected]
Switching your shell
Unlinking /opt/homebrew/Cellar/[email protected]/7.3.33_4... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/7.4.33_1... 25 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/8.0.27_1... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/8.1.15... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/php/8.2.3... 0 symlinks removed.
Linking /opt/homebrew/Cellar/php/8.2.3... 24 symlinks created.
Switching your apache conf
Restarting apache
Stopping `httpd`... (might take a while)
==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd)
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)

PHP 8.2.3 (cli) (built: Feb 15 2023 00:18:01) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans

All done!

Support

Submit a new bug report on the Github repository.

All code contributions (bug fixes, new features and enhancements) are welcome. Please submit a Pull Request.

License and Copyright

Copyright (c) 2023 Andy Miller

Released under the MIT License

sphp.sh's People

Contributors

dregad avatar rhukster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sphp.sh's Issues

Not adding LoadModule statement when not already present in httpd.conf

If there is no existing LoadModule statement in httpd.conf for the PHP version being switched to, the script does not add it. This results in a non-functional web server, which is unable to interpret PHP.

This can happen e.g. when a new PHP version is installed after the initial setup.

The script does have a function to cover that scenario, but it's not working as expected because it is is relying on the existence of a "native osx" module in httpd.conf as the reference point to add the missing PHP module. When this line does not exist in the file (which is the case with macOS 13), then the LoadModule line is never added.

Request: version for MacPorts

It'd be awesome if the script could auto-detect whether you installed PHP via homebrew or via MacPorts, and work accordingly.

(A big request, I know ... maybe I'll work on a PR in my spare time.)

Refactoring OK ?

Hi,

I started looking at the script, to implement the fix for the grep issue I was facing. Independently from that, I noticed some things that could be improved / simplified (e.g. duplicated code to determine PHP module/Apache lib based on PHP version.

Before I spend too much time coding, are you willing to consider a refactoring PR ?

Switch doesn't shows

I am using MacBook Pro 13 with macOS Sonoma . The problem is when I switch to php version the system does't show the changes only shows the changes after restarting the machine. I have also tried restarting apache.

Thanks

future proofing sphp with semver and self-update

First of all, thanks for this useful script!

I found instructions to install it (via):

curl -L https://raw.githubusercontent.com/rhukster/sphp.sh/main/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp

But when php 8.2+ comes out (assuming this script would be maintained and updated), I'll have to go figure out again where to grab the latest version. And I noticed a few improvements that could be made to this respect

  1. the README should contain install/update instructions.
  2. there isn't any mention inside the sphp.sh file itself about where it came from or what version it is.
  3. it would be amazing if there could be a self-update sub-command.

What are sphp's optional parameters for ?

Script usage describes some optional parameters, -s and -c :

usage: sphp.sh version [-s|-s=*] [-c=*]

Unless I missed something, they are not used in the script - can you please clarify what they are for and how they should be used ?

lots of grep stray \ before / warnings.

$> sphp 8.0

Switching your shell
Unlinking /opt/homebrew/Cellar/[email protected]/7.4.33_1... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/8.0.28... 25 symlinks removed.
Unlinking /opt/homebrew/Cellar/[email protected]/8.1.15... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/php/8.2.3... 0 symlinks removed.
Linking /opt/homebrew/Cellar/[email protected]/8.0.28... 25 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
Switching your apache conf
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
sed: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
sed: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
sed: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: warning: stray \ before /
grep: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
sed: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
sed: /opt/homebrew/etc/httpd/httpd.conf: No such file or directory
Restarting apache
Warning: Service `httpd` is not started.
Error: Formula `httpd` is not installed.

PHP 8.0.28 (cli) (built: Feb 14 2023 15:42:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies

All done!

Maybe because of usage of GNU grep.

$> grep --version

grep --version
grep (GNU grep) 3.8
Packaged by Homebrew
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

I am not using httpd/apache... so it's safe to ignore the notices above, but probably worth checking to see if apache/httpd file exists before trying the action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.