In this tutorial, we will see how to prepare ubuntu for PHP development.

(1) Install apache2 package

main@work:~# sudo apt install apache2

(2) Install mysql-server package

main@work:~# sudo apt install mysql-server

You will be asked to set a password for mysql user root - the mysql administrator.

mysql-server package configuration – Set password of root user

(3) Install php package and libapache2-mod-php package (apache2 module for php).

main@work:~# sudo apt install php libapache2-mod-php

(4) Install php extensions packages: php-mysql , php-dom , php-zip

main@work:~# sudo apt install php-mysql php-dom php-zip

(5) Since Composer is the defacto dependency management tool for PHP and have gain popularity with PHP developers, we will install it.

main@work:~# sudo apt install composer

(6) While we can use mysql command line client or mysql workbench visual tool for database administration, I prefer to use phpMyAdmin web application for this task.

main@work:~# sudo apt install phpmyadmin
  • Select apache2 as the http server to configure.

phpmyadmin package configuration – Select the HTTP server

  • Select auto configure the web application via dbconfig-common

phpmyadmin package configurtion - Use automatic configurtion

  • Enter the root password you entered above

phpmyadmin package configurtion - mysql `root` password

Now, open /etc/phpmyadmin/apache.conf with you favorite editor:

main@work:~# sudo nano /etc/phpmyadmin/apache.conf

Comment the lines with ## and add the lines at the end of the file:

## Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    ##<IfModule mod_php.c>
    ##    <IfModule mod_mime.c>
    ##        AddType application/x-httpd-php .php
    ##    </IfModule>
    ##    <FilesMatch ".+\.php$">
    ##        SetHandler application/x-httpd-php
    ##    </FilesMatch>
          php_flag magic_quotes_gpc Off
          php_flag track_vars On
<Directory /usr/share/phpmyadmin/setup/lib>
Require all denied
Listen 8080
<VirtualHost *:8080>
    TransferLog  "/var/log/apache2/phpmyadmin_access.log"
    ErrorLog     "/var/log/apache2/phpmyadmin_errors.log"
    DocumentRoot "/usr/share/phpmyadmin"

Now we can manage our mysql server at http://work:8080

Now , we can start develop our site in PHP.

Your document root is under /var/www/html.

Let’s check whether we successfully configure apache. Open /var/www/html/main.php in favorite editor and enter the following content:


Now, access http://work/main.php in your webbrowser. You should see the familiar page:

phpinfo() output