December 11, 2018

Mac install Apache/PHP WEB-server

Updated 2019-01-07 

!! Note !! Before Monterey !! 

As a part of one of my projects, the ultimate Weather site ?? Weather34(W34), I needed a WEB-host with PHP and started to use a Raspberry Pi.

In this post You will get some short install tips on Apache with PHP on a Mac with Mojave, macOS 10.14.x, and at the end of the post the W34 installation is done.

For those who want more details, this post is nice.

The Apache WEB server(AWS) is actually installed from the beginning, you just have to start it, in a Terminal window, with 

sudo apachectl start

To check that it is up and running use, in Your Mac WEB browser, the URL 

http://localhost

and "It works" should be displayed

PHP is not active by default so in a Terminal window edit the configuration file with

sudo nano /etc/apache2/httpd.conf

In the editor do a Ctrl + "w", "where is", type "php" and enter which will take You to a line where You remove the starting "#". After editing the line will be

LoadModule php7_module libexec/apache2/libphp7.so

Restart AWS with 

sudo apachectl restart

To check the PHP function create a file with name “phpinfo.php”, with the content

 <?php phpinfo(); ?>

and place it in the document root


/Library/WebServer/Documents/

and then in Your browser check with URL

http://localhost/phpinfo.php

which will display info about the PHP version.

The end of this post will be a guide to install the mentioned weather template W34. On the link You could find additional info which is needed to get it up and running.

The Cumulus version of W34 is now, 2019-01-07, supported by the Cumulus team. There is a Wiki, a Forum, a GitHub repository and a source zip-file for download.

Download the ZIP file expand it and check that a folder with name "CU-HWS-master" is created and it contains several folders and files with the extension .php. 

(Another way, if Git is installed on Your Mac, is

git clone https://github.com/ktrue/CU-HWS.git)

Create a new folder

mkdir CU-HWS-master/add_on

Download/fork the files, "cumulusdata.php" and "realtime.templ", from Github and place them in the "add_on" folder. (The online file "realtime.txt" will be created by the program)

Edit the PHP file, "cumulusdata.php", so that the 3 records in the beginning of the program

$wlink_user = "XXXX"; 
$wlink_pass = "YYYY";
$wlink_apiToken = "ZZZZ";

uses Your credentials to log on to WL.

Rename the "CU-HWS-master" folder to "pws" and move it to 

/Library/WebServer/Documents/pws

The default user and grop for AWS is "_www" so with the command 

sudo chown -R _www:_www /Library/WebServer/Documents/pws

You will fix authority, and then check the site with 

http://localhost/pws/

Do the W34 setup according to the above link and finally set up a cronjob that will fetch weather data from Weatherlink every 5 minutes. With command

sudo EDITOR=nano crontab -e

and adding line

*/5 * * * * php /Library/WebServer/Documents/pws/add_on/cumulusdata.php

Avoiding cron job ? Check this

Don't forget to change "Energy saver" in "System Prefences" so the Mac never goes to sleep.

No comments:

Post a Comment

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !