{"id":1917,"date":"2019-02-15T01:03:27","date_gmt":"2019-02-15T01:03:27","guid":{"rendered":"http:\/\/www.richa1.com\/RichardAlbritton\/?p=1917"},"modified":"2019-12-12T16:05:56","modified_gmt":"2019-12-12T16:05:56","slug":"wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt","status":"publish","type":"post","link":"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/","title":{"rendered":"Wireless NAT server E-ink badge with Apache, PHP, SQL, Media Wiki, and MQTT"},"content":{"rendered":"<h3>Intro<\/h3>\n<p>This will walk you through setting up a Raspberry Pi Web server with Raspbian Buster Lite. The following services will be installed and available by the end of this tutorial.<\/p>\n<ol>\n<li>Apache web server<\/li>\n<li>MySQL database<\/li>\n<li>PHP<\/li>\n<li>MediaWiki<\/li>\n<li>MQTT<\/li>\n<\/ol>\n<p><!--more--><\/p>\n<h3>What You Need<\/h3>\n<h3>Setting Up Your Pi<\/h3>\n<p>First we will need to set your Raspberry Pi up with SSH and get it connected to the internet via WiFi.<\/p>\n<p>This tutorial will help you get that going:<\/p>\n<p><a href=\"http:\/\/www.richa1.com\/RichardAlbritton\/setting-up-a-pi-zero-w\/\" target=\"_blank\">SETTING UP A PI ZERO W<\/a><\/p>\n<h3>Installing Apache<\/h3>\n<p>Now that we have the Pi connected to the Internet and logged in via SSH, it is time to install our web server. We will be using Apache because like everyone uses it and it is free. Apache is software that runs on a server to\u00a0handle all the stuff like HTML and HTTP data. Basically all the cool stuff that we see in our web browsers.<\/p>\n<p>From your Pi&#8217;s SSH window, run the following commands:<\/p>\n<pre class=\" language-bash\"><code class=\" language-bash\">sudo apt-get install apache2 -y<\/code><\/pre>\n<p>This may take a bit of time to install&#8230;<\/p>\n<p>Next we can test this install by going to the IP address assigned to the Pi from any web browser on your network.<\/p>\n<p>Get the IP address of your Pi by running the command:<\/p>\n<pre class=\"lang:default decode:true\">hostname -I<\/pre>\n<p><img loading=\"lazy\" class=\"wp-image-1925 size-medium alignright\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/apache-it-works-300x238.png\" alt=\"apache-it-works\" width=\"300\" height=\"238\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/apache-it-works-300x238.png 300w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/apache-it-works-768x609.png 768w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/apache-it-works.png 804w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><br \/>\nYour IP address should start with something like <span style=\"color: #993300;\">192.168.<\/span> My Pi was given the address <span style=\"color: #993300;\">192.168.1.87<span style=\"color: #000000;\"> so if I type that into the address bar of my web browser, I get a page that looks like this:<\/span><\/span><\/p>\n<p>Now we know that Our web server is running. You should also be able to get the same page by going to\u00a0<a href=\"http:\/\/raspberrypi.local\/\" target=\"_blank\">http:\/\/raspberrypi.local\/<\/a><\/p>\n<h3>Install MySQL and PHP<\/h3>\n<p>First we will install MySQL<\/p>\n<pre class=\"lang:default decode:true\">sudo apt install mariadb-server<\/pre>\n<p>Now we will install PHP<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get install php libapache2-mod-php -y<\/pre>\n<p>Remove the index.html page from your www\/html folder.<\/p>\n<pre class=\"lang:default decode:true\">sudo rm \/var\/www\/html\/index.html<\/pre>\n<p>We will replace this file with an index.php page.<\/p>\n<pre class=\"lang:default decode:true\">sudo\u00a0nano \/var\/www\/html\/index.php<\/pre>\n<p>Add the following code to the file:<\/p>\n<pre class=\"lang:php decode:true\" title=\"index.php\">&lt;?php phpinfo(); ?&gt;<\/pre>\n<p>Exist and save this file.<\/p>\n<p>Now go to\u00a0<a href=\"http:\/\/raspberrypi.local\/\" target=\"_blank\">http:\/\/raspberrypi.local\/<\/a> and you should see a bunch of info about your PHP install.<\/p>\n<p>We need to create an account for the Database so run the following code.<\/p>\n<pre class=\"lang:default decode:true\">sudo mysql -p -u root<\/pre>\n<p>Set a password for this user, then when MariaDB is loaded, run the following command but replace <em><span style=\"color: #993300;\">username<\/span><\/em> and <em><span style=\"color: #993300;\">password<\/span><\/em> with one of your choosing.<\/p>\n<pre class=\"lang:default decode:true\">GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';<\/pre>\n<p>Remember this password and username as you will need it later. Close the Database:<\/p>\n<pre class=\"lang:default decode:true\">quit<\/pre>\n<p>Restart the MySQL service:<\/p>\n<pre class=\"lang:default decode:true\">sudo service mysql restart<\/pre>\n<h3>Install MediaWiki<\/h3>\n<p>For those of you unfamiliar with a Wiki, this is basically like an HTML interface for a Database on a web server. It means that to don&#8217;t need a web browser to create, edit, or organize new pages. Wikipedia runs on MediaWiki and it is perfect for our own use on our new Pi server.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Wiki\" target=\"_blank\">Click here<\/a> for more information on what a Wiki is.<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get install mediawiki<\/pre>\n<p>This one will take a while to install. Basically we are creating a Content Management System (CRM). This is the backbone of what most people consider the internet and it consists of a few applications working together.<\/p>\n<ul>\n<li>Apache handles communication between the server\u00a0(your Pi) and client (the person browsing your site).<\/li>\n<li>MySQL is a Database that runs on the server and is protected from the outside world.<\/li>\n<li>PHP filters requests for data from the client and sends it it back, if the client has permission to get said data. It also handles the dynamic assembly of HTML files that get served through Apache. That way sensitive data is not exposed in the code going out to the client.<\/li>\n<li>MediaWiki is basically a UI that has been pre-written for use with PHP and MySQL.<\/li>\n<\/ul>\n<p>This is all a bit overly simplified, but that is the basics anyway.<\/p>\n<p>Restart the Apache server<\/p>\n<pre class=\"lang:default decode:true\">sudo \/etc\/init.d\/apache2 restart<\/pre>\n<p>If all worked out, you should be able to go to\u00a0<a href=\"http:\/\/raspberrypi.local\/mediawiki\/\" target=\"_blank\">http:\/\/raspberrypi.local\/mediawiki\/ <\/a>and see this page:<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-1927 aligncenter\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/Capture.png\" alt=\"Capture\" width=\"274\" height=\"273\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/Capture.png 274w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/Capture-150x150.png 150w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2018\/07\/Capture-50x50.png 50w\" sizes=\"(max-width: 274px) 100vw, 274px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3><\/h3>\n<ol>\n<li>Click the link to set up the wiki<\/li>\n<li>Select your desired language<\/li>\n<li>The next page checks to see if things are working correctly. If you see some green text that says &#8220;<span style=\"color: #008000;\">The environment has been checked. You can install MediaWiki.<\/span>&#8221; then click the <strong>Continue<\/strong> button.<\/li>\n<li>Skip down to <strong>Database username.<\/strong><\/li>\n<li>Enter the username that you created for MySQL earlier.<\/li>\n<li>In the <strong>Database password<\/strong> field, enter the password set up for the MySQL user.<\/li>\n<li>Click the <strong>Continue<\/strong> button.\n<ul>\n<li><em><span style=\"color: #993300;\"><strong>Note:<\/strong> If the connection to MySQL fails, they the steps found in\u00a0<a style=\"color: #993300;\" href=\"http:\/\/www.richa1.com\/RichardAlbritton\/cant-get-mediawiki-to-connect-to-mysql-using-root-password\/\" target=\"_blank\"><strong>this post<\/strong>.<\/a><\/span><\/em><\/li>\n<\/ul>\n<\/li>\n<li>Leave these settings alone and just click the\u00a0<strong>Continue<\/strong>\u00a0button.<\/li>\n<li>Enter in a name that you want to use for this Wiki.<\/li>\n<li>Skip down to the Administrator account.<\/li>\n<li>Fill in all of the information to set up a login for making changes to the Wiki via the browser interface.<\/li>\n<li>Click the\u00a0<strong>Continue<\/strong>\u00a0button.<\/li>\n<li>Select the desired <strong>User rights profile<\/strong>.<\/li>\n<li>Do not enable <strong>E-mail settings<\/strong> unless your Raspberry Pi will be connected to the internet rather than a NAT.<\/li>\n<li>Check the boxes next to any Extensions you wish to add to your Wiki.<\/li>\n<li>Be sure to check the <strong>Enable file uploads<\/strong> so that you can add photos later.<\/li>\n<li>Click the\u00a0<strong>Continue<\/strong>\u00a0button.<\/li>\n<li>Once this is done, click\u00a0the\u00a0<strong>Continue<\/strong>\u00a0button.<\/li>\n<li>The page should now say that your settings file is complete.<\/li>\n<li>Click the Download <strong>LacalSettings.php<\/strong> link.<\/li>\n<li>Open this file with a Notepad++<\/li>\n<\/ol>\n<p>In the SSH window\u00a0run the following command:<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/var\/lib\/mediawiki\/LocalSettings.php<\/pre>\n<p>Select all of the text in the\u00a0<strong>LacalSettings.php\u00a0<\/strong>file and copy it.<\/p>\n<p>Click on the SSH window, which should now have a blank file open, then, right click on the center of the window. All of that text should start to appear in the file. Once done, save and close the\u00a0<strong>LacalSettings.php<\/strong> in the SSH window.<\/p>\n<p>Now go to\u00a0http:\/\/raspberrypi.local\/mediawiki\/ and see if your new Wiki is all set up. If it works, there should be all kinds of resources for editing pages once you are logged in.<\/p>\n<h3>Install Samba<\/h3>\n<p>Samba makes it easy to share files over a network without having to use FTP. Once installed, your Pi will show up as a regular network drive.<\/p>\n<p>From the SSH window run:<\/p>\n<pre class=\"lang:default decode:true\">sudo apt update &amp;&amp; sudo apt full-upgrade -y\r\n\r\nsudo apt-get install samba samba-common-bin<\/pre>\n<p>Once finished we need to make a shared folder and set permissions for it. The 1 prevents this folder from being deleted by accident. The 777 sets it so that all users can read\/write\/execute files in this folder.<\/p>\n<pre class=\"lang:default decode:true\">sudo mkdir -m 1777 \/share<\/pre>\n<p>Now we need to add some setting to the smb.conf file<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/samba\/smb.conf<\/pre>\n<p>Add the following code to the bottom of this file.<\/p>\n<pre class=\"lang:default decode:true\">[share]\r\nComment = Pi shared folder\r\nPath = \/share\r\nBrowseable = yes\r\nWriteable = Yes\r\nonly guest = no\r\ncreate mask = 0777\r\ndirectory mask = 0777\r\nPublic = yes\r\nGuest ok = yes<\/pre>\n<p>Now we do want to create a user account for Samba<\/p>\n<pre class=\"lang:default decode:true\">sudo smbpasswd -a pi\r\n<\/pre>\n<p>You will be asked to enter a password for this. Now it is time to restart Samba.<\/p>\n<pre class=\"lang:default decode:true\">sudo \/etc\/init.d\/samba restart<\/pre>\n<p>Once finished your Raspberry Pi should pop up under Network, if your network discovery is turned on.<\/p>\n<p>You should be able to navigate through it just like any other folder.<\/p>\n<h3>Let&#8217;s add MQTT<\/h3>\n<pre class=\"lang:default decode:true\">sudo wget http:\/\/repo.mosquitto.org\/debian\/mosquitto-repo.gpg.key\r\nsudo apt-key add mosquitto-repo.gpg.key\r\ncd \/etc\/apt\/sources.list.d\/\r\nsudo wget http:\/\/repo.mosquitto.org\/debian\/mosquitto-wheezy.list\r\nsudo apt-get update\r\nsudo apt-get -y install mosquitto mosquitto-clients<\/pre>\n<p>Test by starting the service<\/p>\n<pre class=\"lang:default decode:true\">sudo \/etc\/init.d\/mosquitto start<\/pre>\n<p>open a new Putty terminal<\/p>\n<p>In the first terminal enter the following:<\/p>\n<pre class=\"lang:default decode:true\">mosquitto_sub -d -t hello\/world<\/pre>\n<p>In the second Window, enter:<\/p>\n<pre class=\"lang:default decode:true \">mosquitto_pub -d -t hello\/world -m \"Hello from Terminal 2!\"<\/pre>\n<p>If successful, the packet sent from terminal window 2 should appear in window 1<\/p>\n<h3>Change raspberrypi.local to something else.<\/h3>\n<p>Change the host name so that we don&#8217;t have to always use the Pi&#8217;s IP address but we also do not want to use the generic name that all Pi&#8217;s use for default.<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/hosts<\/pre>\n<p>Change the raspberrypi to whatever name your want then save this file. Do not change anything else.<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/etc\/hostname<\/pre>\n<p>Change this to match your new host name<\/p>\n<p>To commit the changes, reboot the Pi.<\/p>\n<pre class=\"lang:default decode:true\">sudo reboot<\/pre>\n<h3>Install the E-Ink display<\/h3>\n<p>Run<\/p>\n<pre class=\"lang:default decode:true\">sudo raspi-config<\/pre>\n<p>Select Interfacing Options<\/p>\n<p>Select I2C and enable it<\/p>\n<p>Also enable Remote GPIO<\/p>\n<p>Note: E-ink python scripts live in the following directory path:<\/p>\n<p>\/PaPiRus\/RTC-Hat-Examples<\/p>\n<p>Reference Links:<\/p>\n<p><em><a href=\"https:\/\/www.raspberrypi.org\/documentation\/configuration\/wireless\/access-point.md\" target=\"_blank\">SETTING UP A RASPBERRY PI AS AN ACCESS POINT IN A STANDALONE NETWORK (NAT)<\/a><\/em><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-1917\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-1917\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Intro This will walk you through setting up a Raspberry Pi Web server with Raspbian Buster Lite. The following services will be installed and available by the end of this tutorial. Apache web server MySQL database PHP MediaWiki MQTT<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-1917\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-1917\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/wireless-nat-server-e-ink-badge-with-apache-php-sql-media-wiki-and-mqtt\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[164,79],"tags":[84,27,72,15,143],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5AhH6-uV","_links":{"self":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1917"}],"collection":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/comments?post=1917"}],"version-history":[{"count":4,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1917\/revisions"}],"predecessor-version":[{"id":2274,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1917\/revisions\/2274"}],"wp:attachment":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/media?parent=1917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/categories?post=1917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/tags?post=1917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}