Table of Contents
Setting up your rPi to host the default website
If you have followed my building an rPi page, you should now have CumulusMX running successfully. You will have access to the CumulusMX Interface as CumulusMX hosts its own site. However, you will not be able to view or see the default public website1).
This section of the wiki will show you how to set up your rPi as a local web host so that you can view and edit the public site locally before uploading your changes to a public system.
Only the first step is essential, all others simply give you more options later on.
Step 1
Installing Apache2
This library enables your rPi to act like a web server and understand and deliver html and javascript code. It also configures the url localhost to include anything that is in the folder /var/www/html/ so that you can view it in your web browser.
Open a terminal window on your rPi and enter the following commands separately:-
sudo apt update sudo apt full-upgrade -y sudo apt install apache2 -y sudo chown <username>:root -R /var/www/html
Change <username> to your user on the rPi
You should now have a working local web host
You should be able to open the browser on your rPi and enter the address localhost and view the Apache2 Debian Default Page.
Conversely, you could enter the IP Address of the rPi in the address bar of any machine on your local network.
Step 2 (optional)
Installing PHP
PHP is a scripting language used in many websites (and some of the other templates available for CumulusMX) to construct dynamic web pages. Unlike JavaScript, that works in your browser, PHP is used to create web page content at the web server, before it is sent to the browser. This enables it to access server resources, which Javascript cannot.
Although this step is optional, it will allow you to access data stored in a MySQL database on your rPi2), as well as use PHP to create your own web pages.
Again in a terminal window enter the following commands…
sudo apt install php libapache2-mod-php -y
Testing
This installation does not provide a ready made testing file like the one provided by Apache2. However, it is not difficult to create one. To start save the file below into /var/www/html/ by clicking on its filename.
Now, in your rPi browser enter the address localhost/about.php. You should see a page confirming the current php configuration. Again, this can be done in any browser on any machine connected to the same local networkby using the rPi's IP address rather than 'localhost'.
Step 3 (optional)
Install Maria Database
This one is a little more complex but as stated above, will allow you to store CumulusMX data in a separate database. For reference you might want to look at RaspberryPi Tips.
Follow these steps:
sudo apt install mariadb-server -y
To make sure that the database is secure you should then enter this command:
sudo mysql_secure_installation
You will be prompted for several responses during this process. Here is some guidance:
- You will be asked for an initial password, there isn't one so just press enter
- Use UNIX Sockets authentication: Answer N
- Set a new password: Answer Y and enter a good password - twice.
- Remove annonymous users: Answer Y
- Disallow root login: Answer Y
- Remove test database: Unless you want to use it answer Y
- Reload Privileges: Answer Y
Once this is done, you will need to set up a new user that you can use to access databases you create - it is not good practice to use the root login.
Follow these commands - carefully
sudo mysql -uroot -p
Enter your password
CREATE USER ‘<user>’ IDENTIFIED BY ‘<password>’; GRANT ALL PRIVILEGES ON *.* TO ‘<user>’ WITH GRANT OPTION; FLUSH PRIVLIEGES; QUIT;
Change <user> and <password> to whatever you want.
To test that you have successfully created this new user open a new terminal window and enter:
mysql -u<user> -p
MySQL should request you chosen password and then open with various prompts. you can type QUIT; to exit.
Step 4 (Optional)
Set up phpMyAdmin
This package allows you to use a browser to look at and manage databases created in MariaDB®. This will make it easier to see how and what CumulusMX is storing when you use the MySQL options. Visit RaspberryTips for further information.
To install phpmyadmin® enter these commands in a terminal window:
sudo apt install phpmyadmin -y
During the installation process you will be prompted to select the scripting language used on your web server. This will appear in a blue popup window.
You will need to select apache2 - press the spacebar to put an Asterix next to this option and press enter.
You will also be asked if you want to configure the database. Answer Y to this prompt. You will need to supply the password you used for MySQL.
Testing
In a browser, either on the rPi or another computer on the local network, enter the address localhost/phpmyadmin or <ipaddress>/phpmyadmin respectively and you should be presented with a phpmyadmin® logon screen. Enter your MariaDB® username and password that you set up in Step 3 above to enter.
If you have used phpmyadmin to manage databases on a public web server you should note that you have full access to this system. Other pages will show you how to configure CumulusMX to create and populate a database for your weather data.
