[SOLVED - partially] LC Server (Indy)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

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

Re: [SOLVED - partially] LC Server (Indy)

Post by stam » Mon Aug 31, 2020 12:15 am

I managed to get this working, in a fashion.
Sadly any variation of httpd.conf settings i've tried failed and i was not able to get the above working at all.

I did however find some helpful advice on an apple support forum that allowed me to run this via .htaccess (there are missing steps in the lesson on this, which is why i couldn't get that to work originally either - I'll also post this as a comment on the .htaccess lesson as an FYI).
Apache documentation advises against using .htaccess if possible because of the increased overhead/server load, but so far this is the only way i can get server to work on mac.

For others that may find this helpful:
- Use BBEdit - best way to edit Wheel-owned documents.
- The cgi-bin folder is /Library/WebServer/CGI-Executables/
- The documents to serve (.html and .lc) go into the folder /Library/WebServer/Documents/
- The apache installation lives in /etc/apache2/

Steps
1. Put all the downloaded 'server' files in the cgi-bin folder (the livecode-server file, the drivers and externals folders)
2. Use Terminal.app to navigate to this folder and make the livecode-server file executable by running chmod:

Code: Select all

sudo chmod 755 livecode-server
3. Using BBEdit, open the file: /etc/apache2/httpd.conf and uncomment these lines (remove the #):

Code: Select all

#LoadModule cgid_module libexec/apache2/mod_cgid.so

Code: Select all

#LoadModule cgi_module libexec/apache2/mod_cgi.so

Code: Select all

#LoadModule actions_module libexec/apache2/mod_actions.so

Code: Select all

#LoadModule alias_module libexec/apache2/mod_alias.so          ##This last module was already enabled for me, but worth checking.

4. In /etc/apache2/httpd.conf file, in the section <Directory "/Library/WebServer/Documents"> scroll down to the section that allows .htaccess to run directives (described in comments) and change

Code: Select all

AllowOverride None
to

Code: Select all

AllowOverride All
Save the httpd.conf file (if not using BBEdit you may have to create duplicate, save it elsewhere and then drop it into /etc/apache2/ and replace the existing file after authenticating).

5. In BBEdit, create new file with the following text:

Code: Select all

Options ExecCGI
AddHandler livecode-script .lc
Action livecode-script /cgi-bin/livecode-server
and save this file in the directory /Library/WebServer/Documents/ with the name .htaccess

6. Restart apache

Code: Select all

sudo apachectl restart
Now http://localhost/test.lc renders correctly.
This is the only way i could get this to work for me using apache 2.4 on MacOS Catalina

If anyone can advise how to to run this without using .htaccess would be really grateful for advice...
Last edited by stam on Mon Aug 31, 2020 3:11 pm, edited 1 time in total.

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

Re: [SOLVED - partially] LC Server (Indy)

Post by stam » Mon Aug 31, 2020 3:02 pm

For what it's worth, this works with MAMP as well (i've only tested apache, not nginx)

On Mac, the relevant files are in /Applications/MAMP/
The default httpd.conf in /Applications/MAMP/conf/apache/ is configured correctly and needs no modification.
Save the above .htaccess file to /Applications/MAMP/htdocs/
Copy the server files to /Applications/MAMP/cgi-bin/
Make the livecode-server executable as above.
Put the test file in the 'htdocs' folder and restart the server.

As the default port for MAMP is 8888, the test file can be rendered with the URL http://localhost:8888/test.lc
(this works fine in parallel with the built-in apache on port 80)

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

Re: [SOLVED - partially] LC Server (Indy)

Post by FourthWorld » Mon Aug 31, 2020 4:54 pm

Will this eventually be moved to a public server, or will it remain strictly in-house?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: [SOLVED - partially] LC Server (Indy)

Post by stam » Mon Aug 31, 2020 5:41 pm

Hi Richard, for now this is for testing purposes only, and in-house only... so i imagine .htaccess should be ok.
Just don't like not be able to get things to work :)

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

Re: [SOLVED - partially] LC Server (Indy)

Post by aetaylorBUSBnWt » Mon Jan 30, 2023 5:37 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!

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

Re: [SOLVED - partially] LC Server (Indy)

Post by aetaylorBUSBnWt » Tue Jan 31, 2023 2:54 am

And just one more tidbit.

After doing all that work, lets reap a few rewards.
How about accessing a livecodescript stack and read some input and send it back?
Yes the following is trivial, but a beginning.
A public website - not localhost!

In order to go public, as far as I know, you will need to put these files into /WebServer/Documents.
Which means dealing with sudo permissions on every change.
I am sure that there are security concerns I am not addressing here.
Anyway:

I modified a script from a Server lesson about $_GET

Code: Select all

<?lc

start using stack "testServerStack.livecodescript"
put getCompany($_GET["company"]) && return && readCompany()

//  put "Your company name is" && $_GET["company"]

?>
I saved the above as test.lc in /WebServer/Documents

Then the livecodescript:

Code: Select all


function getCompany pCompany
   return "Company Name from " && pCompany
end getCompany

function readCompany
   return "Read GET global<" && $_GET["company"]
end readCompany
named testServerStack.livecodescript and put into /WebServer/Documents

Then via the MessageBox in LiveCode IDE I typed:
put URL "http://<my-domain-name>/test.lc?company=RunRev" into message

and the following appears in the MessageBox:
Company Name from RunRev
Read GET global< RunRev

You don't get two lines back as you would expect in the MessageBox, but if you copy that text out and paste it anywhere else, that "return" is present - along with some extra spaces.

There is another global $_POST and a command called "load" for doing asynchronous getting of information from the server.
All boring to the experts, but for me - IT WORKS!
(and I don't have to learn java, php, ....)
:D

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: [SOLVED - partially] LC Server (Indy)

Post by mwieder » Tue Jan 31, 2023 3:08 am

Wow. You went through some serious contortions there to get things running. Congrats.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”