Nas Apache Web Server



بسم الله الرحمن الرحيم


To host your website on your NAS, please follow the instructions below: 1. Select Services - Web Server. Select the Enable Web server checkbox found under the Web Server heading and then click Apply. Go into your nas Control Panel, and then into Web Services. Then check the box Enable Web Station.

Abstract


  • A tutorial to install the Apache webserver in FreeNAS 9.10 Jail.
  • Configure and enable SSL on Apache.
  • Enable Virtual Hosts.
  • Enable and configure Apache Server Pool Management.
  • Configure Apache to run CGI and Perl scripts.
  • Install and configure php56.

Assumptions and Prerequisites


  • Domain: example.com
  • Hostname: www.example.com
  • System Notification Email: info@example.com
  • OS: FreeNAS 9.10.1-U2 (FreeBSD 10.3-STABLE)
  • Container: Warden Jail
  • Jail Name: www
  • Private IP: 10.0.0.56
  • Subnet Mask: 255.255.255.0/24
  • Server Location: Melbourne, Australia
  • Webserver and Version: Apache v2.4.23_1
  • Apache Document Root Directory: /usr/local/www/apache24/data
  • Apache MPM: Prefork Module
  • Disable Directory Browsing.
  • Allow Over Ride All to .htaccess files.
  • CA Certificate File: /usr/local/etc/ssl/certs/ca.pem
  • SSL Certificate File: /usr/local/etc/ssl/certs/www.example.com.crt
  • SSL Key File: /usr/local/etc/ssl/private/www.example.com.key

Instructions


- Install Apache2.4
# pkg install apache24

- Configure Apache settings
Edit file /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(214) ServerAdmin info@example.com
(222) ServerName www.example.com
(260) Options -Indexes +FollowSymLinks
(267) AllowOverride All
- Set Server Defaults for Production Server
Edit /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(505) Include etc/apache24/extra/httpd-default.conf
Edit /usr/local/etc/apache24/extra/httpd-default.conf
# vi /usr/local/etc/apache24/extra/httpd-default.conf
(55) ServerTokens Prod
Enable apache to run and start on boot.
# sysrc apache24_enable='yes'
Start Apache Server

Qnap Nas Web Server


# service apache24 start
- Generate Self-Signed Certificate Authority, Server Certificate and Key.

Enable SSL

Edit /usr/local/etc/apache24/httpd.conf
Nas apache web server hosting# vi /usr/local/etc/apache24/httpd.conf
(89) LoadModule socache_shmcb_module libexec/apache24/mod_socache_shmcb.so
(144) LoadModule ssl_module libexec/apache24/mod_ssl.so
(513) Include etc/apache24/extra/httpd-ssl.conf
Edit /usr/local/etc/apache24/extra/httpd-ssl.conf
# vi /usr/local/etc/apache24/extra/httpd-ssl.conf
(52) #SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4
(53) #SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4
(65) SSLCipherSuite HIGH:MEDIUM:!SSLv3:!kRSA
(66) SSLProxyCipherSuite HIGH:MEDIUM:!SSLv3:!kRSA
(124) DocumentRoot '/usr/local/www/apache24/data'
(125) ServerName www.example.com:443
(126) ServerAdmin info@example.com
(127) ErrorLog '/var/log/httpd-error.log'
(128) TransferLog '/var/log/httpd-access.log'
(144) SSLCertificateFile '/ust/local/etc/ssl/certs/www.example.com.crt'
(154) SSLCertificateKeyFile '/usr/local/etc/ssl/certs/www.example.com.key'
(175) SSLCACertificateFile '/usr/local/etc/ssl/certs/ca.pem'
Reload new settings for Apache
# service apache24 graceful

Enable Virtual Hosts

- Enable Virtualhosts to redirect traffic from unecrypted port (80) to encrypted port (443).
Edit /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(496) Include etc/apache24/extra/httpd-vhosts.conf
Edit /usr/local/etc/apache24/extra/httpd-vhosts.conf
# vi /usr/local/etc/apache24/extra/httpd-vhosts.conf
(23)
(24) ServerAdmin info@example.com
(25) DocumentRoot '/usr/local/www/apache24/data'
(26) ServerName www.example.com
(27) ServerAlias www.example.com
(28) ErrorLog '/var/log/www.example.com-error_log'
(29) CustomLog '/var/log/www.example.com-access_log' common
(30) Redirect '/' 'https://www.example.com'
(31)
Reload new settings for Apache
# service apache24 graceful


Enable Server Pool Management

Edit /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(478) Include etc/apache24/extra/httpd-mpm.conf
Change the number of concurrent connections for the server from 250 to 50 by editing the /usr/local/etc/apache24/extra/httpd-mpm.conf file
# vi /usr/local/etc/apache24/extra/httpd-mpm.conf
(32) MaxRequestWorkers 50
Reload new settings for Apache
# service apache24 graceful

Enable CGI and Perl Scripts


Edit /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(162) LoadModule cgid_module libexec/apache24/mod_cgid.so
(165) LoadModule cgi_module libexec/apache24/mod_cgi.so
(260) Options -Indexes +FollowSymLinks +ExecCGI
(418) AddHandler cgi-script .cgi .pl
Reload new settings for Apache
# service apache24 graceful

- Create CGI Script to test on Server
Create file /usr/local/www/apache24/data/index.cgi
#vi /usr/local/www/apache24/data/index.cgi
(1) #!/usr/local/bin/perl
(2) print 'Content-type: text/htmlnn';
(3) print '<html>n<body>n';
(4) print '<div style='width: 100%; font-size: 40px; font-weight: bold; text-align: center;'>n';
(5) print 'CGI Test Page';
(6) print 'n</div>n';
(7) print '</body>n</html>n';
Change Permissions of file
# chmod 705 /usr/local/www/apache24/data/index.cgi
- Test Script in Browser
- Create Perl Script to test on Server
Create file /usr/local/www/apache24/data/index.pl
#vi /usr/local/www/apache24/data/index.pl
(1) #!/usr/local/bin/perl
(2) print 'Content-type: text/htmlnn';
(3) print '<html>n<body>n';
(4) print '<div style='width: 100%; font-size: 40px; font-weight: bold; text-align: center;'>n';
(5) print 'Perl Test Page';
(6) print 'n</div>n';
(7) print '</body>n</html>n';
- Change Permissions of file
# chmod 705 /usr/local/www/apache24/data/index.pl
- Test Script in Browser

Install and Enable php56

# pkg install -y php56 mod_php56 php56-mysql php56-mysqli php56-extensions
Create file php56 configuration file /usr/local/etc/apache24/includes/php56.conf
# vi /usr/local/etc/apache24/includes/php56.conf
(1) <FilesMatch '.php$'>
(2) SetHandler application/x-httpd-php
(3) </FilesMatch>
(4) <FilesMatch '.phps$'>
(5) SetHandler application/x-httpd-php-source

Home Nas Server

(6) </FilesMatch>
Reload new settings for Apache
# service apache24 graceful
- Change script preference to execute index.php over index.html
Edit /usr/local/etc/apache24/httpd.conf
# vi /usr/local/etc/apache24/httpd.conf
(281) DirectoryIndex index.php index.html
- Copy php.ini-production to php.ini
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
- Edit file /usr/local/etc/php.ini
# vi /usr/local/etc/php.ini
(936) date.timezone = 'AustraliaMelbourne'
Reload new settings for Apache
# service apache24 gracefulNas apache web servers
- Create php Script to test on Server
Create file /usr/local/www/apache24/data/index.php
# vi /usr/local/www/apache24/data/index.php
(1) <html>
(2) <body>
(3) <div>
(4) <?php

Nas Server Software

(5) print Date('Y/m/d');
(6) ?>
(7) </div>
(8) </body>
(9) </html>
- Test Script in Browser
- Links

Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.

On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install Apache

First, update the available packages by typing the following command into the Terminal:

Then, install the apache2 package with this command:

Test the web server

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type hostname -I at the command line (or read more about finding your IP address).

Browse to the default web page either on the Pi or from another computer on the network and you should see the following:

This means you have Apache working!

Changing the default web page

This default web page is just an HTML file on the filesystem. It is located at /var/www/html/index.html.

Navigate to this directory in a terminal window and have a look at what's inside:

This will show you:

This shows that by default there is one file in /var/www/html/ called index.htmland it is owned by the root user (as is the enclosing folder). In order to edit the file, you need to change its ownership to your own username. Change the owner of the file (the default pi user is assumed here) using sudo chown pi: index.html.

You can now try editing this file and then refreshing the browser to see the web page change.

Your own website

If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

Additional - install PHP

Nas File Server

To allow your Apache server to process PHP files, you'll need to install the latest version of PHP and the PHP module for Apache. Type the following command to install these:

Now remove the index.html file:

and create the file index.php:

Put some PHP content in it:

Now save and refresh your browser. You should see 'hello world'. This is not dynamic but still served by PHP. Try something dynamic:

Nas Apache Web Server Download

or show your PHP info:

Nas Vs File Server

Further - WordPress

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.