by MWAGNER, PAUL C.
Posted on April 4, 2017 at 1:00 PM
Web Check-In Part 1: Setting up LAMP
Recently at work we had a special event where we expected to have a large number of customers for a relatively small number of sales associates. We decided we wanted to have a sign-in system that would display who's waiting and who's being helped. We also decided this would be a good use for one of the spare Pis we have at the store.
In order to do this, we needed to set up a LAMP (Linux, Apache, MySQL, PHP) server on one of the Pis (we chose a Pi 3), set up a small database, and of course code the system itself. Although we had some inspiration from seeing other systems, neither of us had worked on one ourselves so we had to figure out how we wanted to do things on our own.
So what is a LAMP server? As noted above, it is made up of Linux, Apache, MySQL, and PHP.
Why did we need a LAMP server? Well, we decided to do this as a website so it would be easy to connect every computer involved to the system. In our case, we had a check-in computer, a display computer (to show who was waiting) and two management computers for employees to manage the queue. We had also discussed writing some applications to do the client/server aspect of it, but quite frankly we had too little time to do that properly, and a LAMP server meant we could focus on the things that were needed the most.
This will be the first in a short series of articles describing what to do to create your own sign-in system with a Raspberry Pi!
First of course we needed to set up the LAMP server. To do this on a Pi is actually just a few simple terminal commands. First up, install Apache:
sudo apt-get install apache2
This will install Apache on your Pi. Its default directory for storing any web files is /var/www/html. To validate that Apache is up and running, try browsing to "http://x.x.x.x/index.html", where "x.x.x.x" is the IP address of your Pi. To find the IP address of your Pi, after it is connected to your Wifi, type:
into a terminal window. Next to 'wlan0' you will see an "ipv4" address; this is your IP address (write this down). On a second computer navigate to "http://x.x.x.x/index.html", where "x.x.x.x" is the IP address of your Pi, you should see a page telling you that it's the default webpage for an Apache installation. If so, success! If you get an error then you'll need to find out what's causing it before going further.
Once you've installed Apache, it's time to move on to MySQL. Type in the following command:
sudo apt-get install mysql-server
During installation, you'll be asked to set up a password for MySQL's "root" user. Please make a secure password for this, as just like Linux's "root", the MySQL "root" user has full access to everything stored in your database.
Next you'll want to install PHP. This allows you to create webpages whose content can change based on things outside the website itself (like the information stored in your database!). You'll need 2 commands for this:
sudo apt-get install php5 php5-mysql
sudo service apache2 restart
The reason you need the second command is to restart Apache so it will use the modules which were just installed. To verify everything is up and running, create a file named "phpinfo.php" in the "/var/www/html" directory.
?php phpinfo(); ?
In the code I give in the future guides we'll be using PDO (PHP Data Objects), so you'll want to browse through the page and make sure that there is an entry for both "PDO" and "pdo_mysql", and that "mysql" is listed in the PDO section as one of the "PDO drivers".
Enter your Name and Email to receive notifications about new posts
Feel free to email me at email@example.com with any questions!