Installing Lamp (Linux, Apache, Mysql, PHP) On A Raspberry Pi
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.
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
Now using Putty connect to the RPi using the IP address from earlier.
log in with Username: pi & your password
$ sudo reboot
Again using Putty connect to the RPi using the IP address from earlier.
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
Directory /var/www/
AllowOverride None
/Directory
Change to:
Directory /var/www/
Options Indexes FollowSymLinks
AllowOverride All
/Directory
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
Refresh the web broswer on the same Wi-Fi network, you should now see the PHP info page.
Step 5: ## Install MySQL ##
$ sudo mysql_secure_installation
You will be asked enter current password for root (default is blank): press Enter.
Type in a new password and press Enter. Important: remember this root password.
Type Y and press Enter to Remove test database and access to it.
When complete, you will see the message All done! and Thanks for using MariaDB!.
$ FLUSH PRIVILEGES;
Ctrl & D
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
local_enable=YES
ssl_enable=NO
Change to:
#local_enable=YES
#ssl_enable=NO
# 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
$ sudo reboot
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).
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
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.