Gary Littlemore
Posts: 326
Joined: Thu Oct 11, 2012 11:52 am
Location: Cheshire, UK

Help needed! Trying to implement a LAMP Setup. [solved]

Sat Mar 16, 2019 9:09 pm

I've been trying to get a LAMP setup working and I've followed various Howto's but I couldn't get one to fully work. So between about 4 Howto's I've managed to compile the below. I've used the PHPMyAdmin wizard to setup the MySQL database and configure the PHPMyAdmin admin account, but PHPMyAdmin is saying 'No Privileges'.

Can anyone tell me where it's gone wrong and how I fix the issue please?

Code: Select all

Installing a LAMP on the Raspberry Pi

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

Once the RPi has booted log in with User: pi Pass: raspberry

then

$ hostname -I (Note down the IP Address, you will need this to SSH to the RPi. e.g. 192.168.0.100)

$ sudo raspi-config

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 User: pi Pass: raspberry

## Update Raspbian ##

$ sudo apt update && sudo apt upgrade -y

$ sudo reboot

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

log in with User: pi Pass: raspberry

## Install Apache2 ##

$ sudo apt install apache2 -y

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

$ sudo a2enmod rewrite
$ sudo chown -R pi:www-data /var/www/html/
$ sudo chmod -R 770 /var/www/html/
$ sudo nano /etc/apache2/apache2.conf

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

## Install PHP ##

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

Testing PHP

You will first 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.

## Install MySQL ##

$ sudo apt install mysql-server php-mysql -y
$ sudo service apache2 restart

## Install PHPMyAdmin ##

$ sudo apt install phpmyadmin -y

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

You will now get a wizard to set up PHPMyAdmin, If you are an advanced database administrator and know that you want to perform this configuration manually, or if your database has already been installed and configured, you should refuse this option. Details on what needs to be done should most likely be provided in /usr/share/doc/phpmyadmin. Otherwise, you should probably choose this option.

## Setup an FTP ##

$ sudo apt-get install vsftpd -y
$ sudo nano /etc/vsftpd.conf

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.
Last edited by Gary Littlemore on Mon Mar 18, 2019 12:24 pm, edited 1 time in total.
3b+, 2b, b+, b, Zero & Zero-W

Andyroo
Posts: 2075
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Help needed! Trying to implement a LAMP Setup.

Sun Mar 17, 2019 12:13 am

If I'm reading this correctly phpMyadmin cannot log into Maria DB though its up and running fine?

Try the following (changing 'password' to something else :lol: ) :

Code: Select all

sudo mysql -u root
use mysql;
create user 'admin'@'localhost' identified by 'password';
grant all privileges on *.* to 'admin'@'localhost';
update user set plugin='mysql_native_password' where User='admin';
flush privileges;
exit;
Note the quotes are needed around the admin / localhost and password above on the create user command.

Then do a reboot

Now see if you can sign in to phpMyAdmin using user 'admin' and the 'password' (without quotes in both cases) you set above.

This basically has created a new user that can access all tables etc in the SQL database and uses the SQL password for authentication. This user does not exist outside of SQL so it cannot be used at the command line.

Let me know how you get on - this is from a Debian build I did Dec last year but I'm pretty sure it will be OK on the Pi.
Need Pi spray - these things are breeding in my house...

procount
Posts: 1534
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Help needed! Trying to implement a LAMP Setup.

Sun Mar 17, 2019 10:29 am

I documented my experience on creating a LAMP stack here -> viewtopic.php?f=29&t=218354
Read all the posts because I did miss one step out which was corrected in a subsequent post.

If you want a ready made Raspbian Installation with a LAMP stack, I have a working pre-built image you can install with PINN under the testing category.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Gary Littlemore
Posts: 326
Joined: Thu Oct 11, 2012 11:52 am
Location: Cheshire, UK

Re: Help needed! Trying to implement a LAMP Setup.

Sun Mar 17, 2019 2:12 pm

Thanks for your reply Procount, your documented experience was one of the ones it'd tried to follow when attempting my setup.

I have now resolved the MySQL user problem I was having. I followed the setting up a database guide (manually)(https://projects.raspberrypi.org/en/pro ... ordpress/7) instead of using the phpmyadmin database wizard and I now have full user privileges when accessing via phpmyadmin.

I'm just tidying up my 'Howto' implementing another build on a 128GB card to check the code. I'll post the final 'Howto' when completed.
procount wrote:
Sun Mar 17, 2019 10:29 am
I documented my experience on creating a LAMP stack here -> viewtopic.php?f=29&t=218354
Read all the posts because I did miss one step out which was corrected in a subsequent post.

If you want a ready made Raspbian Installation with a LAMP stack, I have a working pre-built image you can install with PINN under the testing category.
3b+, 2b, b+, b, Zero & Zero-W

Return to “Networking and servers”