A LAMP Server

Introduction: A LAMP Server

So... I know it's pretty lame, but I made a LAMP (Linux, Apache, MariaDB, PHP) server and I am proud of it, as I had some technical problems during the making, but I could solve them.

The server is only accessible in the network you are in, by accessing it via 192.168.1.105 or localhost.

This server is fully compatible with other kinds of servers (like Flask).

Supplies:

  • Raspberry Pi (Fully set up with Raspbian)
  • An Internet connection
  • Patience
  • Some more patience
  • Knowing how to search for errors
  • A sudo admin

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Installing Apache

Before we start we want to check if we do have sudo permissions by going to the terminal and writing

sudo apt-get update

Then we will start the installations. We will need Apache2.

sudo apt-get install apache2 -y

Easy! Then, check if it worked by opening your web navigator and going to http://localhost

You should see the image from the top. YOU DID IT! You should be able to open it in another computer in your network by going to your Raspberry's ip (run ifconfig in the terminal, should be 192.168.1.XXX)

You can change that page by doing the following:

cd /var/www/htm

sudo leafpad index.html

If leafpad doesn't work, try another text editor or download it (sudo apt-get install leafpad). Once you reload the web page you'll be able to see the changes.

Step 2: Installing PHP

PHP is a preprocessor: it’s code that runs when the server receives a request for a web page via a web browser. It works out what needs to be shown on the page, and then sends that page to the browser. Unlike static HTML, PHP can show different content under different circumstances. Other languages are also capable of doing this, but since WordPress is written in PHP, that’s what we need to use this time. PHP is a very popular language on the web: huge projects like Facebook and Wikipedia are written in PHP.

To install it, run:

sudo apt-get install php -y

There is no need to test it (at least for now). But we need to restart Apache

sudo service apache2 restart

Step 3: Installing MySQL

MySQL (pronounced My Sequel or My S-Q-L) is a popular database engine. Like PHP, it’s widely used on web servers, which is why projects like WordPress use it, and why those projects are so popular. MySQL as a thing is discontinued, so we’ll use MariaDB, which is the same, but with another name.
Install the MySQL Server and PHP-MySQL packages by entering the following command into the terminal window:

sudo apt-get install mariadb-server

We’ll restart apache:

sudo service apache2 restart

And we’ll install the php addon for MariaDB:

sudo apt-get install php7.3-mysql

The 7.3 should be changed for the version you are running (you can find out about it by running man php).

Again, restart apache:

sudo service apache2 restart

Step 4: Download Wordpress

Our website will run on Wordpress. This is to ensure the correct functioning and simplicity of the server.

You can download WordPress from wordpress.org using the wget command. Helpfully, a copy of the latest version of WordPress is always available at wordpress.org/latest.tar.gz, so you can grab the latest version without having to look it up on the website. This is the “hard" part:

cd /var/www/html/
sudo rm *

We need to remove everything, as it could give us some problems.

sudo wget http://wordpress.org/latest.tar.gz

We download Wordpress

sudo tar xzf latest.tar.gz

Extract the tarball

sudo mv wordpress/* .

sudo rm -rf wordpress latest.tar.gz

Remove the tarball

sudo chown -R www-data: .

Give all privileges to PHP.

And now, Wordpress is installed and ready to go.

Step 5: Set Up MySQL/MariaDB

Run the MySQL secure installation command in the terminal window.

sudo mysql_secure_installation

You will be asked Enter current password for root (enter for none): — press Enter.
Type in Y and press Enter to Set root password?.

Type in a password at the New password: prompt, and press Enter. Important: remember this root password, as you will need it later to set up WordPress. Type in Y to Remove anonymous users. Type in Y to Disallow root login remotely. Type in Y to Remove test database and access to it. Type in Y to Reload privilege tables now. When complete, you will see the message All done! and Thanks for using MariaDB!.

Now, set up the database:

mariadb -uroot -p

It will ask for the password.

Then write:

create database wordpress;

Now grant database privileges to the root user. Note: you will need to enter your own password after IDENTIFIED BY.

GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD’;

FLUSH PRIVILEGES;

Exit MariaDB via CTRL+D

Step 6: Final Step! - Set Up Wordpress

We have finished!

Now, point a web browser to 192.168.1.105 (for a Raspberry Pi) or localhost. It will ask for the language and then, it will ask you some data. This is what you want to write there:

Database Name: wordpress

User Name: root

Password: <YOUR PASSWORD>

Database Host: localhost

Table Prefix: wp_

Most of them will be already written out.

Then, continue filling it out.

Step 7: AND WE ARE DONE!

Congratulations!

Now, fill your web page to the brim with whatever you want!

Don’t forget, you can access and manage the page by pointing a web browser to the IP of the device (find it via ifconfig, where it says inet).

Please leave a Favourite and check out some of my other work (coming right up!)

STEM Contest

This is an entry in the
STEM Contest

2 People Made This Project!

Recommendations

  • Magnets Challenge

    Magnets Challenge
  • Snow Challenge

    Snow Challenge
  • Wearables Contest

    Wearables Contest

Discussions