Install XAMPP with PHP and MariaDB - Webbprogrammering/websoft GitHub Wiki

image

We will install a web server (Apache) together with support for a back end script (PHP) and a database (MariaDB). We do this by using the XAMPP package.

This will make it possible to run our own website through an actual web server, on our local host.

Read more

You can read more about XAMPP. This is an installer package that will install all utilities we need.

We are using the Apache web server. Check it out for information and documentation.

We are using PHP as a server side scripting language. Like any new programming language, your first stop should be the reference documentation for the language.

We are using MariaDB as the database, it is a drop in replacement for MySQL. Use its documentation to see how to write SQL queries.

You may use your own installation of MySQL, if you prefer, instead of the MariaDB that comes with XAMPP.

Prerequisite

You are familiar with the terminal and how to install programs.

You have basic knowledge of HTML files and you have a texteditor and you know your way around your filesystem.

You have some sample programs that will help you carry out the assignment, you find them in the course repo at example/php.

Install on Linux

If you are on Linux, I then suggest you install apache, php and the database as part of your package manager. You could use a guide like this on.

Install on macOS

There are several ways to install apache and php on your Mac. Feel free to use the one already installed or install using your package manager brew.

If you are uncertain, then proceed and do it the XAMPP way.

XAMPP has two versions for mac-users, one VM and one no VM. I propose you use the no-VM version.

Go to the download page and find the latest version.

  • 7.4.1 / PHP 7.4.1 (Use this, or a newer version)
  • XAMPP-VM / PHP 7.4.1 (avoid this VM-version, if you are unfamiliare with it)

Download it and run the installation program.

Install on Windows

Go to the download page and find the latest version.

  • 7.4.1 / PHP 7.4.1 (Use this, or a newer version)

Download it and run the installation program.

Start it

Start up the control center and click to start the apache web server.

If you already have something running on port 80, configure apache to run on port 8080.

Open your web browser to http://localhost or http://127.0.0.1 and a XAMPP welcome message will display.

Add a HTML and a PHP file

Take this code and put it into a file hello.html.

<h1>HELLO WORLD HTML</h1>

<ul>
    <li><a href="hello.html">hello.html</a></li>
    <li><a href="hello.php">hello.php</a></li>
</ul>

Take this code and put it into a file hello.php.

<h1>HELLO WORLD PHP</h1>

<?php
$str = "Hello from the PHP world";
echo $str;

for ($i = 1; $i < 9; $i++) {
    $str .= $i . ", ";
}
?>

<p>
    <?= $str ?>
</p>

<ul>
    <li><a href="hello.html">hello.html</a></li>
    <li><a href="hello.php">hello.php</a></li>
</ul>

Put the two files in the directory htdocs/.

  • Windows C:\xampp\htdocs
  • macOS /Applications/XAMPP/htdocs

Open your web browser to http://localhost/hello.html and to http://localhost/hello.php.

The two pages should be displayed, and the PHP code should be executed.

Link to your course repo

In your directory htdocs/, create a symbolic link home that points to your home directory to make it easier to reach your course repo from the web server.

On macOS (similair on Linux) using the terminal.

cd /Applications/XAMPP/htdocs
ls "$HOME"
ln -s "$HOME" home
ls -l home
cd home

On Windows using cmd.exe.

cd c:\xampp\htdocs
dir %USERPROFILE%
mklink /D home %USERPROFILE%
dir home
cd home

To try it out, open a web browser and point it to http://localhost/home and a file listning of your home directory should be visible.

If you get a 403 on mac, you might need to update the visibility properties on your home directory.

chmod og+rx "$HOME"

Reload the web browser.

Start your database

Since you have already had a database course I assume you roughly know how to do this.

Either use a installation of MySQL/MariaDB as you already have, or start the MariaDB as part of XAMPP.

Check that you can use the mysql client to access the database.

Create a database websoft with a table and insert some rows, like this.

DROP DATABASE IF EXISTS websoft;
CREATE DATABASE websoft;

USE websoft;

DROP TABLE IF EXISTS tech;
CREATE TABLE tech (
    label CHAR(10) PRIMARY KEY,
    type VARCHAR(20)
);

INSERT INTO tech VALUES
    ('Apache', 'Web server'),
    ('PHP', 'Server side language'),
    ('MariaDB', 'Database server'),
    ('MySQL', 'Database server')
;

SELECT * FROM tech;

It should look a bit like this, when you are done.

mysql> SELECT * FROM tech;
+---------+----------------------+
| label   | type                 |
+---------+----------------------+
| Apache  | Web server           |
| MariaDB | Database server      |
| MySQL   | Database server      |
| PHP     | Server side language |
+---------+----------------------+
4 rows in set (0.01 sec)

Thats all for now.

⚠️ **GitHub.com Fallback** ⚠️