{"id":89427,"date":"2019-09-19T13:45:47","date_gmt":"2019-09-19T13:45:47","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=89427"},"modified":"2021-09-07T19:27:18","modified_gmt":"2021-09-07T19:27:18","slug":"raspberry-pi-apache-mysql-php-lamp-server","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/","title":{"rendered":"Raspberry Pi: Install Apache + MySQL + PHP (LAMP Server)"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to install a LAMP (<strong>L<\/strong>inux, <strong>A<\/strong>pache, <strong>M<\/strong>ySQL, <strong>P<\/strong>HP) server on a Raspberry Pi. <strong>LAMP<\/strong> is a software bundle that is used for web development. The Raspberry Pi will have Raspbian OS installed and you&#8217;ll use phpMyAdmin to easily manage your database through a web interface.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install on Raspberry Pi Apache + PHP + MySQL + phpMyAdmin LAMP Server\" class=\"wp-image-89429\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before continuing with this tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You should be familiar with the Raspberry Pi board \u2013&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\" target=\"_blank\">read Getting Started with Raspberry Pi<\/a>;<\/li><li>You should have the Raspbian or Raspbian Lite operating system installed \u2013&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\" target=\"_blank\">read Installing Raspbian Lite, Enabling and Connecting with SSH<\/a>;<\/li><li>You also need the following hardware: <ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/raspberry-pi-board\/\" target=\"_blank\">Raspberry Pi board<\/a>&nbsp;\u2013 read&nbsp;<a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-starter-kits\/\" target=\"_blank\">Best Raspberry Pi Starter Kits<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\">MicroSD Card \u2013 16GB Class10<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-power-supply\/\" target=\"_blank\">Raspberry Pi Power Supply (5V 2.5A)<\/a> <\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"rntbox rntclblue\">If you like home automation and you want to build a complete home automation system, I recommend downloading my <a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\">home automation course<\/a>.<\/p>\n\n\n\n<p>After having your Raspberry Pi board prepared with Raspbian OS, you can continue with this tutorial.<\/p>\n\n\n\n<p>You can either run the next commands on a Raspberry Pi set as a desktop computer or using an <a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\">SSH connection<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Updating and Upgrading<\/h2>\n\n\n\n<p>Before starting the installation procedure, open a Terminal window and run the following commands to update your Pi:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install Apache2 on Raspberry Pi<\/h2>\n\n\n\n<p>Apache2 is the most widely used web server software. Briefly, a web server is the software that handles requests to access a web page. Then, depending on the page you have requested, the server will generate the document to serve you (<em>.html<\/em>, <em>.php<\/em>, etc).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1105\" height=\"309\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/raspberry-pi-lamp-server-overview.png?resize=1105%2C309&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Apache2 on Raspberry Pi LAMP Server overview\" class=\"wp-image-89491\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/raspberry-pi-lamp-server-overview.png?w=1105&amp;quality=100&amp;strip=all&amp;ssl=1 1105w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/raspberry-pi-lamp-server-overview.png?resize=300%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/raspberry-pi-lamp-server-overview.png?resize=768%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/raspberry-pi-lamp-server-overview.png?resize=1024%2C286&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1105px) 100vw, 1105px\" \/><\/figure><\/div>\n\n\n\n<p>To install Apache2 on your Raspberry Pi, run the next command:<\/p>\n\n\n\n<pre class=\"wp-block-code command-line\"><code>pi@raspberrypi:~ $ sudo apt install apache2 -y<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"749\" height=\"322\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-Install-Apache2.png?resize=749%2C322&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Install Apache2 LAMP Server\" class=\"wp-image-89434\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-Install-Apache2.png?w=749&amp;quality=100&amp;strip=all&amp;ssl=1 749w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-Install-Apache2.png?resize=300%2C129&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 749px) 100vw, 749px\" \/><\/figure><\/div>\n\n\n\n<p>That&#8217;s it! Apache is now installed. To test your installation, change to the <span class=\"rnthl rntliteral\">\/var\/www\/html<\/span> directory and list the files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ cd \/var\/www\/html\npi@raspberrypi:\/var\/www\/html $ ls -al\nindex.html<\/code><\/pre>\n\n\n\n<p>You should have an <em>index.html<\/em> file in that folder. To open that page in your browser, you need to know the Raspberry Pi IP address. Use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ hostname -I<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"501\" height=\"178\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-change-directory-RPi-IP-Address.png?resize=501%2C178&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi change directory RPi IP Address\" class=\"wp-image-89435\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-change-directory-RPi-IP-Address.png?w=501&amp;quality=100&amp;strip=all&amp;ssl=1 501w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-change-directory-RPi-IP-Address.png?resize=300%2C107&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/figure><\/div>\n\n\n\n<p>In my case, the Raspberry Pi IP address is 192.168.1.86. If you open your RPi IP address in any browser in your local network, a similar web page should load (<strong>http:\/\/192.168.1.86<\/strong>):<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"565\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-Apache2-Installed.png?resize=840%2C565&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Apache2 Installed\" class=\"wp-image-89436\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-Apache2-Installed.png?w=840&amp;quality=100&amp;strip=all&amp;ssl=1 840w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-Apache2-Installed.png?resize=300%2C202&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-Apache2-Installed.png?resize=768%2C517&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Install PHP on Raspberry Pi<\/h2>\n\n\n\n<p>PHP is a server side scripting language. PHP (<strong>H<\/strong>ypertext <strong>P<\/strong>re<strong>p<\/strong>rocessor) is used to develop dynamic web applications. A PHP file contains <span class=\"rnthl rntliteral\"><span style=\"color: #333399;\">&lt;?php &#8230; ?&gt;<\/span><\/span> tags and ends with the extension &#8220;<em>.php<\/em>&#8220;.<\/p>\n\n\n\n<p>To install PHP on Raspberry Pi, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo apt install php -y<\/code><\/pre>\n\n\n\n<p>You can remove the <em>index.html<\/em> and create a PHP script to test the installation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo rm index.html\npi@raspberrypi:\/var\/www\/html $ sudo nano index.php<\/code><\/pre>\n\n\n\n<p>In your <em>index.php<\/em> file add the following code to echo the &#8220;<strong>hello world<\/strong>&#8221; message:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php echo \"hello world\"; ?&gt;<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"354\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-Create-PHP-Test-File-Hello-World.png?resize=597%2C354&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Create PHP Test File Hello World\" class=\"wp-image-89437\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-Create-PHP-Test-File-Hello-World.png?w=597&amp;quality=100&amp;strip=all&amp;ssl=1 597w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-Create-PHP-Test-File-Hello-World.png?resize=300%2C178&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/figure><\/div>\n\n\n\n<p>To save your file: press <strong>Ctrl+X<\/strong>, followed by <strong>y<\/strong>, and press <strong>Enter <\/strong>to exit.<\/p>\n\n\n\n<p>Finally, restart Apache2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo service apache2 restart<\/code><\/pre>\n\n\n\n<p>To test if Apache2 is serving <em>.php<\/em> files, open the Raspberry Pi IP address and it should display the &#8220;<strong>hello world<\/strong>&#8221; message from the <em>index.php<\/em> script created earlier.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"233\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-test-PHP-File-Hello-World-message-web-browser.png?resize=557%2C233&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi test PHP File Hello World message web browser\" class=\"wp-image-89438\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-test-PHP-File-Hello-World-message-web-browser.png?w=557&amp;quality=100&amp;strip=all&amp;ssl=1 557w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-test-PHP-File-Hello-World-message-web-browser.png?resize=300%2C125&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/figure><\/div>\n\n\n\n<p>If everything is working, you can remove <em>index.php<\/em> file from the <span class=\"rnthl rntliteral\">\/var\/www\/html<\/span> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo rm index.php<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install MySQL (MariaDB Server) on Raspberry Pi<\/h2>\n\n\n\n<p>MySQL (often pronounced <strong>My<\/strong> <strong>S<\/strong>&#8211;<strong>Q<\/strong>&#8211;<strong>L<\/strong>) is a popular open source relational database.<\/p>\n\n\n\n<p>Install the MySQL Server (MariaDB Server) and PHP-MySQL packages by entering the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo apt install mariadb-server php-mysql -y\npi@raspberrypi:\/var\/www\/html $ sudo service apache2 restart<\/code><\/pre>\n\n\n\n<p>After installing MySQL (MariaDB Server), it&#8217;s recommend to run this command to secure your MySQL installation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>This should appear in your Terminal window:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-MySQL-MariaDB-Install-Secure-Installation.png?resize=773%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi MySQL Database MariaDB Secure Installation\" class=\"wp-image-89439\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-MySQL-MariaDB-Install-Secure-Installation.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-MySQL-MariaDB-Install-Secure-Installation.png?resize=300%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-MySQL-MariaDB-Install-Secure-Installation.png?resize=768%2C288&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>You will be asked Enter <strong>current password for root<\/strong> (type a secure password): press Enter<\/li><li>Type in <strong>Y<\/strong> and press <strong>Enter <\/strong>to Set root password<\/li><li>Type in a password at the New password: prompt, and press Enter. Important: remember this root password, as you will need it later<\/li><li>Type in <strong>Y<\/strong> to Remove anonymous users<\/li><li>Type in <strong>Y<\/strong> to Disallow root login remotely<\/li><li>Type in <strong>Y<\/strong> to Remove test database and access to it<\/li><li>Type in <strong>Y<\/strong> to Reload privilege tables now<\/li><\/ul>\n\n\n\n<p>When the installation is completed, you&#8217;ll see the message: &#8220;Thanks for using MariaDB!&#8221;.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-MySQL-Database-MariaDB-Final-Secure-Installation.png?resize=773%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi MySQL Database-MariaDB Final Secure Installation\" class=\"wp-image-89440\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-MySQL-Database-MariaDB-Final-Secure-Installation.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-MySQL-Database-MariaDB-Final-Secure-Installation.png?resize=300%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-MySQL-Database-MariaDB-Final-Secure-Installation.png?resize=768%2C288&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<p>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). <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo mysql --user=root --password\n&gt; create user admin@localhost identified by 'your_password';\n&gt; grant all privileges on *.* to admin@localhost;\n&gt; FLUSH PRIVILEGES;\n&gt; exit;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install phpMyAdmin on Raspberry Pi<\/h2>\n\n\n\n<p>phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL using a web interface. <\/p>\n\n\n\n<p>To install phpMyAdmin on a Raspberry Pi, type the following command into the terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo apt install phpmyadmin -y<\/code><\/pre>\n\n\n\n<p>PHPMyAdmin installation program will ask you few questions. We&#8217;ll use the <strong>dbconfig-common<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Select <strong>Apache2 <\/strong>when prompted and press the <strong>Enter <\/strong>key<\/li><li>Configuring <strong>phpmyadmin<\/strong>? <strong>OK<\/strong><\/li><li>Configure database for phpmyadmin with <strong>dbconfig-common<\/strong>? <strong>Yes<\/strong><\/li><li>Type your <strong>password <\/strong>and press <strong>OK<\/strong><\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-install-phpMyAdmin.png?resize=773%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi install phpMyAdmin\" class=\"wp-image-89442\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-install-phpMyAdmin.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-install-phpMyAdmin.png?resize=300%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-install-phpMyAdmin.png?resize=768%2C288&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<p>Enable the PHP MySQLi extension and restart Apache2 for changes to take effect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo phpenmod mysqli\npi@raspberrypi:\/var\/www\/html $ sudo service apache2 restart<\/code><\/pre>\n\n\n\n<p>When you go to your RPi IP address followed by <strong>\/phpmyadmin<\/strong> (in my case <span class=\"rnthl rntliteral\">http:\/\/192.168.1.86\/phpmyadmin<\/span>), you&#8217;ll probably see the &#8220;Not Found&#8221; error page in your browser:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"927\" height=\"454\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-Failed-to-open-phpMyAdmin-Raspberry-Pi.png?resize=927%2C454&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Failed to open phpMyAdmin Raspberry Pi\" class=\"wp-image-89444\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-Failed-to-open-phpMyAdmin-Raspberry-Pi.png?w=927&amp;quality=100&amp;strip=all&amp;ssl=1 927w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-Failed-to-open-phpMyAdmin-Raspberry-Pi.png?resize=300%2C147&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-Failed-to-open-phpMyAdmin-Raspberry-Pi.png?resize=768%2C376&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 927px) 100vw, 927px\" \/><\/figure><\/div>\n\n\n\n<p>If that&#8217;s the case, you&#8217;ll have to move the <strong><em>phpmyadmin<\/em><\/strong> folder to <span class=\"rnthl rntliteral\">\/var\/www\/html<\/span>, run the next command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ sudo ln -s \/usr\/share\/phpmyadmin \/var\/www\/html\/phpmyadmin<\/code><\/pre>\n\n\n\n<p>Now, if you list the files, it should return the <strong>phpmyadmin <\/strong>folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ ls\nphpmyadmin<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-Raspberry-Pi-move-phpMyAdmin.png?resize=773%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi move phpMyAdmin to \/var\/www\/html phpMyAdmin folder\" class=\"wp-image-89443\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-Raspberry-Pi-move-phpMyAdmin.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-Raspberry-Pi-move-phpMyAdmin.png?resize=300%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-Raspberry-Pi-move-phpMyAdmin.png?resize=768%2C288&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<p>Reload your web page (<strong>http:\/\/192.168.1.86\/phpmyadmin<\/strong>), your should see the login page for phpMyAdmin web interface::<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"753\" height=\"703\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?resize=753%2C703&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Open phpMyAdmin Login Page\" class=\"wp-image-89446\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?w=753&amp;quality=100&amp;strip=all&amp;ssl=1 753w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?resize=300%2C280&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/figure><\/div>\n\n\n\n<p>Enter your defined username (it should be <strong>Username = root<\/strong>) and the password you defined during the installation. <\/p>\n\n\n\n<p>Press the <strong>Go <\/strong>button to login. A new page loads:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"615\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Open-phpMyAdmin-Logged-in-Page.png?resize=1024%2C615&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Open phpMyAdmin Logged in Page\" class=\"wp-image-89447\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Open-phpMyAdmin-Logged-in-Page.png?resize=1024%2C615&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Open-phpMyAdmin-Logged-in-Page.png?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Open-phpMyAdmin-Logged-in-Page.png?resize=768%2C461&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Open-phpMyAdmin-Logged-in-Page.png?w=1170&amp;quality=100&amp;strip=all&amp;ssl=1 1170w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>That&#8217;s it! Your Raspberry Pi board is prepared with a LAMP server: Apache2, MySQL, PHP. We&#8217;ve also decided to include phpMyAdmin in this installation for an easier database management through a web interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Optional Step (but recommended)<\/h2>\n\n\n\n<p>To manage your web pages, you should change the permissions for your <span class=\"rnthl rntliteral\">\/var\/www\/html\/<\/span> folder. To do this, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ ls -lh \/var\/www\/\npi@raspberrypi:~ $ sudo chown -R pi:www-data \/var\/www\/html\/\npi@raspberrypi:~ $ sudo chmod -R 770 \/var\/www\/html\/\npi@raspberrypi:~ $ ls -lh \/var\/www\/<\/code><\/pre>\n\n\n\n<p>After running these commands, you&#8217;ll see something as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"290\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-change-var-www-html-folder.png?resize=773%2C290&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry-Pi change var www html folder\" class=\"wp-image-89445\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-change-var-www-html-folder.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-change-var-www-html-folder.png?resize=300%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-change-var-www-html-folder.png?resize=768%2C288&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>We hope you found this guide useful! Your Raspberry Pi has a LAMP server with phpMyAdmin that allows you to build interesting IoT projects like these:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-raspberry-pi-lamp-server\/\">ESP32\/ESP8266 Publish Data to Raspberry Pi LAMP Server<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/visualize-esp32-esp8266-sensor-readings-from-anywhere\/\">Visualize Your Sensor Readings from Anywhere in the World (ESP32\/ESP8266 + MySQL + PHP)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">ESP32\/ESP8266 Insert Data into MySQL Database using PHP and Arduino IDE<\/a><\/li><\/ul>\n\n\n\n<p>Learn more about Home Automation with the Raspberry Pi: <strong><a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\">Build a Home Automation System for $100<\/a><\/strong><\/p>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to install a LAMP (Linux, Apache, MySQL, PHP) server on a Raspberry Pi. LAMP is a software bundle that is used for web development. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi: Install Apache + MySQL + PHP (LAMP Server)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/#more-89427\" aria-label=\"Read more about Raspberry Pi: Install Apache + MySQL + PHP (LAMP Server)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":89429,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[304,305,301,307],"tags":[],"class_list":["post-89427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-home-automation","category-0-other","category-0-raspberrypi","category-0-review"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-Linux-Apache2-MySQL-PHP-PHPMyAdmin-LAMP-Server.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=89427"}],"version-history":[{"count":1,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89427\/revisions"}],"predecessor-version":[{"id":106481,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89427\/revisions\/106481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/89429"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=89427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=89427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=89427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}