Back to the sore point of getting Server working on MacOS... [SOLVED - FINALLY!]

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Back to the sore point of getting Server working on MacOS... [SOLVED - FINALLY!]

Post by stam » Mon May 01, 2023 11:08 am

Hi all,
with a new laptop and new version of LC server (9.6.9 'pro'), I thought I'd revisit running server. I have never really got his working properly :(. On this attempt, I did this to partly work but it is not functioning correctly. I used a test .lc page published elswhere:

Code: Select all

<html>
<head>
 	 <title>My LiveCode Server Test Page</title>
</head>
<body>
 	 <h1>My LiveCode Server Test Page</h1>
<?lc
 	 put "<p>Hello World! from LiveCode Server</p>"
 	 put "<p>The date is" && the date & "</p>"
?>
</body>
</html>
only the first put renders correctly:
Screenshot 2023-05-01 at 10.53.55.png
Clearly the first 'put' works correctly, but not the second. And while I can get the 'general' site to partially work (ie http://localhost/test.lc) I can't get user site to work with LC server (ie http://localhost/~stam/test.lc doesn't render), although both do work perfectly for html files.

I really don't understand what mistake(s) I've made in setting this up, or why for this matter it should be so difficult. Below is a summary of what I've done based on several previous discussions on the forums and with the inputs from all @LCMark, well as a summary post from @aetaylorBUSBnWt. For my own sanity I split this into sections for Sever/Server files and Apache config files and as long posts are not easy to digest, I'll post each individually.

I would be really very grateful for any advice and pointing out what I've not done right...

Many thanks
Stam
Last edited by stam on Tue May 02, 2023 10:18 pm, edited 5 times in total.

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS...

Post by stam » Mon May 01, 2023 11:15 am

SERVER FILES

I copied the downloaded folder containing LC Server LiveCodeServerPro-9_6_9-Mac to /Library/WebServer/CGI-Executables/

Permissions for server files
For CGI-Executables/ , LiveCodeServerPro-9_6_9-Mac/ , and live code-server-pro executable, all permissions need to be set to 755 (full permissions to owner, read/execute permissions to others):

Code: Select all

sudo chmod 755 /Library/WebServer/CGI-Executables
sudo chmod 755 /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_9-Mac
sudo chmod 755 /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_9-Mac/livecode-server-pro
Codesign server files
I used the shell script provided by @aetaylorBUSBnWt. I created a text file to shell script ’sigd’ — no extension, with the text below, and saved it in /Library/WebServer/CGI-Executables/LiveCodeServerPro-9_6_9-Mac/

Code: Select all

#!/bin/zsh
cp $1 $1-copy
codesign -s - -f $1-copy
rm $1
echo "did codesign & remove"
mv $1-copy $1
In the terminal I then run this shell script on all server files (and thanks once again to @aetaylorBUSBnWt for simplifying this task that @LCMark explained was necessary to codesign all server files):

Code: Select all

./sigd livecode-server-pro
./sigd revpdfprinter.dylib
./sigd drivers/dbmysql.dylib
./sigd drivers/dbodbc.dylib
./sigd drivers/dbpostgresql.dylib
./sigd drivers/dbsqlite.dylib
./sigd externals/mergJSON.dylib
./sigd externals/mergMarkdown.dylib
./sigd externals/revdb.dylib
./sigd externals/revxml.dylib
./sigd externals/revzip.dylib
Gatekeeper: In addition to this, all server files (the executable and all dylib files) are blocked by Gatekeeper, so I right-clicked and selected ‘open’ for each of these to get them whitelisted with Gatekeeper
Last edited by stam on Mon May 01, 2023 11:51 am, edited 6 times in total.

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS...

Post by stam » Mon May 01, 2023 11:21 am

Apache config files

my username is 'stam' in the text below
The config files I modified were:

Code: Select all

/private/etc/apache2/httpd.conf
/private/etc/apache2/extra/httpd-userdir.conf
/private/etc/apache2/users/stam.conf
I found I was unable to save changes to these files as they were owned by 'wheel' and I then assign read/write permissions to myself via Finder -> Get info.

httpd.conf
I uncommented the following lines:

Code: Select all

LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule cgid_module libexec/apache2/mod_cgid.so
LoadModule actions_module libexec/apache2/mod_actions.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
Include /private/etc/apache2/extra/httpd-userdir.conf
I added the following to the end of httpd.conf

Code: Select all

<Directory "/Library/WebServer/CGI-Executables/LiveCodeServer-9_6_9-Mac/">
	Options Indexes MultiViews ExecCGI
	AllowOverride None
	Require all granted
	AddHandler livecode-script .lc
	Action livecode-script /livecode-cgi/livecode-server-pro
</Directory>

ScriptAlias /livecode-cgi/ /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_9-Mac/


httpd-userdir.conf
I uncommented the line

Code: Select all

Include /private/etc/apache2/users/*.conf

stam.conf
I added the following text

Code: Select all

<Directory "/Users/stam/Sites/">
	Options Indexes MultiViews
	AllowOverride None
	Require all granted
	AddHandler livecode-script .lc
	Action livecode-script /livecode-cgi/livecode-server
</Directory>
Last edited by stam on Mon May 01, 2023 11:37 am, edited 1 time in total.

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS...

Post by stam » Mon May 01, 2023 11:31 am

Testing

I put the test.lc file in my first post in the directories:

Code: Select all

/Library/WebServer/Documents
/Users/stam/Sites

I restarted apache with

Code: Select all

sudo apachectl restart

Navigating to http://localhost and http://localhost/~stam shows the correct test html files with the text "It works!" and "My site works!" respectively.

However navigating to http://localhost/test.lc shows the output in my OP.
Navigating to http://localhost/~stam/test.lc just says 'file not found, even though the file test.lc is definitely in /Users/stam/Sites.


Vexing...
Very grateful for expert help with this...
Stam

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS...

Post by stam » Tue May 02, 2023 9:38 am

Further to this, I should mention this was attempted on MacOS Ventura 13.3.1, using server 9.6.9, on an M2 Pro MBP.

I'll also add that resetting everything to default settings and follow the lesson on using .htaccess failed completely (this used to work)
Lesson: https://lessons.livecode.com/m/4070/l/3 ... a-htaccess

After changing settings to what I had previously posted in the comments of that same lesson, I got the same result as my initial post here - unconvincing partial success.

While I'm sure the issue is with what I've done, a part of me wonders if this may be an issue with some kind of change in the default apache installation on MacOS Ventura or some kind of change in 9.6.9 live code-server-pro executable.

Again any insight into what I've done wrong would be really appreciated...
Many thanks
Stam

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9852
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Back to the sore point of getting Server working on MacOS...

Post by FourthWorld » Tue May 02, 2023 2:56 pm

I used to run LC Server on an old Mac, but found the extra setup steps for Apache mods annoying so it's been years. It hasn't got simpler since. ;)

But if it helps, remember that LC Server is only remarkable for the language we enjoy; in general, it's just another CGI. Whether compiled by the LC team or a custom app you wrote yourself in Objective C, setting up a CGI program should be pretty much the same steps.

So if it helps, you should be able to step outside of LC-specific documentation for guidance.

As noted, I have little to offer on this myself, but perhaps you'll see the "a ha!" detail you're looking for in more general guidance on setting up Apache CGI on Ventura:

https://duckduckgo.com/?q=apache+cgi+on ... fpas&ia=qa
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS...

Post by stam » Tue May 02, 2023 10:16 pm

FourthWorld wrote:
Tue May 02, 2023 2:56 pm
perhaps you'll see the "a ha!" detail you're looking for in more general guidance on setting up Apache CGI on Ventura:

https://duckduckgo.com/?q=apache+cgi+on ... fpas&ia=qa
Great suggestion, thank you Richard! (although duckduckgo refused to play ball as it thought our hospital WiFi was a search engine and blocked me... Google was my friend today!).

Turns out the answer came from a 2016 post on how to set up LiveCode Server on 'El Capitan' of all things! It basically showed me that 2 lines were put in the wrong place on all lessons, tutorials and guides I've seen. I've now got it working both on localhost and localhost/~<user>. The clue was in a screenshot that is no longer current (as .pl, .rb, .py CGIs are no longer included by default), and having seen this now I am not sure how other configurations even managed to work...

This did work me for me today:
I put the contents of the folder LiveCodeServerPro-9_6_9-Mac directly into the /Library/WebServer/CGI-Executables/ folder and got rid of said folder (these files and executable were already code signed and made executable, as per my previous post).

The main changes were in the httpd.conf file - I just needed to add 2 lines to the <IfModule mime_module> section of all places, and remove these from everywhere else (various guides had these in the sections for the DocumentRoot, or cgi directory, or <username>.conf or any combination of the above, but should be removed from all). The 2 lines are:

Code: Select all

AddHandler livecode-script .lc
Action livecode-script /cgi-bin/livecode-server-pro
so my <IfModule mime_module> section now looks like this:

Code: Select all

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig /private/etc/apache2/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi
    
    
    # <-- LIVECODE SERVER CONFIGURATION -->
    AddHandler livecode-script .lc
    Action livecode-script /cgi-bin/livecode-server-pro



    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>
My DocumentRoot directory declaration looks like this:

Code: Select all

<Directory "/Library/WebServer/Documents”>
	Options Indexes MultiViews FollowSymLinks
	MultiviewsMatch Any
	AllowOverride None
	Require all granted
</Directory>
And the ScriptAlias section for the cgi binaries, with an added ScriptAlias line:

Code: Select all

#
# "/Library/WebServer/CGI-Executables" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/Library/WebServer/CGI-Executables">
	Options Indexes MultiViews ExecCGI
	AllowOverride None
	Require all granted
</Directory>

ScriptAlias /livecode-cgi/ /Library/WebServer/CGI-Executables/
Finally, the <username>.conf file looks like this

Code: Select all

<Directory "/Users/stam/Sites/">
	Options Indexes MultiViews
	AllowOverride None
	Require all granted
</Directory>
to restart and check configuration, in the terminal:

Code: Select all

sudo apachectl restart
apachectl configtest
Added bonus: to dismiss the warning generated by the apachectl configtest in the terminal (no biggie, but annoying if you are running configtest), uncomment the "ServerName" directive in httpd.conf and set it to

Code: Select all

ServerName localhost

If you don't think it's duplication, I can make a new post with a full guide from start to end to get this running on MacOS Ventura with 9.6.9. Given that this worked for whatever community LC version was current in 2016 and ran on El Capitan it's a safe bet this probably works in all MacOS configurations. But I can't honestly say how much any of this applies to other platforms... (probably not at all)

Thanks once again for making me drop 'Ventura' and '9.6.9' from my searches ;)
A non-trivial portion of my life has been wasted getting this working but it is now :)

Stam

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9852
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Back to the sore point of getting Server working on MacOS... [SOLVED - FINALLY!]

Post by FourthWorld » Wed May 03, 2023 1:31 am

The forums are great for support, but a lousy substitute for good docs.

Maybe the better option would be to send the post to support AT LiveCode.com so the official Lesson on LC Server setup could be updated.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Back to the sore point of getting Server working on MacOS... [SOLVED - FINALLY!]

Post by stam » Wed May 03, 2023 9:59 am

Thanks Richard, I've emailed them my 'complete' guide.
It should be noted that a lot of this can be automated - I don't really have time to write a tool to do this, but may do at some point if no one else does.
I'll post my complete guide below as well.

Many thanks once again,
Stam

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9852
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Back to the sore point of getting Server working on MacOS... [SOLVED - FINALLY!]

Post by FourthWorld » Wed May 03, 2023 10:05 am

Thank you, Stam. Keeping the docs current with OS changes is a lot of work. I appreciate your contribution.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

FINAL: Setting up LiveCode Server on MacOS (9.6.9/Ventura)

Post by stam » Wed May 03, 2023 10:36 am

FINAL: Setting up LiveCode Server on MacOS (9.6.9/Ventura)

NOTES
Web directory is /Library/WebServer/Documents/
cgi-bin folder is /Library/WebServer/CGI-Executables/
User web directory is /Users/<username>/Sites/
Apache configuration files are in /private/etc/apache2/
BBEdit is the easiest tool to edit configuration files

Outline of installation
Download and copy server files to cgi-bin folder
Set permissions and codesign all server files/executable
Edit 3 apache configuration files
Restart apache & test


SERVER FILES
Download zip file with server files - put the contents of the unzipped folder (current version is LiveCodeServerPro-9_6_9-Mac) into the cgi-bin folder Library/WebServer/CGI-Executables.

Set permissions
The server executable and it’s containing folder need to be made executable by all:

Code: Select all

sudo chmod 755 /Library/WebServer/CGI-Executables
sudo chmod 755 /Library/WebServer/CGI-Executables/livecode-server-pro

Codesign server files
Create a text file to shell script (in this example named ’sigd’ — no extension) with the text below - script provided on the forums by @aetaylorBUSBnWt to simplify this task that @LCMark explained was necessary to codesign all server files on more modern MacOS versions.

Code: Select all

#!/bin/zsh
cp $1 $1-copy
codesign -s - -f $1-copy
rm $1
echo "did codesign & remove"
mv $1-copy $1
Save it to /Library/WebServer/CGI-Executables/ and cd there in the terminal. Run this shell script on all server files:

Code: Select all

./sigd livecode-server
./sigd revpdfprinter.dylib
./sigd drivers/dbmysql.dylib
./sigd drivers/dbodbc.dylib
./sigd drivers/dbpostgresql.dylib
./sigd drivers/dbsqlite.dylib
./sigd externals/mergJSON.dylib
./sigd externals/mergMarkdown.dylib
./sigd externals/revdb.dylib
./sigd externals/revxml.dylib
./sigd externals/revzip.dylib

Gatekeeper
right-click and ‘open’ the server executable and *all* .dylib files to whitelist them in gatekeeper



APACHE CONFIG FILES
These are:
/private/etc/apache2/httpd.conf
/private/etc/apache2/extra/httpd-userdir.conf
/private/etc/apache2/users/<username>.conf

** If unable to save changes to these files then assign read/write permissions to yourself (eg via Finder -> Get info). Using BBEdit you'll be asked to authenticate to save changes.


httpd.conf
Summary: Uncomment 5 lines, Change 1 line, Add 3 lines

Uncomment (remove the ‘#’) the following lines:

Code: Select all

LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule actions_module libexec/apache2/mod_actions.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
Include /private/etc/apache2/extra/httpd-userdir.conf

Edit section <IfModule mime_module>. This is the main change from previous tutorials/guides/lessons, but was valid for installing Community version of livecode-server in 2016 on MacOS El Capitan, so probably valid for most/all MacOS configurations.
Source: https://www.linkedin.com/pulse/livecode ... ark-clark/

If you have these lines any in any other location, delete them or the installation won't work.
Below the line #AddHandler cgi-script .cgi add the optional comment and 2 lines of code:

Code: Select all

# LIVECODE CONFIG
AddHandler livecode-script .lc
Action livecode-script /cgi-bin/livecode-server-pro

Edit section for CGI directory declaration by changing Options from None to Indexes MultiViews ExecCGI, and add a ScriptAlias line below this declaration

Code: Select all

# "/Library/WebServer/CGI-Executables" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/Library/WebServer/CGI-Executables">
	Options Indexes MultiViews ExecCGI
	AllowOverride None
	Require all granted
</Directory>

ScriptAlias /livecode-cgi/ /Library/WebServer/CGI-Executables/


OPTIONAL: To remove the warning generated by the terminal command apachectl configtest, uncomment the Servername directive and change it to

Code: Select all

Servername localhost



httpd-userdir.conf
Uncomment the line

Code: Select all

Include /private/etc/apache2/users/*.conf



<username>.conf
Set the text of this file to the below (where <username> is the short account name)

Code: Select all

<Directory "/Users/<username>/Sites/">
	Options Indexes MultiViews
	AllowOverride None
	Require all granted
	AddHandler livecode-script .lc
	Action livecode-script /livecode-cgi/livecode-server
</Directory>

Make everything in the user directory executable by the special user _www, as per advice on a •User tip• on the Apple forums, by running this in terminal, but unsure if this is actually needed (I did however do this in my long attempt to get this working):

Code: Select all

chmod +a "_www allow execute" ~
Source: https://discussions.apple.com/docs/DOC- ... login=true




RESTART AND TEST
Test file
Create a text file with the suffix .lc, eg test.lc with the following text and save to /Library/WebServer/Documents and /Users/<username>/Sites

Code: Select all

<html>
<head>
 	 <title>My LiveCode Server Test Page</title>
</head>
<body>
 	 <h1>My LiveCode Server Test Page</h1>
<?lc
 	 put "<p>Hello World! from LiveCode Server</p>"
 	 put "<p>The date is" && the date & "</p>"
?>
</body>
</html>


Restart apache
In the terminal, restart apache and check it’s configuration

Code: Select all

sudo apachectl restart
apache configtest

Assuming syntax is OK then check installation by opening the files in a browser:
http://localhost/test.lc — for the /Library/WebServer/Documents/test.lc file
http://localhost/~<username>/test.lc — for the /Users/<username>/Sites/test.lc file

If all goes well, you should see a page stating:

Code: Select all

My LiveCode Server Test Page

Hello World! from LiveCode Server

The date is 5/3/23
I hope this helps!
Stam

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”