Ricmedia PC Help

Tech guides for everyone

  • Home
  • Browsers +
    • Chrome
    • Chromium
    • Firefox
    • Internet Explorer
    • Microsoft Edge
    • Safari
    • Opera
    • Browsers (all)
  • Windows +
    • Windows 10
    • Windows 8/8.1
    • Windows 7
    • Windows Vista
    • Windows XP
    • Windows (all)
  • Other OS +
    • Linux
    • MAC OS X
    • Raspbian
    • Other OS (all)
  • MS Office +
    • Office 2013
    • Office 2010
    • Office 2007
  • Raspberry Pi
  • More +
    • Software
    • Networking
    • Hardware
    • Builds
    • Tools & Apps
    • Miscellaneous
    • Support +
      • Help
      • About
      • Sitemap
      • Contact
    • Legal +
      • Privacy
      • Terms
      • Disclaimer
      • Copyright
You are here: Home / Builds / Setup LAMP Server on Raspberry Pi 3 – [Updated 2019] Complete DIY Guide

Setup LAMP Server on Raspberry Pi 3 – [Updated 2019] Complete DIY Guide

March 7, 2017 By Richie 64 Comments

Introduction

[This guide has been fully updated in 2019 to reflect the changes to MySQL in Raspbian “Stretch” v9.x and the FTP issues have been fixed] You wouldn’t think a little PC like the Raspberry Pi 3 could handle the job of being a Web Server, but it does, and performs flawlessly too. Today I will show you how to source genuine Raspberry Pi 3 hardware, then setup a fully fledged LAMP Server (Linux, Apache, MySQL, PHP) along with instructions to install WordPress. You’ll also know how to access your web server via FTP, SSH and PHPMyAdmin. We will be using the latest version of Raspbian “Stretch” v9.x.

Contents

  1. Introduction, Hardware, Download & Burn Raspbian Image
  2. Setup Raspbian
  3. Install LAMP Server Packages, Setup FTP
  4. Install WordPress, Summary

Hardware

My first experience buying a Raspberry Pi 2B didn’t go very well, I unwittingly purchased a fake knockoff from China via eBay that didn’t even work, needless to say I was very disappointed. Since then I have learned you have to be very careful where you buy any Raspberry Pi hardware. There are several official Raspberry Pi hardware suppliers that I’ll list below, but first let’s go through the list of parts you will need for this project.
  1. Raspberry Pi 3 motherboard/SBC
  2. A suitable case for your Pi (I like metal cases)
  3. 8GB (or more) MicroSD card class 10
  4. Raspberry Pi Micro USB power supply
  5. LAN Network cable
Raspberry Pi 3 SBC
Raspberry Pi 3 SBC
Official Raspberry Pi 3 USB Power Supply
Official Raspberry Pi 3 USB Power Supply
Raspberry Pi 3 Metal Case Black
Raspberry Pi 3 Metal Case Black
8GB SanDisk Ultra MicroSD Card Class 10
8GB SanDisk Ultra MicroSD Card Class 10
There are really only two official suppliers of Raspberry Pi gear: RS Components and Farnell/Element14. Both sell world-wide with Farnell selling smaller quantities via authorized resellers. Below you will find links to the entire list of resellers for Element14, Farnell, and a link to all the countries that RS Components serves. I do strongly urge you to only buy from these suppliers or their authorized resellers.
  • Raspberry Pi 3 Official & Authorized Resellers
  • Element14 (main website)
  • Farnell/Element14 World Wide Authorized Resellers
  • RS Components (choose your country)
  • Sources for Suitable MicroSD Cards
  • Predefined eBay.com search for Sandisk Ultra 8GB MicroSD cards
  • Predefined eBay.com search for Sandisk 32GB MicroSD cards
  • Search for Sandisk 32GB MicroSD cards on Google Shopping
  • Raspberry Pi 3 Cases
  • Predefined eBay.com search for Raspberry Pi 3 Metal Cases
  • Search for Raspberry PI 3 Metal Case on Google Shopping
Once you have your Raspberry Pi 3 board and case you can go ahead and fit the board into the case carefully, some of the components on the board are prone to being crushed so be gentle and if something is not fitting, don’t force it.

Download & Burn Raspbian Image

Download Raspbian

Raspbian is the official operating system for the Raspberry Pi, and based on the excellent Debian Linux distribution. Raspain comes in to flavors: full Raspbian with the Pixel desktop, or Raspbian Lite with no desktop, which is the one we want. So go ahead and visit the Raspbian Downloads page, download the Lite version .zip file (if you have a BitTorrent client, choose the .torrent as it’s faster).

Burn Raspbian to SD Card

Once you have finished downloading the Raspbian Zip file, follow the instructions below to burn the IMG file to your MicroSD card.
  1. Unzip the .img file and take note of the file location
  2. Visit etcher.io and download the Etcher Image Burner for Windows, MAC or Linux and install
  3. Insert your MicroSD card into your PC’s card reader, take note of the drive letter assigned to it
  4. Run Etcher and select the .img file you unzipped earlier
  5. Make sure Etcher has selected the correct drive letter, if not then change it to your SD card’s drive letter (Important!)
  6. Once you’re sure the right .img file and drive letter is selected, click the Flash! button
    How to flash MicroSD card with Etcher Image Burner
    How to flash MicroSD card with Etcher Image Burner
  7. Once Etcher has finished, remove the MicroSD card and insert into your Raspberry Pi with the terminal contacts facing up as shown below
    How to insert a MicroSD card into a Raspberry Pi 3
    How to insert a MicroSD card into a Raspberry Pi 3
  8. Now connect up a USB keyboard (mouse not required), HDMI, LAN network cable and have the power supply plugged into the power socket and unit but don’t turn it on just yet
Pages: 1 2 3 4

Filed Under: Builds, Hardware, Linux, Motherboards, Other OS, Raspberry Pi, Raspberry Pi 3, Raspbian, Web Design Tagged With: Apache, LAMP, LAMP Server, Linux, MySQL, PHP, Portable, Raspberry Pi, RasPi, Web Server

Comments

  1. Scott J says

    June 8, 2017 at 1:25 pm

    I think this tutorial is great, and I’m using it this evening to learn about LAMP servers and about my RPi 3. I’m basically new to Linux and while not “new car smell” new, I’m wondering how exactly you envision connecting SFTP? Just since i’m playing around, I figure the SSH-FTP route would be the way to go, but not sure how I’m supposed to use connection data. Are you suggesting using WinSCP or similar which takes the IP address, port, protocol, login, and password? I’m just not clear how that login process is supposed to happen. I’ll dig around on your site some more, but how you’re intending us to apply that information is unclear (I have a guess on some options, but your intention might be easier than what else I might try). Still, I greatly appreciate the post!

    Reply
    • Richie says

      June 8, 2017 at 1:48 pm

      Hi Scott, thanks for your question and feedback. In this tutorial I give two ways to connect to your RPi; (1) via SSH-FTP (SFTP) which is a bit dangerous as you’ll login as root and have access to entire filesystem or (2) install and setup VSFTPD then login using FTPS which is the better option. The client for both connection types is PuTTY, but any FTP client should do. FTPS is FTP over a secure SSL or TLS encrypted connection, whereas SFTP or SSH-FTP is data transfer over the SSH connection. The reason I recommend FTPS is you can lock-down the folder access to just the /var/www folder, whereas the SSH-FTP gives access to the entire filesystem, I realize I could have created a separate Linux user, but it’s difficult to lock down to the /var/www folder, and permissions are a nightmare. Cheers! Richie

      Reply
      • Scott J says

        June 10, 2017 at 11:33 am

        Thank you Richie. The precaution of using VSFTPD makes sense both in your reply above, and in the main article for the security reasons you cited. For my purposes, which is just trying it out at home, the SSH-FTP route is just fine, but I understand your point and its validity.

        One more point, which I think I have right and I’ll make here for anyone passing this way that momentarily is confused on that last section: Although you’re saying to use root for login after changing the sshd_config file, root is not enabled by default on Debian (which Raspbian is based) distributions. You would need to enable the root account, which is not covered in the procedure above.

        Reply
        • Richie says

          June 10, 2017 at 12:30 pm

          Hi Scott, yes VSFTPD is the better/safer option. I actually do go through changing the AllowRootLogin without-password to AllowRootLogin yes under the “Login to FTP as Root User” section, but you may not have read it as you went down the VSFTPD path 😉 Cheers, Richie

          Reply
  2. Scott J says

    June 9, 2017 at 12:03 pm

    My bad…. I missed it…. you have a link to FileZilla in the section just above where I jumped to…. thank you!

    Reply
  3. Tevis C says

    November 30, 2017 at 6:12 am

    I think a great addition to this would be to include a web IDE like Codiad into the tutorial. It allows a new user to get into the web development without getting too deep into setting up an IDE in Linux. This also allows allows the user to code their web page from other devices. I built a WAMP + Codiad + phpMyAdmin and will try to build the same on my R-Pi.

    Reply
    • Richie says

      November 30, 2017 at 8:22 am

      I would love to do many more RPi tutorials, time is the factor 😉 cheers, Richie

      Reply
  4. Angel says

    December 28, 2017 at 8:01 pm

    Thank you very much for this tutorial.

    During the Install MySQL you mention “note* that you will be asked to enter and confirm a root password during the installation process”, this is not my case the process it doesn’t request MySQL password.

    Late in the Setup WordPress Database request the above password, but I don’t know.
    “Login to MySQL as root using the same MySQL root password we entered when installing it earlier”

    Could you please tell me how to get the root MySQL password in your installation process?

    Reply
    • Richie says

      December 28, 2017 at 8:15 pm

      Hi Angel, apparently Debian/Raspbian now has MariaDB as the default database instead of MySQL engine. This has made the setup slightly different in that no root password is given. Basically, instead of using the old -u root -p command you simply use sudo mysql or if you’re already logged in as root just type mysql to bring up the interface. AFAIK MariaDB has no root password making it impossible to actually login as root as a security measure, you need to login with a user that has lower permissions (ie. user of a particular database) or follow this guide on how to give root as password.

      Let me know how you go.
      cheers!
      Richie

      Reply
  5. Michu says

    December 30, 2017 at 10:42 pm

    Hi Richie
    Thanks for the great tutorial!
    I can’t access the phpmyadmin site… how can I delete it on the raspberry to install it again?

    Reply
    • Richie says

      December 30, 2017 at 10:53 pm

      Hi Michu, are you sure you put in the right web address? Remember you need to find the Raspberry Pi IP address with ifconfig OR ip address to find your IP address, then enter http://[ip-address]/phpmyadmin/ so be sure you try that first.

      If you still want to uninstall PHPMyAdmin, login as root and enter the following code on line at a time:

      dpkg -P phpmyadmin
      rm -f /etc/apache2/conf.d/phpmyadmin.conf
      service apache2 restart

      Cheers!
      Richie

      Reply
  6. Joshua says

    January 7, 2018 at 5:40 am

    Hi Richie,

    Thanks for putting this tutorial together! I was going through the steps using Raspbian 9.3 and encountered a problem with http:///phpmyadmin/ similar to Michu after completing the phpmyadmin install instructions above. I corrected the 404 not found by including an extra step:

    nano /etc/apache2/apache2.conf

    At the bottom of the file append:

    Include /etc/phpmyadmin/apache.conf

    Save and quit, then restart the service:

    service apache2 restart

    These steps made the phpmyadmin web interface login available.

    Reply
    • Richie says

      January 7, 2018 at 11:46 am

      Hi Joshua, thanks for the info. The issue is due to Debian changing the default MySQL engine from MySQL to MariaDB in version 9.x which is why I link directly to version 8.x Jessie in the guide. I will have to update the guide to reflect these change as soon as I can.

      cheers
      Richie

      Reply
  7. orthodoxcumbriawebmaster says

    January 27, 2018 at 4:08 am

    I think something has changed in the way phpmyadmin is set up, I have tried several tutorials without success. I can log in as phpmyadmin, but then can’t create a new database (no privileges), and root access is denied:
    #1698 – Access denied for user ‘root’@’localhost’
    mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’

    Googling for a solution offers many, but there is no trace of AllowRootLogin in any of the configuration files……

    I’ve done this many times on other machines, but this has be stumped.

    Reply
    • Richie says

      January 27, 2018 at 10:59 am

      Hi Richard, yes it’s actually MySQL that has changed and now does not allow root login via phpmyadmin interface. But you can fix this issue by following this guide: https://askubuntu.com/questions/763336/cannot-enter-phpmyadmin-as-root-mysql-5-7

      Let me know how you go mate.

      cheers!
      Richie

      Reply
  8. Angelo says

    January 30, 2018 at 10:30 am

    Thanks alot for the guide. Please note that default phpmyadmin login details are: phpmyadmin with the password that you provided in the setup prompt.

    Reply
  9. Richie says

    January 30, 2018 at 8:43 pm

    Please Note* This guide has been fully updated (2018-01-30) to reflect the changes to MySQL in Raspbian “Stretch” version 9.x, which has caused a lot of the code to break. There are a few different aspects to how we create databases in that we run MySQL with the sudo prefix instead of logging in as root. Also, all code is now written to conform to the Linux sudo system which greatly increases security.

    Let me know if you have any issues with the new code and instructions, but I think you’ll find it all works far better now.

    Cheers!
    Richie

    Reply
  10. Kenneth H says

    February 4, 2018 at 6:28 pm

    awesome tutorial !

    everything worked perfect, untill i installed wordpress.

    after i Enter database details and then click Submit, i get this error

    Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

    Are you sure you have the correct username and password?
    Are you sure that you have typed the correct hostname?
    Are you sure that the database server is running?
    If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

    i am 100% sure i enter the right username and password.

    what could the problem be, and how can i fix it ?

    Reply
    • Richie says

      February 4, 2018 at 6:50 pm

      Hi Kenneth, thanks mate. This error means that either one or more of the following is incorrect: db username, db password, db host (which should be localhost). When you entered the code to create the database user: create user 'wordpress'@'localhost' identified by '[enter password]'; did you enter password without the brackets? like this: create user 'wordpress'@'localhost' identified by 'abc123'; ? If you’re unsure, create a new database and user as follows:

      1
      2
      3
      4
      5
      create user 'wordpress2'@'localhost' identified by 'abc123';
      create database wordpress2;
      grant all privileges on wordpress2.* to 'wordpress2'@'localhost';
      flush privileges;
      exit;

      Then enter username: wordpress2, password: abc123, database name: wordpress2, host: localhost, db prefix: wp_ and see if that works mate.

      Let me know how you go.
      cheers
      Richie

      Reply
      • Kenneth H says

        February 4, 2018 at 10:44 pm

        that did the trick 🙂

        thank you ! and sorry for my noob mistake

        Reply
        • Richie says

          February 4, 2018 at 10:46 pm

          No worries at all mate, cheers, Richie

          Reply
  11. R C says

    April 11, 2019 at 4:51 pm

    This is great. Thanks for the thorough guide!

    However, somewhere around this part it is failing:

    “We also need to add user pi to the www-data group, give ownership of the /var/www folder to www-data user and group, change user pi’s home folder to same, and loosen some permissions on the /var/www folder”

    the second usermod command, I was getting “the user pi is in use by process: XXX”. So I attempted to boot into the CLI instead to see if I could get it complete the command, I figured perhaps the GUI was causing an issue, as it seems most of this guide is written with CLI /lite installs in mind.

    it still does not complete that command.

    Do you have any idea why?

    Reply
    • Richie says

      April 11, 2019 at 5:40 pm

      Howdy RC, thanks for the feedback mate. the error: “the user pi is in use by process: XXX” is usually because you’re not logged in as root, so be sure to su and enter root password. Let me know how that goes and will update the guide. cheers, Richie

      Reply
      • Phill says

        May 29, 2019 at 9:05 pm

        I’m having the same issue and getting the same error message (“the user pi is in use”). I saw this comment regarding logging in as root as followed that another tutorial for logging in as root because I had never done it before and didn’t know what the password was.

        Anyways I logged in as root and was able to complete the command (sudo usermod -m -d /var/www pi). When I log back in as “pi” and run all 4 commands in that section they all appear to go through, however “sudo usermod -m -d /var/www pi” returns the message “No Changes” rather than “the user pi is in use”.

        I thought everything had worked, but I still can’t log in to the pia via FTP/Filezilla. The settings match what is in the tutorial, but Filezilla tells me “Connection attempt failed with “ECONNREFUSED – Connection refused by server”.

        I’m definitely a beginner level with most of this and just wanted to try learning PHP and MySQL. If there’s more information I can provide I’ll be happy to if I know how to get it.

        Reply
        • Richie says

          May 30, 2019 at 6:39 pm

          Hi Phill, thanks for letting me know this, I have fixed the issue by creating a new user called piftp as it seems too difficult to alter user pi while logged in as pi, and I didn’t want to use the nuclear option of logging in as root. I have run through the entire tutorial again and all works 100% now, perhaps you could confirm this for me buy running through it again? cheers! Richie

          Reply
          • harrison says

            June 26, 2019 at 5:15 am

            Hey Richie! Thank you so much for the incredible guide! Just got my first pi 3 and am having a similar issue even with the updated guide using piftp instead of pi. Im still not able to ftp into my pi and get the ECONNREFUSED error. Any idea??

          • Richie says

            June 26, 2019 at 1:20 pm

            Hi Harrison, no worries at all 🙂 I went through the guide again with a fresh install of Raspbian Buster and it all works ok on my end. Usually this happens because of the FTP client settings, are you using Filezila? And with the following settings? FileZilla settings Also check out the FileZilla network config page and try some of the suggestions there. Let me know how you go. cheers! Richie

  12. ITSP says

    June 12, 2019 at 1:56 pm

    Hi,
    Thank you very much for this tutorial.

    i just have an issue with public IP that wordpress plugin installation error and ask for ftp login details. when i put login detail it says login failed.

    please help me…

    Thank you.

    Reply
    • Richie says

      June 12, 2019 at 2:04 pm

      Hi there, no probs. Did you change ownership of the entire html folder to www-data? You’ll need to enter the following: chown -Rf www-data:www-data /var/www/html and then retry installing the WordPress plugin. Let me know how you go mate.

      cheers!
      Richie

      Reply
  13. Heath Knight says

    August 6, 2019 at 11:08 pm

    Many thanks Richie,
    This is exactly the way the internet should be…. knowledge sharing at its best. You have enabled me to acomplish a pretty challenging task (for an old duffer like me) setting up LAMP on the Pi, I am a bit uncertain of what exactly WordPress does, but at least it is now parked on my Pi as I progress setting up the webserver.
    One comment for Pi newbies… don’t forget to make a disk image backup of that fragile little SD card after doing all this.

    Reply
    • Richie says

      August 6, 2019 at 11:20 pm

      Thanks Heath, glad you enjoyed the tutorial. WordPress is basically a publishing platform, think of it like Word for the web 🙂 You might also be interested in learning more about PHP? If so I can highly recommend Brad Traversy’s free YouTube course PHP Front to Back. Cheers! Richie

      Reply
  14. Alan says

    August 26, 2019 at 3:50 pm

    Where can I locate the location of the php.ini so I can edit the file? Thank you so much for the great tutorial!

    Reply
    • Richie says

      August 26, 2019 at 4:59 pm

      Hi Alan, no worries glad you liked the tutorial! As we’re using Apache’s build-in PHP processor libapache2-mod-php the location of the php.ini is /etc/php/7.2/apache2/php.ini but it will depend on which version of PHP you’re running, so replace the 7.2 with your version. Run cd /etc/php and then the dir command to see what version you have installed.

      Cheers!
      Richie

      Reply
  15. Teme says

    September 11, 2019 at 11:09 pm

    I tried this but it didn’t work or everything else seems to work but wordpress…booking in the wp doesn’t work for me althoug I quite sure I fill all fields as they shoud. I tried also manualy configurate wp but that didn’t work either. Maybe I try to remove wp user and db and create those again.

    Reply
    • Richie says

      September 13, 2019 at 5:32 pm

      Hi Teme, most likely a folder permission/ownership issue or incorrect database details. Make sure you run chown -R www-data:www-data /var/www/html/* after downloading and unzipping WordPress, and double check your database details. If you’re unsure, try creating a new database and user, login to mysql:

      mysql -uroot -p'MyPassword'

      then…


      create database wordpress2;
      create user 'wordpress2'@'localhost' indentified by 'MyPassword';
      grant all privileges on wordpress2.* to 'wordpress2'@'localhost';
      flush privileges;
      exit;

      See how you go and let me know if you have success.

      cheers!
      Richie

      Reply
      • Teme says

        October 4, 2019 at 11:15 pm

        Actually now I found out what was wrong….I put password inside these []…total brain fart…now its working fine.

        Reply
        • Richie says

          October 6, 2019 at 11:46 am

          oh well not to worry 🙂

          Reply
  16. Bob G says

    September 22, 2019 at 4:44 am

    Hello, I got this installed without any real issues and have been testing some installs of some PHP Websites I’m working on. I’m using a Raspberry Pi 3b and of the 5 websites I working on only one is giving me a fit. Please note I have these all running on Production Web Servers and on a Windows EasyPHP setup.

    Only one will not run and gives me a 500 error and for the life of me I can’t get it to run.

    I was hoping to get everything running on a Pi so I could travel, do installs and run small training sessions.

    Thanks for your attention and help.

    Reply
    • Richie says

      September 22, 2019 at 6:21 am

      Hi Bob, sounds like a PHP or Apache issue, without knowing exactly whats causing it you’ll need to look in your Apache error logs: nano /var/log/apache2/error.log and track down the error. There is also a guide on analyzing Apache 500 errors.

      Let me know how you go mate.

      cheers!
      Rich

      Reply
  17. Max Müller says

    October 5, 2019 at 11:12 pm

    Hi

    first of all, thank you very much for this great tutorial for setup MariaDB and PHP. Before I fund your tutorial, I had 3 crashed installations of mariadb/mysql,
    but now until finishing by the tutorial without any problem!

    ok, the database is still not defined, it doesn’t exist until now
    my system is a RPi4 with a SSD-USB drive and all the Databases has to be there
    until now, I could not find any info’s, how to provide this

    where I can find more info’s?

    thanks again
    Max

    Reply
    • Richie says

      October 6, 2019 at 11:45 am

      Hi Max, not sure exactly what information you’re after mate? So there are 3 databases on the SUB drive that you want to access? cheers! Rich

      Reply
  18. David J HALLOWS says

    October 12, 2019 at 9:44 am

    Thanks so much Richie. I’ve been going round in circles for days following various tutorials, almost at the point of giving up. Hopefully you’ll never hear from me again. Big up.

    Dave

    Reply
    • Richie says

      October 12, 2019 at 8:45 pm

      Thanks Dave. 🙂 cheers!

      Reply
  19. David J HALLOWS says

    October 12, 2019 at 8:36 pm

    Hi Richie

    Thanks so much for putting all this together, I’ve been trying for a few weeks now, following various tutorials and them all breaking at various points. Last night I ripped through yours and it’s all working brilliantly. My pi 4 is all wordpressed up 🙂

    I’ve got a question if I may; when I try to move a folder (theme) into the server using Filezilla, it won’t create directories and fails. The Filezilla help threads point to server issues and it’s out of their hands. I know from the other tutorials I used, it seemed to always be permission/user errors that killed me off! This is the type of response people with the same problem have been getting-

    The router already runs some sort of FTP server software. But that software must be configured correctly, currently it seems to be read only (at least you can’t create directories). This must be fixed on the server end directly, no way to do this through FileZilla Client.

    Any ideas

    Thanks again
    Dave

    Reply
    • Richie says

      October 12, 2019 at 8:54 pm

      Hi Dave, are you hooked into a web server via a company (GoDaddy hosting, DreamHost etc) or do you have something like a DigitalOcean droplet you setup yourself? Either way it sounds like a permission issue and your FTP user doesn’t have folder write permissions. If you’re with a hosting company, login to their control panel (possibly example.com/cpanel) and create an SFTP user with full write permissions for the website folder, then delete what you have already uploaded and re-upload with your new SFTP user, see if that solves the issue. cheers! Richie

      Reply
  20. David J HALLOWS says

    October 12, 2019 at 9:09 pm

    Thanks for the super swift response Richie 🙂

    In short no, I’m not hooked into any webservers companies. I was hoping to run my own server with the pi? I’m at the stage where I followed your tutorial and set up the LAMP server. I was hoping to get my domain name diverted/hooked up to my wordpress site when it’s all done. So, the FTP user is pi?

    Apologies for the rookie knowledge!

    Cheers
    Dave

    Reply
    • Richie says

      October 12, 2019 at 9:36 pm

      ahh I see, now you’re getting into DNS and networking which is more complicated, but I’ll guide you through it. You’re home Internet connection likely uses a dynamic IP address, which means it changes every few days or weeks, but if you want to host a web server, you need either a dedicated (consistent) IP address, or a service that automatically updates your website IP when it changes (preferred option). See this guide, this one and this one. You will also have to set this up in your router/modem and give your PI a dedicated local IP address (i.e 192.168.1.100) and make that IP a DMZ zone or port-forward ports 80 and 443 (will depend on what services you’re running, ports 80 and 443 are website ports) to your Pi’s local IP from your WAN.

      Hope this helps mate.

      cheers!
      Richie

      Reply
  21. David J HALLOWS says

    October 12, 2019 at 10:11 pm

    Hi Richie

    Thanks for the networking info, I have set up some port forwarding settings but will need to do this properly. In terms of the write permissions problem, I’m presuming that it won’t be changed/solved by the networking elements….would this work –

    sudo chgrp www-data /html
    sudo chmod 777 /html
    sudo chmod g+s /html
    sudo usermod -a -G pi
    sudo chown -R pi /html

    Cheers
    Dave

    Reply
    • Richie says

      October 12, 2019 at 10:26 pm

      Ok try the following:

      su [enter root password]
      cd /var/www/html
      chown -R www-data:www-data /var/www/html
      usermod -a -G www-data pi
      usermod -m -d /var/www pi
      chmod -R 755 /var/www/html/

      That should solve permission issues, then try sftp again.

      cheers
      Richie

      Reply
  22. Kev says

    October 18, 2019 at 5:59 pm

    After following your guide, how would I go about on enabling Python in Apache and linking it with the MySQL DB? What is the account for the DB is it what we use for phpmyadmin?

    Reply
    • Richie says

      October 18, 2019 at 6:42 pm

      Hi Kev, (please read this thoroughly first). Better not to use the phpmyadmin account and instead login to MySQL as root via the command line mysql -uroot -pMyPassword then create a new database and user as follows:


      create database my_new_database;
      create user 'MyNewUser'@'localhost' identified by 'MyUsersPassword';
      grant all privileges on my_new_database.* to 'MyNewUser'@'localhost';
      flush privileges;
      exit;

      From this point you can access MySQL via localhost, username and database name in your Python scripts. If you wanted to run Python scripts like web pages (index.py) similar to the way PHP runs, you’re better off following this guide as you’ll need FastCGI and mpm_event disabled. I advise the latter.

      cheers!
      Richie

      Reply
    • Matt says

      November 3, 2019 at 8:24 am

      Great update on this guide. I used a similar one about 2 years ago. Is anyone else having trouble installing apache at the moment? Mirror down??
      E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/a/apache2/apache2-bin_2.4.38-3+deb10u1_armhf.deb 404 Not Found [IP: 93.93.128.193 80]
      E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/a/apache2/apache2-data_2.4.38-3+deb10u1_all.deb 404 Not Found [IP: 93.93.128.193 80]
      E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/a/apache2/apache2-utils_2.4.38-3+deb10u1_armhf.deb 404 Not Found [IP: 93.93.128.193 80]
      E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/a/apache2/apache2_2.4.38-3+deb10u1_armhf.deb 404 Not Found [IP: 93.93.128.193 80]

      Reply
  23. patrickvandewinkel says

    October 27, 2019 at 8:02 am

    hi where do i need to download the package for ftp in /var/www/html or does it need another directory

    Reply
  24. Bob G says

    November 4, 2019 at 6:03 am

    I may have found the issue, the php version is to high for this script, is there a way to install an older version before version7?

    Reply
  25. cinetube says

    November 6, 2019 at 1:32 pm

    Thanks for your detailed DIY Guide. Will it be possible for you to create a bash script so that I can install LAMP and wordpress within a few minutes without any interaction?

    Reply
    • Richie says

      November 6, 2019 at 7:29 pm

      Hi, writing bash scripts is pretty easy, try using the commands in my guide and build one, https://ryanstutorials.net/bash-scripting-tutorial/bash-input.php.

      cheers
      Richie

      Reply
  26. DaveH says

    November 15, 2019 at 9:45 pm

    Hi Richie

    Thanks again for the awesome tut. I’ve had lots of attempts to get it up and running and have largely succeeded. I’ve done the duckdns.org and CNAME pointed my domain to it, set up the Certbot SSL and it’s pretty solid 🙂 I had to change the wp-config settings to this, to resolve weird formatting issues:

    define(‘WP_HOME’,’https://192.168.1.108′);
    define(‘WP_SITEURL’,’https://www.davidhallows.com’);

    Also to solve some ssl issues I did this too:

    A simple solution is to force SSL by modifying wp-config.php.
    Find:
    define(‘WP_DEBUG’, false);
    Directly below that, add:
    if ( $_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’ )
    {
    $_SERVER[‘HTTPS’] = ‘on’;
    $_SERVER[‘SERVER_PORT’] = 443;
    }
    Save wp-config.php and reload the page.

    Although it seemed to be rock solid last night, I can’t login to WordPress now, nor will it send me a email reset, I get this weird message –

    The email could not be sent. Possible reason: your host may have disabled the mail() function.

    So, the really weird bit seems to be the WordPress PHPmyadmin doesn’t show a WordPress table. Lots of fixes resolve around the access to that but I just have this in the table field:

    information_schema
    phpmyadmin

    Any awesome advice or ideas much appreciated.
    Thanks again

    Dave

    Reply
    • Richie says

      November 16, 2019 at 8:25 pm

      Hi Dave, no problems mate. Ok so I will try and answer your questions on a point by point:

      • There would be a conflict having HOME_URL set to an IP address and SITE_URL to your domain name, they need to be the same afaik
      • Ubuntu/Debian and PHP won’t send mail without some initial setup, see this guide
      • you will need to login using the username (probably wordpress?) and password you used to create the WP database, phpmyadmin won’t have access to it, only WP database user and root

      That should solve any issues, let me know how you go.

      cheers!
      Richie

      Reply
  27. DaveH says

    November 19, 2019 at 10:00 am

    Hiya Richie

    I stripped it out and follwed your tut again, changed both URL’s and bingo – http://www.davidhallows.com!! Super happy. Not entirely sure what weird password idea I’d had…I also spent some time on a thread with Let’s Encrypt who helped with the Certbot SSL encryption 🙂 Do you have any back up suggestions, I’d feel gifted if I knew how to reinstall after a bodge.

    Thanks for all your help
    Dave

    Reply
    • Richie says

      November 19, 2019 at 9:23 pm

      Hi Dave, yep sometimes starting over is the best option. I don’t know how many times I’ve done that when writing guides etc to make sure it all works 😉 If you want to backup your database and WP installation, use WP-DBManager and then backup your wp-content folder via crontab. You can then download the compressed file to your local PC or rsync it to another server. There are also backup plugins available for WP.

      cheers mate!
      Richie

      Reply
  28. Josie says

    January 17, 2020 at 3:55 pm

    I manage to complete the lamp server but I cant access it on other device in my local network. I am both my other computer and my raspberry are connect to the same internet but can’t see it. Also how do you allow it to see the website on a phone?

    Reply
    • Richie says

      January 17, 2020 at 5:06 pm

      Hi Josie, are you typing in the IP address of the Pi? it’s should be 192.168.x.x or 10.0.0.x or 172.16.x.x. If you login to your Pi and enter this command: ip addr show it will show your Pi’s IP address, then type that address into your web browsers address bar. If you’re trying to use a domain name, you’d need to setup a dynamic IP system with a company like DynDNS and set up Apache to accept requests for that domain name using VirtualHosts.

      cheers!
      Richie

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Help & Support • Legal, Terms & Privacy • Contact Details • Copyright ©2006- Ricmedia • Part of the Ricmedia group of websites   Part of the Ricmedia group of websites