LiveCode Server and M2 processor? [SOLVED]

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

LiveCode Server and M2 processor? [SOLVED]

Post by stam » Mon Nov 07, 2022 9:27 pm

Hi all,

I'm wondering if I've stumbled onto an issue with LC Server - I use this currently for linting code with FerrusLogic's excellent VSCode plugin https://forums.livecode.com/viewtopic.p ... ic#p213010

However I've run into a problem since migrating to a fancy new M2 MBA: setting the server file path that the plugin requires no longer works.
When downloading the latest version (seems to be version 9.6.8) and putting it either in my /Applications folder or my Documents folder and copying the path VSCode now throws an error:
Screenshot 2022-11-06 at 15.04.04.png

I assumed this may be a permissions error so ran a chmod 777 on It as a test - when VSCode attempts to access the server executable now, it throws a system error that the executable is damaged and should be moved to the bin.

Just wanted to check: is LC Server executable actually compatible with M2 architecture/rosetta2?
If it is, does anyone have any idea how to fix the issue?

Thanks in advance
Stam

-----------------------
** Title edited to remove '(issue with FerrusLogic's VSCode plugin)' as that turned out not to be the problem - see below
-----------------------
Last edited by stam on Mon Nov 14, 2022 12:58 pm, edited 3 times in total.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: LiveCode Server and M2 processor? (Issue with FerrusLogic's VSCode plugin)

Post by LCMark » Tue Nov 08, 2022 12:42 pm

@stam: So a recent update to macOS on arm macs has tightened the verification of executables. We need to tweak what we do to the server engines we ship to make it work out of the box... However, you can resolve the issue yourself by doing:

Code: Select all

cp server server-copy
codesign -s - -f server-copy
rm server
mv server-copy server
This re-applies an ad-hoc (tied to local machine) signature to the executable.

Btw, the reason for the little cp/rm/mv dance around it is that macOS ties codesignature verification to the inode number of the file - so you can't resign an executable in place, you have to make a copy and resign that.

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

Re: LiveCode Server and M2 processor? (Issue with FerrusLogic's VSCode plugin)

Post by stam » Sun Nov 13, 2022 7:20 am

LCMark wrote:
Tue Nov 08, 2022 12:42 pm
This re-applies an ad-hoc (tied to local machine) signature to the executable.
Thanks Mark,

I followed your instruction and it seemed to progress a bit. I had to do the same procedure to 2 other dylib files following similar errors after resolving the first.

However when trying to run the VSCode plugin from FerrusLogic, I now get a different error:
Screenshot 2022-11-13 at 06.19.58.png
I'm at a loss... grateful for help on this!
Stam

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

Re: LiveCode Server and M2 processor? [SOLVED]

Post by stam » Mon Nov 14, 2022 12:54 pm

Further to this - it finally got it to work by repeating the cp/rm/mv dance, as Mark put it, for all 10 of the included .dylib files as above
I then had to open both the server executable and all 10 .dylib files with the right-click->open->open process to get round GateKeeper...

Hopefully in the future this will be automated as it proved to be quite a tedious process... and presumably affects every possible use of server on Ventura (not just for linting...)

S.

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

Re: LiveCode Server and M2 processor? [SOLVED]

Post by stam » Mon Nov 14, 2022 1:16 pm

An additional note for anyone else with a similar issue:

In trying to fix this I had changed permissions (trying both 755, 775 and 777 out of desperation) with chmod.
The sever file was no longer (or perhaps never was?) executable after this.

To fix I also need to run this in terminal:

Code: Select all

sudo chmod +x <path-to-livecode-server-file>
S.

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Sep 20, 2012 5:11 pm

Re: LiveCode Server and M2 processor? [SOLVED]

Post by aetaylorBUSBnWt » Mon Jan 30, 2023 5:35 pm

Hi,

I hit the errors described in this thread and others and after a few days of going in circles, got a response back from Panos that pointed me to another thread that had more information and finally a mistake I made that eventually got the problem solved. That "mistake" happened while I was trying to do this "install" on another machine.
I suspect that there were two or three specific problems:

1. providing "755" permission access high enough UP the directory levels that contain the LiveCodeServer.
2. application signature issues that Apple introduced at some point that cause liveCodeServer-968 to not function unless you "re-signature" all executable files in the LiveCodeServer distribution.
3. I forget.

Reiterating some of the information in the lesson, changes you need to make, top to bottom:

In httpd.conf, remove the leading "#" (uncomment) to enable the following directives:
(these are not sequential in the httpd.conf file)

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

There is also a cgid_module line in httpd.conf. In my last round of modifications I did NOT enable that line despite the fact that the Apache documentation suggests that it will run the cgi_module if the cgid_module does not execute. In my past testing, the cgid_module seemed to cause a problem, but it might have been other things wrong.

In the /private/etc/apache2/extra/httpd-userdir.conf, remove the leading "#" (uncomment)
for the following line:

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

Now where does the LiveCodeServer-xxxxxx folder go?
Well wherever it goes, you need to make sure that there is executable permission high enough UP the directory chain.
I wanted to make the installation more general, not something living in my User folders.
There appears to be a standard directory for WebServers - at least for Apache on the Mac that is not associated with the logged in User.

/Library/WebServer/CGI-Executables

So for me I put the LiveCodeServer-9_6_8-Mac folder in there.

Followed up with the commands:

sudo chmod 755 /Library/WebServer/CGI-Executables
sudo chmod 755 /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_8-Mac
sudo chmod 755 /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_8-Mac/livecode-server

THE FIRST chmod command is the CRUCIAL, NEVER DONE BEFORE that I did when trying this whole process over again on another machine. You need to be certain that the folder that you put the downloaded LiveCodeServer-9_6_8-Mac folder into has the correct permissions TOO!


The next step is somewhat dependent upon what version of MacOS that you have. It is definitely required for a MacBook Pro M1 or M2 running on macOS 13.

The livecode-server file and the .dylib files accompanying it do not have the appropriate Apple signature to execute. (Hopefully RunRev will fix this ASAP!) So for now, it has to be done after it has been copied into the destination folder you want to execute from. You can either execute these commands individually for each file or try using the script I include below. This set of commands came from LCMark via the "LiveCode Server and M2 processor" thread
(if anybody knows how to generalize this and apply it to the directories - please enhance and let the rest of us know!)

I named the script "sigd" for signature dance. - call it what you want. I put it in the LiveCodeServer-9_6_8-Mac folder.

Code: Select all

#!/bin/zsh
cp $1 $1-copy
codesign -s - -f $1-copy
rm $1
echo "did codesign & remove"
mv $1-copy $1
Caveat: The above shell script is stating it uses z shell - what Apple recommends now. If you are running a different shell in Terminal, maybe the script will work or delete the first line or find out how to specify the shell you are running in Terminal. (it may be as simple as replace zsh for bash in the case of running bash)

Now with "LiveCodeServer-9_6_8-Mac" as the current directory in Terminal...
So now you do:

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
Hah, well that is easier for you all, since I just copied all the commands that I had to type.
Well maybe the above set can be a script too!

Hey RunRev, how about you fix the download so it has a script in it that does the chmod changes and then the signature dance process!
(or if some steps have to be done manually, put those in the script file too (with documentation) so people have one place to find out how to do all this.)

Next step you have to do manually. (stam discovered this nuisance)
Control Click - Open each of the above files and click Open (or NOT cancel if it is not "Open") in the dialog box that comes up. You need to run each of these executables manually once because otherwise the macOS will refuse to run them ever.


OK, now I believe you have an executable livecode-server.
Now for setting up Apache to notice the livecode-server.

From what I have discovered so far, in whatever directory you want to have LiveCode scripts, you need to tell Apache about that via a .conf file.

Two standard folders would be the logged in user and what appears to be an Apache standard:
/Library/WebServer/Documents

For the logged in user, your LiveCode scripts (files with a suffix of .lc) go into a folder named "Sites".
In my case: /Users/andrewtaylor/Sites/
I have a .conf file named: andrewtaylor.conf and it lives in the /private/etc/apache2/Users/ folder.
Below are the contents of that file.

Code: Select all

<Directory "/Users/andrewtaylor/Sites/">
Options Indexes MultiViews
AllowOverride None
Require all granted
AddHandler livecode-script .lc
Action livecode-script /livecode-cgi/livecode-server
</Directory>
Caveat:
IF you are running an Apache PRIOR to 2.4:
then instead of "Require all granted"
use:
Order allow,deny
Allow from all

Now since I want to have the LiveCode Server in a spot where it can be used by any User, I put it at a system level instead of in a folder in my user area.
So I put the following at the end of the httpd.conf file that was modified up above.

Code: Select all

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


#ScriptAlias /livecode-cgi/ /Users/andrewtaylor/Sites/LiveCodeServer-9_6_8-Mac/
ScriptAlias /livecode-cgi/ /Library/WebServer/CGI-Executables/LiveCodeServer-9_6_8-Mac/
Caveat:
IF you are running an Apache PRIOR to 2.4:
then instead of "Require all granted"
use:
Order allow,deny
Allow from all

IF instead you are going to put LiveCode Server in your User folder somewhere (I had it in "Sites" for a while), then you would add the above code to the end of your "username".conf file. You would also uncomment and modify the ScriptAlias line to point to your user folder. (uncomment means delete the '#').
Then comment out the line with ScriptAlias point to the CGI-Executables folder.(or just delete the line).

SetHandler vs AddHandler?
I came across a website that recommends using SetHandler for security purposes. If you use SetHandler then Apache will only execute files it finds in that directory - it will NOT display. So hackers can't look at your files.
If you use SetHandler livecode-script instead, then .html and .lc files still execute, but the PosterChild HTML5 lesson example will NOT work.
I don't know what other advantages or disadvantages occur as a result of that change.

All done? (almost!)

Be good to test all this.

So you need a .lc file. (here is the one from the lesson - as updated by Panos today)

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>
Call it what you want: "something.lc" and put it in the "Sites" folder.
That is: /Users/username/Sites, where username is your login, in my case: andrewtaylor.

For testing the general installation, .lc files that live in WebServer/Documents, you need one for there too.

Make a copy of the above file, I suggest you give it a different name just so you are sure it ran

When you are putting stuff into the "not your user folder" areas you will need to deal with permissions to write into those areas. Not a big deal if you are your machine's admin.


A couple more things, then you can test!

From the Terminal command line:

sudo apachectl restart

Then double check the configuration by:

apachectl configtest

You should only get one error from the above. It will complain about server's domain name:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.233. Set the 'ServerName' directive globally to suppress this message

This is not a problem - you can ignore it unless you want to be public. In which case search for "ServerName" in the httpd.conf and update per the information in there. The IP address above is my machine at the moment - I move around so it changes - it will be whatever your machine is at the moment you run the command.


NOW YOU CAN TEST!

Go to your browser and type:

http://localhost/~andrewtaylor/sitesScript.lc

or

http://localhost/docscript.lc

In the above replace "andrewtaylor" with your username and "sitesScript" with what you named that test script file.
NOTE THE '~' THAT IS BEFORE THE username! IT IS REQUIRED!

For the second test, I named the script I put into WebServer/Documents, "docscript.lc"

Both should return the following:

Hello World! 1/29/23 8:41 PM

(actually the date and time you run the script)

I had no knowledge of Apache and how to interact with it prior to spending a couple days digging this out from the lesson and various posting from others trying to solve this problem. Hopefully I have documented the entire process properly and completely in one place so others need not go through this yet again!

Post Reply

Return to “Talking LiveCode”