The Apache web server is the most commonly used web server application in the world. Today we are going to show you how to setup Apache web server with PHP, MySQL database server in your Raspberry Pi.

Initial Setup:

1.Setup your SD card with Raspbian OS with this tutorial.
2.In order to control your Raspberry from your PC you can use SSH or VNC and to setup VNC server in your Raspberry Pi follow this tutorial. To Access SSH enter ssh pi@<IP> in the terminal or you can use Putty in Windows.


1.Enter the Raspberry Pi Terminal.

setup apache web server raspberry pi

Raspberry Pi via SSH

2.Install Apache using this command.

sudo apt-get install apache2

3.Install MySQL database server using the command. Enter the root password for the MySQL database while installing.

setup apache web server raspberry pi

Set MySQL root Password on Installation.

sudo apt-get install mysql-server

4.Install php5 using the command.

sudo apt-get install php5 php5-mysql

5.After installing the packages to start the Apache Web Server using the command

service apache2 start

Now you your web server will start working. Visit Raspberry Pi’s IP in your PC to check whether its working.

Change Directory:

The default web directory in Raspberry Pi is /var/www. Change the directory in the file /etc/apache2/sites-available/default

Check PHP:

1.Move to the directory /var/www
2.Then sudo nano index.php
3. Paste the contents in the file and save it.


4.Now open <IP>/index.php you will see the PHP configuration in your Raspberry Pi.

setup apache web server raspberry pi

[Also Read: Setup Nginx Web Server in Raspberry Pi with PHP, MySQL]

Enjoy 🙂
Any questions comment here.



Content Creator at learn2crack
Am an active blogger who loves programming, gaming, computer and internet tricks.
  • cybernet2u

    dude, you nailed it. apache is the most lightweight webserver. it’s the perfect choice for raspberry …

    • Srini Vasan

      hi cybernet2u, thanks for your feedback …keep visiting.

  • TroyBoy

    THank you!

    • Srini Vasan

      you are welcomed TroyBoy
      keep visiting

  • etienne35

    thanks for the tuto, but I do not manage to get it running. Being completely new to type of environment, it may be something trivial that I missed….

    I run the installation as explained, and when I open ‘/index.php’ in my browser I just get a blanck page, no error message!

    I do not clearly understood the default directory modification in the ‘/etc/apache2/sites-available/default’ file, I do not see any ‘default director’ in it… so I keep it as it is (it contains already /var/www for ‘DocumentRoot’). Could you please provide detailled content of the file?

    • The default directory is “/var/www” . You must create the index.php file in the “/var/www/” folder. If you want to change the directory modify the DocumentRoot.

  • TJ Lee

    Thank you for this tutorial. It helps a lot!
    However, it failed to make_sock when I tried to do “service apache2 start”, so you might want to change it to “sudo service apache2 start”.

    • Srini Vasan

      thanks for commenting.

  • Siddharth

    how to start mysql server and apache server at boot?