Install Apache, PHP, MySQL, & phpMyAdmin in Ubuntu


Apache – Apache web server is the most widely utilized web server in the world and most of the world’s websites are served on Apache web servers. Apache development is run by the Apache Software Foundation, which is a community of software developers. Apache is released with an open-source software license. There are releases of Apache that can run on most operating systems including Unix, Linux, Windows and Apple to name a few. Most often Apache is run on Linux web servers. The website is hosted on an Apache webserver, using shared webhosting. Shared webhosting utilizes Apache’s ability to host multiple websites on one web server, called virtual hosts.

PHP – is a programming or scripting language that is typically installed on a web server, but it can also be installed on an end user computer system. It is one of the most popular scripting languages to install on web servers in order to create dynamic web content. It is called a server-side scripting language in that the PHP code is interpreted by the web server, and html content is generated, and sent to the user’s web browser. The PHP code is interpreted and executed by the PHP engine or interpreter which is often installed as a module in the web server. PHP is very useful for retrieving and sending data to and from relational databases like MySQL. PHP is freely distributed software and has available releases for most major operating systems. PHP is a competitor with other server-side programming languages, like Microsoft’s Active Server Pages (ASP) and Sun’s JavaServer Pages (JSP).

{loadposition adposition6}MySQL – MySQL is currently the most popular relational database management system (RDBMS) in the world. MySQL functions as a database server that allows users to connect to its stored databases. MySQL is open-source software released under the GNU public license (GPL). MySQL is used in conjunction with many popular web applications and content management systems like Joomla (this website), WordPress, and Drupal to name only a few.

PhpMyAdmin – is a graphical, browser-based management interface, for working with MySQL. PhpMyAdmin is an open-source project written in PHP. PhpMyAdmin can make managing MySQL databases more intuitive, and easier to learn.


Installation Steps

    1. Open a terminal (the commands in this lab should work with Ubuntu and Linux Mint)
    2. Type in the following command to update your software package repositories. You will be required to type in your password:
      sudo apt-get update

    3.  You will need a text editor later in this lab. Upgrade the vi command line text editor by entering the following command and pressing enter, or Y and enter, when prompted to proceed with the install:
      sudo apt-get install vim

    4. Type in the following command to install Apache web server, press enter when prompted:
      sudo apt-get install apache2

    5. To check to see if Apache is running open Firefox and type in the following web address:
      http://localhost   or,
      You should see the message, “It Works!” This is the Apache homepage, the index.html file and it means the server has installed correctly and is currently running.

    6. If you didn’t see “It Works!” try starting the server. The commands to start, stop, restart, and test status in Apache are:
      sudo systemctl start apache2
      sudo systemctl stop apache2
      sudo systemctl restart apache2
      sudo systemctl status apache2

      The deprecated older method using init.d is:
      sudo /etc/init.d/apache2 start
      sudo /etc/init.d/apache2 stop
      sudo /etc/init.d/apache2 restart
      sudo /etc/init.d/apache2 status

    7. Go to the Apache web directory (i.e. where you put your webpages and websites) and look for the index.html file. Type in the following commands:
      cd /var/www/
          In Mint 17 and 18 the directory is:
      cd /var/www/html

      You should see the index.html file listed in the directory
    8. Open the index.html file, edit it, and save it. Type in the following command to open index.html in the vi text editor:
      sudo vi index.html
      To edit the file press i to enter insert mode. Now you can edit and personalize it:

      <html><body><h1>Your Name’s Website</h1>
      <p>Hello everyone, this is my homepage!</p>
      <p>I will update this page soon.</p>

      To exit and save changes, press the esc key, then type :wq and press enter to save and quit.
    9. Refresh the web page in Firefox to see your changes. You now have an Apache web server running on your local computer and you know how to add/edit webpage content. Time to learn HTML and CSS… 🙂
    10. To install PHP5 and the Apache library/module for PHP type in the following command and press enter when prompted to accept:
      sudo apt-get install php libapache2-mod-php7.0


    1. Once PHP has been installed restart Apache. Type in the following command:
      sudo systemctl restart apache2
      sudo /etc/init.d/apache2 restart


    1. Now we need to test PHP by writing a PHP file and calling the phpinfo function. Type in the following command to create a php text file and open it in gedit:
      sudo touch /var/www/test.php
      sudo vi /var/www/test.php

      In Mint 17, 18 the command and directory is:
      sudo touch /var/www/html/test.php
             sudo vi /var/www/html/test.php

    2. To edit the test.php file in vi press i to enter insert mode, and type in the following line:

      <?php phpinfo(); ?>

      To exit and save changes, press the esc key, then type :wq and press enter to save and quit.

    3. Open your Firefox browser and put in the following web address:


    1. If PHP is working you should see a long page of information about the installed version of PHP and its configuration parameters.


    1. Now to install MySQL server. Type in the following command and press enter when prompted to accept:
      sudo apt-get install mysql-server

      During the installation you will be prompted to enter a password for MySQL root user, do so and hit the Tab key to highlight the <Ok> button and press enter.

      If you leave the password blank you can always enter it later by typing the following command:
      mysql -u root
      mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);


  1. Once you have MySQL installed you will want to install the phpMyAdmin tool as an easy interface to working with MySQL. Type in the following command:
    sudo apt-get install php7.0-mysql phpmyadmin
    During the installation you may need to choose Apache2 to be the database associated with MySQL and phpmyadmin. Make sure Apache2 is selected and tab, click enter
    During the installation you may need to choose ‘yes’ to have ‘dbconfig-common’ handle the database configuration for you. Choose yes and hit enter. You will be prompted twice for your MySQL root user password.
  2. Create a symbolic link from phpMyAdmin to the Apache www directory. Type in the following command:
    sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

    In Mint 17 and 18 the command and directory is:
    sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

  3. Now put the following web address in Firefox:
    You should see the phpMyAdmin login page, but if you get an error page instead, then restart the Apache webserver, and refresh the webpage in the web browser:
    sudo /etc/init.d/apache2 restart 
  4. Refresh http://localhost/phpmyadmin in your browser to get to the phpMyAdmin login page. Type in the user field as ‘root’ and the password you set during the installation process and log in. Cheers!

Video Tutorial

In this video I download, install, and run Apache web server in Ubuntu

In this video I install PHP to an Apache web server in Ubuntu

In this video I install MySQL and PhpMyAdmin to an Apache web server in Ubuntu


If you choose advanced configuration option you may need to configure php to work with MySQL by editing the php.ini file:

sudo gedit /etc/php5/apache2/php.ini
Uncomment the following line by removing the semicolon:
; (to)
Also people report missing the “y” like this:
; (to)

sudo /etc/init.d/apache2 restart


If you choose to have your MySQL server on a network you may need to edit the bind-address. To do that type the following commands to edit the my.cnf file:
      sudo gedit /etc/mysql/my.cnf
Change the following line to your ip address:
      bind-address =



Author: Dan

Dan teaches computer networking and security classes at Central Oregon Community College.

Leave a Reply

Your email address will not be published.