Actions

LAMP Server

From SharedSkies

The telescope control computers, servers, and workstations at Moore and Mt. Kent Observatories run under Linux, typically the openSUSE distribution with an Xfce desktop environment. The public servers, and increasingly our internal operations, also depend on server-side technology to provide interactive computing and remote access while minimizing the need for software that depends on the end-user's computer system. To this end, we use the Linux-Apache-MySQL-PHP (LAMP) model, and add Python and SQLite for many applications.

This page provides a brief guide to installing these components.


Installation of Apache HTTPD and PHP from Source

From openSUSE using YAST:

Install the standard LAMP server package including --

Apache

MySQL

PHP


Install libsqlite-3-0 to provide SQLite libraries (usually by default)

Install most of Python 2.7 (not yet 3.0, using modules in the list for openSUSE installation at the observatories)


Although we do not use the distribution's Apache and PHP software, we do use MySQL and the default installation provides internal consistency. However, after installation do not start the default Apache server. We install our own Apache and PHP in /usr/local/ so that this does not interfere with the system defaults. While the openSUSE configuration of HTTPD is particularly arcane for small systems and individual users, it offers support through YAST updates. Its installation is described in the openSUSE wiki. When running the default openSUSE LAMP server we follow the guide from the SLES documentation.


Install the Apache server in /usr/local:

From Apache download httpd-2.4.3.tar.gz or the latest stable release and save in /usr/local/src

tar xvzf httpd-2.4.3.tar.gz

cd httpd-2.4.3

Copy or edit the following into ./config.nice:

#! /bin/sh
#
"./configure" \
"--prefix=/usr/local/apache2" \
"--enable-so" \
"$@"

Then run ./config.nice (or run the above commands directly from the command line) and

make

make install

The last command will create /usr/local/apache2 if it does not already exist, and install the software and configuration files there. You will need to edit the configuration file, and start the software using apachectl in /usr/local/apache2/bin (see below).


Install PHP in /usr/local:


From PHP download php-5.4.10.tar.gz and save in /usr/local/src/

cd php-5.4.10


Copy or edit the following into ./config.nice:

#! /bin/sh
#
# Created by configure
'./configure' \
'--prefix=/usr/local/php' \
'--with-gd' \
'--with-zlib' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--with-libdir=/lib64' \
"$@"


Then run ./config.nice (or run the above commands directly from the command line)

make

make install


The last command will add php support to /usr/local/apache2/conf/httpd.conf if it does not already exist, and install the library and configuration files in /usr/local/php. You should copy php.ini-development to /usr/local/phplib64/php.ini .

Configuration of HTTPD

The new configuration file for the Apache HTTPD server is in /usr/local/apache2/conf. This is a single file (unlike OpenSUSE's multiple-file system in /etc/apache2. Simply edit httpd.conf to meet your needs.

Since we use CGI scripting for communicating with hardware, the server must be configured for dynamic content. For more information see the Apache tutorial

http://httpd.apache.org/docs/2.4/howto/cgi.html

For a simple local server enabling cgi and uploads you might have the following entries in addition to the defaults:


LoadModule cgi_module modules/mod_cgi.so
LoadModule php5_module modules/libphp5.so
DocumentRoot "/data/www/htdocs"
User wwwrun
Group www
<Directory "/data/www/htdocs">
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>
<IfModule alias_module>
  ScriptAlias /cgi-bin/ "/data/www/cgi-bin/"
</IfModule>
<Directory /data/www/cgi-bin>
   Options +ExecCGI
   AddHandler cgi-script .cgi .pl .py
</Directory>
<Directory /data/www/htdocs/remote>
  Options +ExecCGI
  AddHandler cgi-script .cgi .pl .py
</Directory>
<Directory /data/www/htdocs/archive>
  AllowOverride AuthConfig  
  AuthType Basic
  AuthName "Restricted Files"
  AuthUserFile /usr/local/apache2/passwd/passwords1
  Require valid-user   
</Directory>
<Directory /data/www/htdocs/upload>
  AllowOverride AuthConfig  
  AuthType Basic
  AuthName "Restricted Files"
  AuthUserFile /usr/local/apache2/passwd/passwords1
  Require valid-user   
  LimitRequestBody  524288000
</Directory>
<IfModule dir_module>
   DirectoryIndex index.html index.php
</IfModule>
<IfModule mime_module>
  AddHandler cgi-script .cgi .py .pl
  AddType application/x-httpd-php .php
</IfModule>

Configuration of PHP

The PHP configuration file is php.ini in /usr/localphp/lib64 . The default file will work as is, but modify for it larger upload and download file sizes. Edit the entries for these two lines and change them to values appropriate for your use, such as

post_max_size = 500M
upload_max_filesize = 500M

Starting and Stopping HTTPD

Control of the local installation of httpd is through /usr/local/apache2/bin/apachectl. You may run this from the command line, and as root to start the server

cd /usr/local/apache2/bin

./apachectl start


or to stop the stop the server

cd /usr/local/apache2/bin

./apachectl stop


For automatic starting at boot, rather than change the system configuration that is already set up for its own server, add this to /etc/rc.d/boot.local -

/usr/local/apache2/bin/apachectl start


Writing CGI Scripts with Python

Once the server is running and responding to CGI scripts written in Bash or Perl, the Python remote telescope operations scripts can be used, and new ones can be added. Python scripts are easy to debug because they will also run from the command line, or they can be tested line by line interactively. For more information see this useful tutorial:

http://www.tutorialspoint.com/python/python_cgi_programming.htm


The CGI script must have permission to access devices, for example those connected to a serial port or on the USB bus. This is achieved by adding wwwrun to groups that have permission to use those devices -- video for the gphoto2 USB cameras, and dialout for the serial ports. See OpenSuse for more information.