How do I install Livecode Server with Apache on macOS version 10.15 to 13.x
The LiveCode Server product brings Livecode's english like script language to the server environment. The server engine is a separate build of the LiveCode engine with specific syntax and functionality that makes it suitable for use in command-line contexts and, in particular, as a CGI processor.
This lesson will walk you through the complete steps required to setup Apache as a local web server using a personal website in the user folder and install LiveCode Server on macOS Version 10.15 (Catalina) to 13.x (Ventura). For MacOS versions < 10.5 please see this lesson.
Apache is the most most popular web server package available today. Apache will allow your machine to function as a web server, hosting websites and serving web pages. By default, macOS comes with Apache installed.
This lessons assumes you have access to your system's Apache configuration files. If you do not, see the the lesson "How to install LiveCode Server with Apache via .htaccess?"
Before starting, it might be good to read the lesson "How do I install LiveCode Server".
2. Setting up Apache as local web server
2.1. Creating a personal website folder
As we are configuring Apache to use a personal website in your user folder, we need to create a folder which will host the Livecode Server executables and all .html and. lc files.
So open your user folder in Finder and create a new folder and name it Sites in case this folder doesn't already exist.
2.2. Changing permissions to edit the files using Textedit.app
To set up Apache as local web server we need to modify some of its configuration files. These are
httpd.conf located in /etc/apache2/
httpd-userdir.conf located in /etc/apache2/extra/
<username>.conf located in /etc/apache2/users/. Each user has their own configuration file. It might be that it already exists, but if not you have to create it. This will be discussed later.
To edit those files you either can use the VI or VIM editor in Terminal.app or use Textedit.app or any other text editor. If you want to use Textedit.app or any other desktop editor, then you have to change the permissions of files before you can save the modified configuration files.
If you are using Vi or Vim in Terminal.app skip the following step and continue with step 2.3
To access your Apache configuration files in Finder, navigate to the folder /etc/apache2/.
To do this, open up Finder, click on the Go menu, select Go to Folder, type in /etc/apache2/ and click on Go. This should open up a new Finder window displaying the contents of the Apache folder.
You should now see a list of files similar to the list below
Right click on httpd.conf and select Get Info. In the upcoming window click on the Sharing & Permissions (1) to see the current file permissions. Clicl on the Lock symbol (2) and enter the username and password of an administrator account. This will enable the small icon bar at the bottom (3).
Press on the + button (4) . In the upcoming windows select your username (5) and press Select (6). In our example we will select the user "Matthias Rebbe" .
The new user is now added to the list under Sharing & Permissions (7). Click now on Read only and select Read & Write to give the user write access to the file httpd.conf.
Repeat the above steps also for the file httpd-userdir.conf which is in the folder /etc/apache2/extra/
and also for the file <username>.conf which is in the folder /etc/apache2/users/ in case it already exists.
If the file <username>.conf does not exist, run the following command in terminal
sudo touch /etc/apache2/<username>.conf
Replace <username> with the short account username (that's also the name of your user folder)
After that run the above steps to set the write permission for that file.
2.3. Modifying the Apache configuration files
2.3.1. Modifying Apache configuration files - httpd.conf
Open the file /etc/apache2/httpd.conf in your editor and make sure that any of the following lines are not commented.
Commented lines begin with the character #. So make sure to remove the # from the beginning of the following lines.
LoadModule cgi_module libexec/apache2/mod_cgi.so LoadModule userdir_module libexec/apache2/mod_userdir.so LoadModule actions_module libexec/apache2/mod_actions.so LoadModule alias_module libexec/apache2/mod_alias.so Include /private/etc/apache2/extra/httpd-userdir.conf
2.3.2. Modifying Apache configuration files - httpd-userdir.conf
Open the file httpd-userdir.conf in your editor and make sure that the following line is not commented.
Commented lines begin with the character #. So make sure to remove the # from the beginning of that line
2.3.3. Modifying Apache configuration files - <username>.conf
Note: In our lesson we will install the LiveCode Server files in the folder /Users/<username>/Sites/cgi-bin/ (step 3.1)
So the sample configuration file we are now creating will use that folder.
Open the file /etc/apache2/users/<username>.conf in an editor and add the following lines to the file. (Replace <username> with the short account username)
<Directory "/Users/<username>/Sites/"> Options Indexes MultiViews # For Apache 2.2 enable the following 2 lines, disable for Apache 2.4 #AllowOverride None #Order allow,deny # For Apache 2.4 enable the following line, disable for Apache 2.2 Allow from all # Livecode Server AddHandler livecode-script .lc # Comment the following line out, if using Livecode Server Pro Action livecode-script /livecode-cgi/livecode-server # Uncomment the following line, if using Livecode Server Pro #Action livecode-script /livecode-cgi/livecode-server-pro Require all granted </Directory>
<Directory "/Users/<username>/Sites/cgi-bin/"> Options ExecCGI # For Apache 2.2 enable the following 2 lines, disable for Apache 2.4 #AllowOverride None #Order allow,deny # For Apache 2.4 enable the following line, disable for Apache 2.2 Allow from all </Directory>
ScriptAlias /livecode-cgi/ /Users/<username>/Sites/cgi-bin/
Replace <username> with the short account username in the above lines.
Save the file.
2.3.4. Granting Apache access to the user folder (macOS >= 12)
This step is only needed, if you are running macOS 12 or higher.
Starting with macOS 12 the user folder cannot be accessed by other users anymore. By default Apache is run using the special user _www.
So we need to grant the user _www access to our user folder. This is done by running the following command in Terminal.app
chmod +a "_www allow execute" /Users/<username>
Replace <username> with the short account username.
2.3.5. Checking the configuration files
To make sure everything is okay with the configuration files, run the following command in Terminal.app
If Syntax ok is returned, then all is fine with the configuration files.
It might be that although Syntax ok is returned, also an error message "httpd: Could not reliably determine the server's fully qualified domain name, using Mac-Studio.local. Set the 'ServerName' directive globally to suppress this message" is returned. You can fix this by defining a server name in file /etc/apache2/httpd.conf. But you can also just ignore that error message and also any other error message that might be returned, as long as Syntax ok is also returned.
If Syntax ok is not returned, you have to check your configuration files again.
2.3.6. Starting Apache
After the configuration test in the previous step was successful, you can (re)start Apache . Run the following command in Terminal.app
sudo apachectl graceful
This is also the preferred method to restart Apache after changing its configuration files. Every time the configuration files have been modified the above command should be run. It tells Apache to reread the current configuration files.
2.3.7. Create & test a webpage
You are now ready to test Apache installation. To do this, create a new file in your editor and add the following code to it
<html> <head> <title>My LiveCode Server Test Page</title> </head> <body> <h1>My Apache Server Test Page</h1> </body> </html>
and save the file as index.html in the Sites folder. As already written the "Sites" folder is the location for all the user's web pages and also for the LiveCode Server executable.
To access the file, navigate to http://localhost/~<username>/ in your browser. The image below shows the expected output
If you can see the expected output, Apache is correctly configured.
3. Livecode Server installation and configuration
Now that Apache is working as supposed, we will take care of LiveCode Server.
This contains the steps to download LiveCode Server and to make sure that Livecode Server is executable and code signed.
3.1. Download LiveCode Server
Begin by downloading the LiveCode server zip file. You'll find Livecode Server download files in your Livecode Account at https://www.livecode.com. You can find detailed instructions in the lesson "How do I install LiveCode Server?".
Unzip the package into your desired location - for example in your home folder. In our lesson we use the following example path /Users/<username>/Sites/cgi-bin/ as location for the extracted Livecode Server files.
This path is later needed when modifying the Apache configuration files (step 2.2.3)
3.2. Ensure LiveCode Server is executable
You will need to ensure the executable bit is set on the livecode-server file and the LiveCode Server folder.
Execute these commands in the terminal to set the executable bits
sudo chmod 755 /<path to LiveCode Server Folder>/
sudo chmod 755 /<path to LiveCode Server Folder>/livecode-server if you have a livecode-server installed
sudo chmod 755 /<path to LiveCode Server Folder>/livecode-server-pro if you have a livecode-server pro installed
So with our example path /Users/<username>/Sites/cgi-bin/
the commands would look like this. Replace <username> with the short account username
sudo chmod 755 /Users/<username>/Sites/cgi-bin/ sudo chmod 755 /Users/<username>/Sites/cgi-bin/livecode-server if you have a Livecode Server installed sudo chmod 755 /Users/<username>/Sites/cgi-bin/livecode-server-pro if you have a Livecode Server Pro installed
3.3. Codesign Livecode Server
Current available Livecode Server downloads will not work out of the box under macOS 12 and macOS 13.
Therefore we first need to code sign all files of the downloaded package.
The syntax is
codesign -s - -f <filepath>
-s asks for signing to be performed
- (hyphen) asks for adhoc signing without any certificate
-f makes sure that any existing signature will be replaced by the adhoc signature
Run the following commands in Terminal.app
If you have Livecode Server
codesign -s - -f /User/<username>/Sites/cgi-bin/livecode-server
If you have LiveCode Server Pro
codesign -s - -f /User/<username>/Sites/cgi-bin/livecode-server-pro
and also all .dylib files
codesign -s - -f /User/<username>/Sites/cgi-bin/revpdfprinter.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/drivers/dbmysql.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/drivers/dbodbc.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/drivers/dbpostgresql.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/drivers/dbsqlite.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/externals/mergJSON.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/externals/mergMarkdown.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/externals/revdb.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/externals/revxml.dylib codesign -s - -f /User/<username>/Sites/cgi-bin/externals/revzip.dylib
3.4. Open all files once in Finder
Due to the fact that the current Livecode Server files are not notarized we need to open/run the Livecode Server files once in Finder to tell Gatekeeper that we trust them.
So in Finder right click each of the files listed in 3.3 and select Open. Confirm that you want to open the file.
When this is done we can test our Livecode Server installation.
4. Create & view a web page
To do this, create a file named test.lc in the Sites folder.
To access the test script, navigate to http://localhost/~<username>/test.lc. in your webbrowser. The above image shows the expected output if "test.lc" contains the following script:
<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>
If you can see the expected output then LiveCode Server was successfully installed and is ready to be used with Apache.
For more detailed information on installing LiveCode server, see the server release notes distributed with the server package
Add your comment