The Rasp Pi serves up a tempting web server

Local Web Server

After installing the packages discussed in this section, you should be able to see a test page in your Rasp Pi browser that confirms that your local web server works properly.

To begin, install Apache and PHP:

pi@raspberrypi ~ $ sudo -s
root@raspberrypi:/home/pi# apt-get install apache2 php5 libapache2-mod-php5

Notice that the $ prompt is used to indicate you are operating as a normal user, whereas the # prompt indicates you are superuser (root), which you enter with the sudo command. Next, you can optionally install MySQL, an open source database:

# apt-get install mysql-server mysql-client

When you install MySQL, you will be prompted to add passwords. If you just press Enter, it will continue with the installation, and you won't need a password to use MySQL. If you take this route, you can always add and change MySQL passwords at a later date at the command line.

From the command line, you just type mysql to access the MySQL database:

# mysql
To exit mysql at the command line
1) mysql> exit

Now, you can create databases and tables and run many other commands specific to administrating MySQL.

phpMyAdmin

Another optional installation is phpMyAdmin, which is a GUI and command-line tool used to administer MySQL databases. If you are new to MySQL or do not intend to use it much or at all, you can skip this option and move on to restarting Apache. Otherwise, you should install this tool. For those who use a scripting language like PHP or Perl to connect and interact with MySQL on a regular basis, or for those who like to run custom queries with MySQL, phpMyAdmin is a valuable tool.

PhpMyAdmin allows you to search databases and tables, create and modify tables, and update and delete data. When you get to know it well, it can save you a lot of time. To install phpMyAdmin, enter:

# apt-get install phpmyadmin

Choose your web server, then Tab down to ok and press Enter. When you've completed the installation, open phpMyAdmin with:

http://<IP or localhost>/phpmyadmin

As you will see, you will not be allowed to log in as root, so you'll have to make some configuration changes for phpMyAdmin. To do so, you need to edit the config.inc.php file in the /etc/phpmyadmin directory (see the "Text Editors" box):

Text Editors

When you open files from the command line, you can use any editor installed on your Rasp Pi. Nano [3] is installed by default in Raspbian and works right out of the box. To use Nano, you typically move the cursor with arrow keys and use the Tab or shortcut keys to save the file or apply a different option.

  • To create or open a file with Nano, type nano followed by the filename:
$ nano test.html
  • To add text to a file, just start typing.
  • To save a file and exit, press Ctrl+O.
  • To exit Nano, with a choice of saving or not, press Ctrl+X.

If you would rather use the Vi editor, you need to install the Vim package;

$ sudo apt-get install vim

otherwise, when you enter the vi command, the insert and exit commands (e.g., :q!) will not work properly. Many users prefer Vi as their command-line editor because it has so many time-saving commands and features.

Note that when you install a package and are prompted with Y or N options, always select Y and press Enter.

cd /etc/phpmyadmin
nano config.inc.php

Then, change the lines indicated in Table 1. After you have made these changes, you should be able to log in to phpMyAdmin with the root username and no password. Although it works, this setup is insecure. In phpMyAdmin, you can change the MySQL password for future logins.

Table 1

phpMyAdmin Configuration

Change Line

From

To

$cfg['Servers'][$i]['host']

= $dbserver;

= 'localhost';

$cfg['Servers'][$i]['controluser']

= $dbuser;

= 'root';

$cfg['Servers'][$i]['controlpass']

= $dbpass;

'';*

// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

$cfg['Servers'][$i] …º

* Two single quotes, not a double quotation mark.

º Remove only the slashes and spaces at the beginning of the line.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content