May 07, 2018
As it is a server, you may want to run it headless (i.e., without display, no GUI). Hence, you could download the Noobs lite version and install the minimum Raspbian OS (without Desktop GUI). Add an empty file 'ssh' to the root folder of your mini sd card to enable SSH access. Find your pi's IP address from your router, then you can access it headlessly by
Default password is 'raspberry'. Change your 'pi' password as soon as you get in
sudo passwd pi
Run the following commands:
sudo apt-get install apache2 -y sudo nano /etc/apache2/sites-enabled/000-default.conf
You must update the domain name of the website you are building at this time. If you are content to host this internally, then you may skip this, but you will always have to use the IP address of the Raspberry Pi to access the site.
ServerName example.com ServerAdmin [email protected]
Then enable apache and check status by these commands:
sudo systemctl enable apache2 sudo systemctl start apache2 sudo systemctl status apache2
You can test the web server by enter the address
http://localhost or the IP address of your Pi into Web Browser.
You should see this in your browser window:
Install the PHP and Apache packages with the following command:
sudo apt-get install php -y sudo service apache2 restart sudo nano /var/www/html/info.php
Add the following into the newly created file:
<?php phpinfo(); ?>
Ctrl-X to exit, Y to save. Test that you have successfully set up PHP by entering your browser and using
sudo mv /var/www/html/index.html /var/www/html/index.old
sudo apt-get install mysql-server php-mysql -y sudo systemctl start mysql sudo systemctl status mysql sudo service apache2 restart sudo mysql_secure_installation
I changed the root password, removed test database, and removed the anonymous user access. The rest I did not change. You can test that MySQL is running by entering:
sudo mysql -u root -p
quit to exit MySQL.
Also, give Lets Encrypt a go!
sudo apt-get install git sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt cd /opt/letsencrypt ./letsencrypt-auto --apache -d example.com -d www.example.com
To renew the certificate (when you receive a reminder email that your certificate is expiring), I just ran:
cd /opt/letsencrypt ./letsencrypt-auto renew
During the setup of PHPMyAdmin, you will be asked some questions; choose Apache and No to the DB Common.
sudo apt-get -y install phpmyadmin sudo nano /etc/apache2/apache2.conf
You must add an include to the end of the apache.conf file:
Ctrl-X to exit, Y to save.
sudo systemctl restart apache2.service
You are no longer able to log in to PHPMyAdmin using root, so you will need to create an alternate user with full admin rights as follows:
sudo mysql -u root -p CREATE USER 'admin'@'localhost' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES; quit
Then you must reference the new user name in the config file as follows:
sudo nano /etc/dbconfig-common/phpmyadmin.conf
Replace phpmyadmin user name with just admin:
# dbc_dbuser: database user # the name of the user who we will use to connect to the database. dbc_dbuser='admin'
To access PHPMyAdmin, you can access using the new link:
With this minimal LAMP server you can setup: