0% found this document useful (0 votes)
193 views7 pages

Installing Lamp (Linux, Apache, Mysql, PHP) On A Raspberry Pi

This document provides instructions for installing and configuring a LAMP stack on a Raspberry Pi, including installing Raspbian, Apache, MySQL, PHP, PHPMyAdmin, and an FTP server. Key steps include updating the OS, setting the hostname, enabling SSH, installing and configuring the LAMP components, and securing the MySQL installation.

Uploaded by

ShanmukhaTeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
193 views7 pages

Installing Lamp (Linux, Apache, Mysql, PHP) On A Raspberry Pi

This document provides instructions for installing and configuring a LAMP stack on a Raspberry Pi, including installing Raspbian, Apache, MySQL, PHP, PHPMyAdmin, and an FTP server. Key steps include updating the OS, setting the hostname, enabling SSH, installing and configuring the LAMP components, and securing the MySQL installation.

Uploaded by

ShanmukhaTeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Installing LAMP (Linux, Apache, MySQL, PHP) on a Raspberry Pi

Set up a LAMP (Linux Rasbian Stretch Lite, Apache2, MySQL (MariaDB-10), PHP7) stack with PHPMyAdmin
and FTP access on your Raspberry Pi and configure it to work as a web server.

You will need a Raspberry Pi computer connected to the internet with a 8GB (or greater) MicroSD card. At first
you'll need to be able to configure the Raspi-config with a keyboard to change the default Raspbian password
and to enable SSH. Once the Raspi-config has been completed you'll only need to connect via a SSH
connection.

You should already be able to configure the Rasbian image to the MicroSD card, you'll need knowledge of
being able to SSH to the Raspberry Pi and be able to configure your SQL database using PHPMyAdmin.

Where you see $, this is the command you need to paste/use to install and configure the software.

Step 1: ## Raspbian Image ##

Create a Raspbian Stretch Lite image to a MicroSD card (>8GB recommended)

Once the RasPi has booted log in with Username: pi Password: raspberry

then

$ hostname -I

(Note down the IP Address, you will need this to SSH to the RasPi. e.g. 192.168.0.100)

$ sudo raspi-config

Option 1 - 'Change User Password' > Ok > Enter new UNIX password > Retype new Password > Ok

Option 5 - 'Interfacing Options' > 'P2 SSH' > Yes Tab to 'Finish' > Enter

$ sudo reboot

Step 2: ## Update Raspbian ##

Now using Putty connect to the RPi using the IP address from earlier.
log in with Username: pi & your password

$ sudo apt update && sudo apt upgrade -y

$ sudo reboot

Step 3: ## Install Apache2 ##

Again using Putty connect to the RPi using the IP address from earlier.

log in with Username: pi & your password

$ sudo apt install apache2 -y

Once finished installing Apache2 open a web browser on the same Wi-Fi network and enter the IP address of
the RasPi. If Apache2 installed correctly you will see a page that says 'Apache2 Debian Default Page' and 'It
works!'.
$ sudo a2enmod rewrite

$ sudo systemctl restart apache2

$ sudo chown -R pi:www-data /var/www/html/

$ sudo chmod -R 770 /var/www/html/

$ sudo nano /etc/apache2/apache2.conf

Find: (You can use Ctrl & W to find)

Directory /var/www/

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

/Directory

Change to:

Directory /var/www/
Options Indexes FollowSymLinks

AllowOverride All

Require all granted

/Directory

Ctrl & O > Enter > Ctrl & X

$ sudo service apache2 restart

Step 4: ## Install PHP7 ##

$ sudo apt install php libapache2-mod-php -y

Testing PHP

You will first need to delete the file “index.html” in the directory “/var/www/html”.

$ sudo rm /var/www/html/index.html

Then create an “index.php” file in this directory, with this command line

$ echo "<?php phpinfo ();?>" > /var/www/html/index.php

Refresh the web broswer on the same Wi-Fi network, you should now see the PHP info page.
Step 5: ## Install MySQL ##

$ sudo apt install mysql-server php-mysql -y

$ sudo service apache2 restart

$ sudo mysql_secure_installation

You will be asked enter current password for root (default is blank): press Enter.

Set root password, type Y and press Enter.

Type in a new password and press Enter. Important: remember this root password.

Re-enter the new password and press Enter.

Type Y and press Enter to Remove anonymous users.

Type Y and press Enter to Disallow root login remotely.

Type Y and press Enter to Remove test database and access to it.

Type Y and press Enter to Reload privilege tables now.

When complete, you will see the message All done! and Thanks for using MariaDB!.

$ sudo mysql -uroot -p

Enter the root password.

$ create database YOURDATABASENAME;

$ GRANT ALL PRIVILEGES ON YOURDATABASENAME.* TO 'root'@'localhost' IDENTIFIED BY


'YOURROOTPASSWORD';

$ FLUSH PRIVILEGES;

Ctrl & D

Step 6: ## Install PHPMyAdmin ##

$ sudo apt install phpmyadmin -y

Select Apache2 with the cursor keys and press the spacebar to highlight Apache2 > Tab > Enter.

Configure database for phpmyadmin with dbconfig-common? Select 'No' > Enter, we have already setup a
database above with the MySQL installation.

To access phpmyadmin use the IP address of the RasPi e.g. 192.168.0.100/phpmyadmin/ Username: root
and YOURROOTPASSWORD

Step 7: ## Setup an FTP ##

$ sudo apt install vsftpd -y


$ sudo nano /etc/vsftpd.conf

Find: (You can use Ctrl & W to find)

local_enable=YES

ssl_enable=NO

Change to:

#local_enable=YES

#ssl_enable=NO

Add to the bottom of the file:

# CUSTOM
ssl_enable=YES

local_enable=YES

chroot_local_user=YES

local_root=/var/www

user_sub_token=pi

write_enable=YES

local_umask=002

allow_writeable_chroot=YES

ftpd_banner=Welcome to my Raspberry Pi FTP service.

Ctrl & O > Enter > Ctrl & X

$ sudo usermod -a -G www-data pi

$ sudo usermod -m -d /var/www pi

$ sudo chown -R www-data:www-data /var/www

$ sudo chmod -R 775 /var/www

$ sudo reboot

The process is now complete.


Install MySQL (MariaDB Server) on Raspberry Pi
MySQL (often pronounced My S–Q–L) is a popular open source relational
database.
Install the MySQL Server (MariaDB Server) and PHP-MySQL packages by
entering the following command:

pi@raspberrypi:/var/www/html $ sudo apt install mariadb-server php-mysql -y


pi@raspberrypi:/var/www/html $ sudo service apache2 restart
After installing MySQL (MariaDB Server), it’s recommend to run this command to
secure your MySQL installation:

pi@raspberrypi:/var/www/html $ sudo mysql_secure_installation

This should appear in your Terminal window:

 You will be asked Enter current password for root (type a secure password): 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
 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 the installation is completed, you’ll see the message: “Thanks for using
MariaDB!”.

If you experience any error login into phpMyAdmin, you might need to create a
new user to login. Those commands will create a new user with name (admin)
and password (your_password).

pi@raspberrypi:/var/www/html $ sudo mysql --user=root --password


> create user admin@localhost identified by 'your_password';
> grant all privileges on *.* to admin@localhost;
> FLUSH PRIVILEGES;
> exit;

Install phpMyAdmin on Raspberry Pi


phpMyAdmin is a free software tool written in PHP, intended to handle the
administration of MySQL using a web interface.

To install phpMyAdmin on a Raspberry Pi, type the following command into the
terminal:
pi@raspberrypi:/var/www/html $ sudo apt install phpmyadmin -y
PHPMyAdmin installation program will ask you few questions. We’ll use
the dbconfig-common.
 Select Apache2 when prompted and press the Enter key
 Configuring phpmyadmin? OK
 Configure database for phpmyadmin with dbconfig-common? Yes
 Type your password and press OK
 Enable the PHP MySQLi extension and restart Apache2 for changes to
take effect:
 pi@raspberrypi:/var/www/html $ sudo phpenmod mysqli
 pi@raspberrypi:/var/www/html $ sudo service apache2 restart

When you go to your RPi IP address followed by /phpmyadmin (in my


case http://192.168.1.86/phpmyadmin), you’ll probably see the “Not
Found” error page in your browser:

If that’s the case, you’ll have to move the phpmyadmin folder


to /var/www/html, run the next command:
 pi@raspberrypi:/var/www/html $ sudo ln -s /usr/share/phpmyadmin
/var/www/html/phpmyadmin

Now, if you list the files, it should return the phpmyadmin folder:


 pi@raspberrypi:/var/www/html $ ls
 phpmyadmin

Reload your web page (http://192.168.1.86/phpmyadmin), your should see the


login page for phpMyAdmin web interface::

Enter your defined username (it should be Username = root) and the password
you defined during the installation.
Press the Go button to login. A new page loads:

That’s it! Your Raspberry Pi board is prepared with a LAMP server: Apache2,
MySQL, PHP. We’ve also decided to include phpMyAdmin in this installation for
an easier database management through a web interface.

Optional Step (but recommended)


To manage your web pages, you should change the permissions for
your /var/www/html/ folder. To do this, run the following commands:
pi@raspberrypi:~ $ ls -lh /var/www/
pi@raspberrypi:~ $ sudo chown -R pi:www-data /var/www/html/
pi@raspberrypi:~ $ sudo chmod -R 770 /var/www/html/
pi@raspberrypi:~ $ ls -lh /var/www/

After running these commands, you’ll see something as follows:

You might also like