User avatar
procount
Posts: 1689
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Tue Jul 17, 2018 2:46 pm

I needed to install a LAMP stack (Linux Apache MySQL PHP) for a student to run a project on.
I found it a little tricky since versions had changed since I last did this, but finally I found this tutorial that worked:
https://pchelp.ricmedia.com/setup-lamp- ... y-guide/3/ (starting on page 3, since I already had Raspbian installed)

This installed Apache2, php v7, and MariaDB 10.1.23

I advise following the above tutorial for completeness as it includes an additional step, but for a quick summary and [tl;dr]:

Code: Select all

#Update system
sudo apt-get update
sudo apt-get upgrade -y

#Install Apache2
sudo apt-get install apache2 -y
sudo a2enmod rewrite
sudo service apache2 restart

#Install PHP
sudo apt-get install php libapache2-mod-php -y

#Install MySQL
sudo apt-get install mysql-server php-mysql -y
sudo service apache2 restart

#Install PhpMyAdmin
sudo apt-get install phpmyadmin -y
I found a few additional setup commands were needed to get it to work which are detailed below:

Out of the box, mysql has no root password, but unlike previous versions, this version of MySQL with MariaDB won't work with an emtpy root password unless it is used with sudo.
Here is one way to revert this behaviour:

Code: Select all

sudo mysql -u root

[MariaDB] use mysql;
[MariaDB] update user set plugin='' where User='root';
[MariaDB] flush privileges;
[MariaDB] \q

#This needs to be followed by the following command:
mysql_secure_installation
Although you should be using a proper password instead.

Likewise, phpmyadmin won't allow access with an empty password by default.
To allow passordless access, uncomment the lines in /etc/phpmyadmin/config.inc.php where 'AllowNoPassword' is mentioned.
But you should be using a proper password.

Finally, the installation did not properly configure apache to use phpmyadmin conf files, so I added a couple of symlinks as follows:

Code: Select all

cd /etc/apache2/conf-available
sudo ln -s ../../phpmyadmin/apache.conf phpmyadmin.conf
cd /etc/apache2/conf-enabled
sudo ln -s ../conf-available/phpmyadmin.conf phpmyadmin.conf
sudo service apache2 restart
Pointing your browser at http://127.0.0.1/phpmyadmin should then give access to the phpmyadmin tool
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

fbe
Posts: 494
Joined: Thu Aug 17, 2017 9:08 pm

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Tue Jul 17, 2018 4:12 pm

procount wrote:
Tue Jul 17, 2018 2:46 pm
Finally, the installation did not properly configure apache to use phpmyadmin conf files, so I added a couple of symlinks as follows:
During installation of phpmyadmin you are asked to select a webserver. Use the up/down key to select a webserver, use the space key to enable or disable the configuration.

Don't change the order of statements. You must install phpmyadmin (and I suppose other debian packages too, that need to install a database) before you mess up your root account. If you first make your mysql installation secure and later decide to use phpmyadmin, you are on your own.

fylloxera
Posts: 2
Joined: Sat Dec 26, 2015 9:46 pm

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Oct 18, 2018 5:57 pm

Finally, the installation did not properly configure apache to use phpmyadmin conf files, so I added a couple of symlinks as follows:

Please post the the symlinks, they are not visible on the site. Thank you

User avatar
procount
Posts: 1689
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Oct 18, 2018 7:51 pm

Well, @fbe suggested I missed something out, so if you follow their advice, you may not need the symlinks.

However, if you want to follow my original steps, I included the instructions to create the symlinks in the code block, which I repeat below. Just open a terminal and type the following in:

Code: Select all

cd /etc/apache2/conf-available
sudo ln -s ../../phpmyadmin/apache.conf phpmyadmin.conf
cd /etc/apache2/conf-enabled
sudo ln -s ../conf-available/phpmyadmin.conf phpmyadmin.conf
sudo service apache2 restart
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

m0j01
Posts: 1
Joined: Sat Dec 01, 2018 9:48 am

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Sat Dec 01, 2018 9:50 am

Yo, thank you for the post. It is nice to be able to create tables in phpmyadmin.

U-Rock

eMEsut
Posts: 4
Joined: Wed Apr 17, 2019 2:12 pm

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 18, 2019 6:25 pm

Thanks @procount for your tutorial, you save my time :)

I am newbie on linux and lamp.... :?

I got some errors with symlinks, but i can login phpmyadmin with root user, before i tried other tutorials but i couldn't login with root and couldn't create database :(

[email protected]:~ $ cd /etc/apache2/conf-available
[email protected]:/etc/apache2/conf-available $ sudo ln -s ../../phpmyadmin/apache.conf phpmyadmin.conf
ln: failed to create symbolic link 'phpmyadmin.conf': Dosya var
[email protected]:/etc/apache2/conf-available $ cd /etc/apache2/conf-enabled
[email protected]:/etc/apache2/conf-enabled $ sudo ln -s ../conf-available/phpmyadmin.conf phpmyadmin.conf
ln: failed to create symbolic link 'phpmyadmin.conf': Dosya var

AndieB
Posts: 3
Joined: Mon Jul 18, 2016 12:37 pm
Location: Sweden

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 25, 2019 4:45 am

Hi,

thank you for a great and simple HOWTO guide to have LAMP on RaspberryPi.

Have one issue though.
When accessing phpmyadmin there are not privileges to create a new database.
How shall I fix this?

Thanks!

~AndieB

User avatar
procount
Posts: 1689
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 25, 2019 10:30 am

@eMEsut & @AndieB
I'm not sure what is wrong with either of your installations, as I'm not an expert on this, So I just went through my tutorial step by step again on the latest updated Raspbian and it worked fine. I could create a new database too.
So maybe there is something different about the OS you are using, or made a mistake in one of the steps? I Dunno.
Anyway, if you install PINN, there is a ready made Raspbian-LAMP image under the testing category which is the result of the completing the tutorial above using the June 2018 Raspbian version.
I'm going to repeat the tutorial steps below in my next post with the latest version of Raspbian, but with some minor adjustments according to the latest versions and clarifying some steps. Maybe try again with the following steps.
Last edited by procount on Thu Apr 25, 2019 10:42 am, edited 1 time in total.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
procount
Posts: 1689
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HOWTO: Install LAMP stack (on Raspbian Stretch April 2019)

Thu Apr 25, 2019 10:41 am

I needed to install a LAMP stack (Linux Apache MySQL PHP) for a student to run a project on.
I found it a little tricky since versions had changed since I last did this, but finally I found this tutorial that worked:
https://pchelp.ricmedia.com/setup-lamp- ... y-guide/3/ (starting on page 3, since I already had Raspbian installed)

This installed:
Apache2
PHP 7.0.33-0+deb9u3 (cli) (built: Mar 8 2019 10:01:24) ( NTS )
mysql Ver 15.1 Distrib 10.1.37-MariaDB, for debian-linux-gnueabihf (armv8l) using readline 5.2

I advise following the above tutorial for completeness as it includes an additional step, but for a quick summary and [tl;dr]:

Code: Select all

#Update system
sudo apt-get update
sudo apt-get upgrade -y

#Install Apache2
sudo apt-get install apache2 -y
sudo a2enmod rewrite
sudo systemctl apache2 restart

#Install PHP
sudo apt-get install php libapache2-mod-php -y

#Install MySQL
sudo apt-get install mysql-server php-mysql -y
sudo systemctl apache2 restart

#Install PhpMyAdmin
sudo apt-get install phpmyadmin -y
During the installation of phpmyadmin, it will ask you to choose a webserver. You should choose Apache 2.
There will be a little red square on this selection already, but this is just the cursor; it does not mean it has already been selected! So press the space bar to select Apache2 befpore continuing.

I found a few additional setup commands were needed to get it to work which are detailed below:

Out of the box, mysql has no root password, but unlike previous versions, this version of MySQL with MariaDB won't work with an emtpy root password unless it is used with sudo.
Here is one way to revert this behaviour:

Code: Select all

sudo mysql -u root

[MariaDB] use mysql;
[MariaDB] update user set plugin='' where User='root';
[MariaDB] flush privileges;
[MariaDB] \q

#This needs to be followed by the following command:
mysql_secure_installation
Although you should be using a proper password instead.

Likewise, phpmyadmin won't allow access with an empty password by default.
To allow passordless access, uncomment the lines in /etc/phpmyadmin/config.inc.php where 'AllowNoPassword' is mentioned.
But you should be using a proper password.

(So having now properly selected the Apache2 webserver when installing phpmyadmin, there is no need to mess with the symlinks as in the previous tutorial as these will be created correctly.)

Pointing your browser at http://127.0.0.1/phpmyadmin should then give access to the phpmyadmin tool
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
DarkPlatinum
Posts: 842
Joined: Thu Nov 02, 2017 2:30 pm
Location: Unknown
Contact: Website YouTube

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 25, 2019 12:59 pm

1 * Raspberry Pi Zero W, 1 * Raspberry Pi 2, 1 * Raspberry Pi 3 1 * Raspberry Pi 3B + :mrgreen:

Check Out My Raspberry Site (Run on a Raspberry Pi 3B :) ): https://html.dynu.net

fbe
Posts: 494
Joined: Thu Aug 17, 2017 9:08 pm

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 25, 2019 6:03 pm

It "works". But you should be aware that uses the mysql root user to run wordpress, it writes the mysql root password into wp-config.php and leaves it readable for anyone who can login to the server and it gives the webserver write access to the document root.

The mysql_secure_installation is useless in that tutorial, though it doesn't hurt. The "GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD';" statement doesn't grant any privilege ('root'@'localhost' already has all privileges) but does what the mysql_secure_installation was supposed to do - it enables password authentication and sets the password for root (the IDENTIFIED BY clause does it). The "FLUSH PRIVILEGES" is useless.

If you want to do something serious, almost everything beginning with "Download WordPress" is wrong.

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

Re: HOWTO: Install LAMP stack (on Raspbian Stretch June 2018)

Thu Apr 25, 2019 6:49 pm

fbe wrote:
Thu Apr 25, 2019 6:03 pm
It "works". But you should be aware that uses the mysql root user to run wordpress, it writes the mysql root password into wp-config.php and leaves it readable for anyone who can login to the server and it gives the webserver write access to the document root.
...
I do not know where this idea has come from. I was always taught that each application has minimal access to ANYTHING with only sufficient to do the job they need (role based authentication). Given it’s only a few seconds extra work to create a user specifically for WP and give access only to the WP database I wish that would become the standard document.
fbe wrote:
Thu Apr 25, 2019 6:03 pm
The "FLUSH PRIVILEGES" is useless.
This should be qualified in that the ‘flush’ is not needed in this case as the internal security routines capture and apply changes when done with GRANT as here. It’s only needed when the security tables are updated directly with update / insert / delete.

As for the final statement :o WP still has a major following BUT is rapidly showing its age and even Gutenberg is a last minute gasp to win back users who are seeing ‘drag-and-drop’ tools developing sites that look better. Too many add-ins are not updated, clash or have security weaknesses that it’s a concern to move any site from version to version and the whole idea of auto-updating the base of a multi-user site may well sit fine with WP teams but gives me nightmares as I cannot test it before rolling it out.

The other worry in the majority of installs is no thought is given to security of the box - even a simple firewall rule should be included AS A MINIMUM with Fail2Ban etc added.
Need Pi spray - these things are breeding in my house...

Return to “Advanced users”