Install on macOS Big Sur - cyjoelchen/php-sweph GitHub Wiki
Thank you to @AstroSign-Dev for providing these instructions.
As builtin PHP of macOS Big Sur is PHP version 7.3 and not direct upgradeable we will install Homebrew to update PHP to version 8. To install php and neccessary development tools on macOS big Sur and above, easiest is to install git, homebrew and xcode command line tools.
How to install Homebrew and XCode command line tools »
> brew --version
> xcode-select --version
If there comes up this error during homebrew installation:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
In case of the error above you can create the /usr/local/Frameworks yourself to circumvate this error
sudo mkdir /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks
> brew install php
> brew install git
> git --version
> php --version
This project uses tagged releases. As such, the master branch should be considered unstable and "bleeding edge".
Follow the steps to build the latest version of this extension.
cd ~ ; mkdir swephp; cd swephp;
git clone -b 4.0.4 https://github.com/cyjoelchen/php-sweph.git
cd php-sweph
phpize
./configure
make
optional:
make test
required:
For the next command you have to type in your localhost admin password to create and install the swephp.so
extension into your system
sudo make install
Installing shared extensions: /usr/local/Cellar/php/8.0.9/pecl/20200930/
You need to provide your localhost admin password for this step. Check location of loaded php.ini file and extend the extension section in the php.ini file with:
extension=swephp
php -i | grep php.ini
sudo nano /usr/local/etc/php/8.0/php.ini
Within nano editor I searched with Ctrl+W for extension=bz2
and then above that line I put in a new line with entry: extension=swephp
Ctrl+X
to close and then Y
and Enter
to save the edited php.ini file
php -m | grep swephp
Now we copy some Swiss Ephemeris files of our choice to a dedicated folder on our system, and test if the extension is working
cd ~
cp ~/swephp/php-sweph/sweph/ephe/*.* ~/swephp/
nano ~/example.php
We put the below content into the just created example.php file
<?php
# Set path to ephemeris data files
swe_set_ephe_path("./swephp");
# calc planet position
list($y, $m, $d, $h, $mi, $s) = sscanf(gmdate("Y m d G i s"), "%d %d %d %d %d %d");
$jul_ut = swe_julday($y, $m, $d, ($h + $mi / 60 + $s / 3600), SE_GREG_CAL);
$planets['julday'] = $jul_ut;
for($i = SE_SUN; $i <= SE_VESTA; $i++)
{
if ($i == SE_EARTH) continue;
$xx = swe_calc_ut($jul_ut, $i, SEFLG_SPEED);
if ($xx['rc'] < 0)
{ // error calling swe_calc_ut();
$planets[$i] = array('error' => $xx['rc']);
continue;
}
$planets[$i] = array(
'name' => swe_get_planet_name($i),
'lng' => $xx[0],
'lat' => $xx[1],
'speed' => $xx[3]
);
}
$out = ['planets' => json_encode($planets, JSON_PRETTY_PRINT)];
# calc house cusps
define("GEO_LNG", 121.5);
define("GEO_LAT", 25.05); // Taipei, Taiwan: 121E30, 25N03
$yy = swe_houses($jul_ut, GEO_LAT, GEO_LNG, "P"); // P = Placidus.
$houses = array();
for($i = 1; $i <= 12; $i ++)
{
$houses[$i] = array('lng' => $yy['cusps'][$i]);
}
$out['houses'] = json_encode($houses, JSON_PRETTY_PRINT);
echo '<pre>';
var_dump($out);
echo '</pre>';
and execute it then with:
php ~/example.php
which should give the result of some planets and houses. We are done now with implementing swephp.so
extension on a macOS Big Sur with PHP version 8
For short analysis and checking of some of our PHP calculations it may be worth to check against with command line tool swetest. As we have already installed PHP extension of Swiss Ephemeris, we have already installed all what we need on our system and need only to compile swetest and add it for easy executing to our $PATH
variable.
cd ~/swephp/php-sweph/sweph/src
make
cd ~
cp ~/swephp/php-sweph/sweph/src/swetest ~/swephp/swetest
nano ~/.zshrc
Put the following line at the end of the opened file from above:
export PATH=$PATH:/Users/$USER/swephp
Activate the new $PATH
variable and test swetest
. ./zshrc
swetest -edir./swephp -eswe -b16.08.2021 -geopos8.54,47.38 -fPLls -p0142536m -sid27
date (dmy) 16.8.2021 greg. 0:00:00 TT version 2.10.02
UT: 2459442.499198167 delta t: 69.278346 sec
TT: 2459442.500000000 ayanamsa = 24° 8'10.4784 (True Citra)
geo. long 8.540000, lat 47.380000, alt 0.000000
Epsilon (m) 23°26'11.2789
Sun 119°13'31.8918 119.2255255 0.9610410
Moon 213°58'15.5311 213.9709809 14.1319143
Mars 136°40'18.4574 136.6717937 0.6334771
Mercury 133°15'15.6205 133.2543390 1.7588360
Jupiter 303°37' 4.9765 303.6180490 -0.1304109
Venus 155°38'37.7671 155.6438242 1.1826970
Saturn 285° 2'30.3615 285.0417671 -0.0708022
mean Node 42°42' 6.9441 42.7019289 -0.0529090
rm -R -f ~/swephp/php-sweph