Home / Networking / Setup Apache Web Server With PHP MySQL On Raspberry Pi.

Setup Apache Web Server With PHP MySQL On Raspberry Pi.

Learn how to setup Apache web server on Raspberry Pi /2/3/B . And then access it from anywhere within your network and Internet.


Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.

On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Step 1.) Install Apache2. by typing the following command in Command Line.

sudo apt-get install apache2 -y

Now, Once installation is completed. Type in the IP Address of your Pi to Test the Server. If you get this page. Means , You have successfully installed and setup your server.

apache-it-works_otqp3r Setup Apache Web Server With PHP MySQL On Raspberry Pi.

2.) Change the Web Page.

Now in order to change this default page and add your own html file , goto var/www/html , 

cd /var/www/html 

Now add your own HTML File by typing ,

sudo nano myfile.html

Try editing this file and refreshing the browser to see the web page change. Press Ctrl + X and hit Enter to save and exit.




PHP is a preprocessor; it’s code that runs when the server receives a request for a web page. It runs, works out what needs to be shown on the page, then sends that page to the browser. Unlike static HTML, PHP can show different content under different circumstances. Other languages are capable of this, but since WordPress is written in PHP, that’s what we need to use this time. PHP is a very popular language on the web; large projects like Facebook and Wikipedia are written in PHP.

Install the PHP and Apache packages with the following command:

sudo apt-get install php5 libapache2-mod-php5 -y


Create the file index.php:

sudo nano index.php

Put some PHP content in it:

<?php echo "hello world"; ?>

Now save the file. Next delete index.html because it takes precendence over index.php:

sudo rm index.html 

Refresh your browser. You should see “hello world”. This is not dynamic but it is still served by PHP. If you see the raw PHP above instead of “hello world”, reload and restart Apache like so:

sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart

Otherwise try something dynamic, for example:

<?php echo date('Y-m-d H:i:s'); ?>

Well, Thats all . Now your website should be running. Refer here for port forwarding tutorial 
Dont forget to like and share. !  

About Abdul Hannan Mustajab

Well hello there! Not wanting to keep myself obscure,here's something about me. WHO AM I? Im a young 17 year old,based in India. Currently pursuing education in the science - math stream , im an Computer Science aspirator. WHAT DO I LIKE? A simple statement says it all, computers & tech. WHAT DO I KNOW? I have a passion for programming and have learned the following programming languages so far - C,python,PHP & angular js. Also do I possess knowledge regarding web servers and linux and shell related stuff. WHAT ARE MY INTERESTS? Im interested in Raspberry pi & Arduino associated home automation and well that's what my website is about!

Check Also

Setup Instagram AutoLiker Bot On Raspberry Pi

  Do you have a instagram account and you wish to have thousands of followers …