Installing Composer and LAMP (Linux, Apache, MySQL, PHP) for PHP Development



Composer is a popular dependency management tool for PHP, created mainly to facilitate installation and updates for project dependencies. It will check which other packages a specific project depends on and install them for you, using the appropriate versions according to the project requirements.


Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation, Apache is an open source software available for free. It runs on 67% of all web-servers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. However, WordPress can run on other web server software as well


MySQL is a freely available open source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). SQL is the most popular language for adding, accessing and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use. MySQL is an essential part of almost every open source PHP application. Good examples for PHP & MySQL-based scripts are WordPress, Joomla, Magento and Drupal.


PHP is a server side scripting language that is used to develop Static websites or Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier stood for Personal Home Pages. PHP scripts can only be interpreted on a server that has PHP installed. The client computers accessing the PHP scripts require a web browser only. A PHP file contains PHP tags and ends with the extension “.php”.


Before doing any installation, update the package manager cache by running on the terminal:

sudo apt-get update

When this is done, install composer by running the below command:

Next, let’s install the dependencies. We’ll need curl in order to download Composer and php5-cli for installing and running it. git is used by Composer for downloading project dependencies. Everything can be installed with the following command:

sudo apt-get install curl php5-cli git

After these steps, Composer installation is really simple and can be done with a single command:

curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

This will download and install Composer as a system-wide command named composer, under /usr/local/bin. The output should look like this:

To test your installation, run:


  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version 1.0-dev (9859859f1082d94e546aa75746867df127aa0d9e) 2015-08-17 14:57:00

 command [options] [arguments]

 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --profile             Display timing and memory usage information
 --working-dir (-d)    If specified, use the given directory as working directory

If you see this, your are set with composer.

Next, we will install Apache. This install is a single command and will put the root of the Apache web server at /var/www/html/ on the local machine.

sudo apt-get install apache2

The installer will start the service automatically, and you can test to make sure it’s working by opening up a browser and typing http://localhost or on the local machine.

Next, we’ll install PHP 7.2. We’ll also install some libraries, which will allow everything to play nice when we’re finished.

sudo apt-get install php7.2
sudo apt-get install libapache2-mod-php7.2

We’ll then need to restart the Apache service to ensure PHP functions properly.

sudo /etc/init.d/apache2 restart

Linux Mint comes with the xed GUI text editor, which we can use to create a test PHP file.

sudo xed /var/www/html/test.php

You’ll want to populate the file with the following code:

<?php phpinfo(); ?>

Point a browser at http://localhost/test.php to test the code and make sure PHP is working properly. If it is, you should see a bunch of information about the version of PHP that we just installed.

Next, we’ll install MySQL.

sudo apt-get install mysql-server

After the install is complete you’ll want to do a couple things. The first is to set a password for root in MySQL.

sudo mysql -u root

This will dump you in to the MySQL command line, where you can set a password for root.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret');

Next you’ll want to create a user that can be used to log in to PHPMyAdmin. For whatever reason, after I installed PHPMyAdmin, it would not let me log in as root. It did create an initial user called phpmyadmin, but that account only had read access to everything. To be safe we’ll create a new account called admin from within the MySQL command line.

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'secretpassword';

You’ll obviously want to replace secretpassword with something secure.

Now we’re ready to install the libraries to tie everything together, as well as PHPMyAdmin itself.

apt-get install libapache2-mod-log-sql-mysql
apt-get install php7.0-mysql
apt-get install phpmyadmin

When the installer asks if you want it to create a blank database, tell it Yes. When prompted for a password, set it to the same thing as you set the SQL admin account password you created above.

Next we’ll need to make a small change to a PHP configuration file.

sudo xed /etc/php/7.2/apache2/php.ini

Uncomment (remove the # from the beginning) the line extension=mysqli, save and close the configuration file. Next we’ll need to restart Apache again to ensure everything works.

sudo /etc/init.d/apache2 restart

Next, fire up a browser and point it to http://localhost/phpmyadmin. You should be able to log in with the admin account that you created in MySQL, using your super secret password.

In case you get a 404 ERROR, You will need to configure apache2.conf to work with Phpmyadmin.

sudo gedit /etc/apache2/apache2.conf

Include the following line at the bottom of the file, save and quit.

Include /etc/phpmyadmin/apache.conf

Restart Apache by running: sudo /etc/init.d/apache2 restart

Fixing a Bug in PHPMyAdmin

I found a bug in PHPMyAdmin that results in on screen errors when clicking the name of a table in order to list its contents. Hopefully this bug will be updated soon, but it can be traced back to some incorrect syntax in a configuration file. If you experience this bug, this should hopefully fix it. Remember to keep copies of any config files you modify just in case something goes belly-up.

sudo xed /usr/share/phpmyadmin/libraries/sql.lib.php

Find the line that contains the following text:

(count($analyzed_sql_results['select_expr'] == 1)

You’ll want to edit this line so that it matches the following line:

((count($analyzed_sql_results['select_expr']) == 1)

Essentially, you’ll be adding a ‘(‘ before the existing one, and placing a ‘)’ after the close bracket before ” == 1″.

No further steps need to be taken after that code change. After the modification, I stopped getting error when clicking on the table names in PHPMyAdmin instantly.


If you enjoyed this article and would like to see more, please feel free to share this article on social media, comment below letting me know what else you’d like to see. See my youtube channel by clicking HERE, Subscribe and invite your friends.

Related posts