{"id":158,"date":"2021-01-13T01:49:09","date_gmt":"2021-01-13T01:49:09","guid":{"rendered":"https:\/\/www.larry4u.com\/co2diy.com\/?page_id=158"},"modified":"2023-09-28T13:45:12","modified_gmt":"2023-09-28T13:45:12","slug":"add-the-magic-mirror-software","status":"publish","type":"page","link":"https:\/\/www.larry4u.com\/co2diy.com\/diy-make-big-screen-monitor\/contents\/add-the-magic-mirror-software\/","title":{"rendered":"Add the Web Server"},"content":{"rendered":"<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Loading Web server software.<\/h3>\n<p>Referance: <a href=\"https:\/\/pimylifeup.com\/raspberry-pi-apache\/\">How to Setup a Raspberry Pi Apache Web Server &#8211; Pi My Life Up<\/a><\/p>\n<p><strong class=\"step_numbering\">1.<\/strong>\u00a0Before we install Apache to our Raspberry Pi, we must first ensure the package list is up to date by running the following two commands.<\/p>\n<pre><code class=\"header terminal\">sudo apt-get update\r\nsudo apt-get upgrade<\/code><\/pre>\n<p><strong class=\"step_numbering\">2.<\/strong>\u00a0First, we will need to install the Apache2 package on our Raspberry Pi.<\/p>\n<p>For those who don\u2019t know\u00a0<a href=\"https:\/\/www.apache.org\/\" target=\"_blank\" rel=\"noopener\">what Apache is<\/a>, it is a server software that serves the HTML files from a computer to the web browser.<\/p>\n<p>To install apache2 on your Raspberry Pi, enter the following command into the terminal.<\/p>\n<pre><code class=\"header terminal\">sudo apt install apache2 -y<\/code><\/pre>\n<p><strong class=\"step_numbering\">3.<\/strong>\u00a0With Apache2 installed to our Raspberry Pi, we now have an extremely basic web server up and running. The server will be able to provide non-dynamic content such as HTML files.<\/p>\n<p>In the next section, we will be extending this basic Apache web server by installing PHP to the Raspberry Pi.<\/p>\n<p>To check that Apache is up and running on your Raspberry Pi, you can enter the Raspberry Pi\u2019s IP address into a\u00a0<a href=\"https:\/\/pimylifeup.com\/category\/guides\/browsers\/\">web browser<\/a>. The server should return a webpage with some simple text on it.<\/p>\n<p>If you forgot the IP address run the following command:<\/p>\n<p>&#8220;ifconfig&#8221;<\/p>\n<pre>ifconfig\r\n\r\nwlan0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 1500\r\ninet 192.168.1.249 netmask 255.255.255.0 broadcast 192.168.1.255\r\ninet6 fe80::9192:b666:669c:285e prefixlen 64 scopeid 0x20&lt;link&gt;\r\nether dc:a6:32:08:09:5c txqueuelen 1000 (Ethernet)\r\nRX packets 317686 bytes 439240333 (418.8 MiB)\r\nRX errors 0 dropped 0 overruns 0 frame 0\r\nTX packets 117089 bytes 8392171 (8.0 MiB)\r\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 0<\/pre>\n<p>If you do not know the IP, you can enter the\u00a0<a href=\"https:\/\/pimylifeup.com\/hostname-command\/\">hostname command<\/a>\u00a0into the terminal to retrieve it.<\/p>\n<pre><code class=\"header terminal\">hostname -I\r\n192.168.1.249\r\nsame as ip address.<\/code><\/pre>\n<p><strong class=\"step_numbering\">4.<\/strong>\u00a0In a web browser, enter your\u00a0<a href=\"https:\/\/pimylifeup.com\/raspberry-pi-ip-address\/\">Raspberry Pi\u2019s IP Address<\/a>, it should connect and load a page like the one below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-33455210 lazyloaded\" src=\"https:\/\/pi.lbbcdn.com\/wp-content\/uploads\/2019\/07\/Raspberry-Pi-Apache-Web-Server-Default-Page-v2.png\" sizes=\"(max-width: 691px) 100vw, 691px\" srcset=\"https:\/\/pi.lbbcdn.com\/wp-content\/uploads\/2019\/07\/Raspberry-Pi-Apache-Web-Server-Default-Page-v2.png 691w, https:\/\/pi.lbbcdn.com\/wp-content\/uploads\/2019\/07\/Raspberry-Pi-Apache-Web-Server-Default-Page-v2-300x271.png 300w, https:\/\/pi.lbbcdn.com\/wp-content\/uploads\/2019\/07\/Raspberry-Pi-Apache-Web-Server-Default-Page-v2-600x542.png 600w\" alt=\"Raspberry Pi Apache Web Server Default Page\" width=\"691\" height=\"624\" data-ll-status=\"loaded\" \/><\/p>\n<p><strong class=\"step_numbering\">5.<\/strong> The web page files are in this directoy. \/var\/www\/html<\/p>\n<pre>type cd \/var\/www\/html\r\nthe line command ls will list the files in that directory.\r\nthis will put you in the webpage direcoty<\/pre>\n<p>Firstly, we add the user\u00a0<code>pi<\/code>\u00a0(our user) to the\u00a0<code>www-data<\/code>\u00a0group, the default group for Apache2.<\/p>\n<p>Secondly, we give ownership to all the files and folders in the\u00a0<code>\/var\/www\/html<\/code>\u00a0directory to the\u00a0<code>www-data<\/code>\u00a0group.<\/p>\n<pre><code class=\"header terminal\">sudo usermod -a -G www-data aranet\r\nsudo chown -R -f www-data:www-data \/var\/www\/html<\/code> \r\nsudo chmod 775 \/var\/www\/html \r\nsudo chown aranet \/var\/www\/html<\/pre>\n<h2 class=\"lbb-section-break text-center mt-5\"><i class=\"fas fa-php\"><\/i>\u00a0Setting up PHP7 for Apache<\/h2>\n<p>To start this section, we will need to go ahead and install php7.3 and several other packages to our Raspberry Pi. The additional packages we are installing are ones that are commonly used by PHP applications.<\/p>\n<p>Lucky for us installing all the packages we need is a simple process as PHP 7.3 is available in the Raspbian package repository.<\/p>\n<p>sudo apt install php -y<\/p>\n<p>Run the following command to install all the PHP packages to your Raspberry Pi.\u00a0Now that PHP is installed to our<\/p>\n<p>Raspberry Pi, we can test it to make sure it\u2019s working.<\/p>\n<p>We can test to see PHP is working by creating a PHP file within the\u00a0<code>\/var\/www\/html\/<\/code>\u00a0directory. Creating a file in this directory will allow it to be processed and displayed when you open it in a web browser.<\/p>\n<p>For our example, we will be creating a PHP file called\u00a0<code>index.php<\/code>. We can create this file by issuing the following command.<\/p>\n<pre><code class=\"header terminal\">sudo nano \/var\/www\/html\/index.php<\/code><\/pre>\n<p><strong class=\"step_numbering\">3.<\/strong>\u00a0In this file, we need to add the following lines on PHP code.<\/p>\n<pre><code class=\"header add\">&lt;?php\r\necho \"Today's date is \".date('Y-m-d H:i:s');\r\n?&gt;<\/code><\/pre>\n<p>Now lets delete the index.html.\u00a0 We don&#8217;t need it anymore.<\/p>\n<p>sudo rm \/var\/www\/html\/index.html<\/p>\n<p>The code above is just an incredibly simple PHP script that prints out today\u2019s date retrieved using PHP\u2019s\u00a0<code>date()<\/code>\u00a0function. It will be enough to tell us that PHP is, in fact, up and running.<\/p>\n<p><strong class=\"step_numbering\">4.<\/strong>\u00a0Now save the file by pressing\u00a0<kbd>Ctrl + X<\/kbd>\u00a0then pressing\u00a0<kbd>Y<\/kbd>\u00a0and hitting\u00a0<kbd>ENTER<\/kbd>.<\/p>\n<p><strong class=\"step_numbering\">5.<\/strong>\u00a0In your web browser, go to\u00a0<code>http:\/\/the ip address of your aranet raspberry pi.<\/code><\/p>\n<p>Going to the following URL should display something like the following.<\/p>\n<pre><code class=\"header\">Today's date is 2019-06-28 21:30:45<\/code><\/pre>\n<p>If you see the current date and time we are good to go to the next step.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.larry4u.com\/co2diy.com\/run-environment-for-aranet4\/\">NEXT<\/a><\/p>\n<form action=\"https:\/\/www.paypal.com\/cgi-bin\/webscr\" method=\"post\" target=\"_blank\">\n<div class=\"pal_donation_button\"><input alt=\"PayPal - The safer, easier way to pay online.\" name=\"submit\" src=\"https:\/\/www.paypal.com\/en_US\/i\/btn\/btn_donateCC_LG.gif\" type=\"image\" \/>\u00a0<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.paypal.com\/en_US\/i\/scr\/pixel.gif\" alt=\"\" width=\"1\" height=\"1\" \/><\/div>\n<div><\/div>\n<\/form>\n","protected":false},"excerpt":{"rendered":"<p>Loading Web server software. Referance: How to Setup a Raspberry Pi Apache Web Server &#8211; Pi My Life Up 1.\u00a0Before we install Apache to our Raspberry Pi, we must first ensure the package list is up to date by running <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/www.larry4u.com\/co2diy.com\/diy-make-big-screen-monitor\/contents\/add-the-magic-mirror-software\/\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":133,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"_links":{"self":[{"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/pages\/158"}],"collection":[{"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":50,"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/pages\/158\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/pages\/158\/revisions\/686"}],"up":[{"embeddable":true,"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/pages\/133"}],"wp:attachment":[{"href":"https:\/\/www.larry4u.com\/co2diy.com\/wp-json\/wp\/v2\/media?parent=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}