How to create a LAMP server for PHP development

In this post, I will show the steps I follow to create a LAMP (Linux, Apache, MySql & PHP) server for PHP development.

I tested in Ubuntu 18.04 LTS, Ubuntu 20.04 LTS & Ubuntu 22.04 LTS.

The steps are described below:

1. Installing Apache

Install Apache using the following command:

sudo add-apt-repository ppa:ondrej/apache2
sudo apt install apache2


1. Change “www” folder

change the permission of “www” folder:

sudo chmod 777 /var/www
sudo chmod 777 /var/www/*

Help Links


2. Installing MySql

Install MySQL from apt:

sudo apt install mysql-server

3. Installing PHP x.x

Install PHP using the following command:

sudo add-apt-repository ppa:ondrej/php
# Replace x.y with your preferred version number, e.g., 8.0 etc.
# You can also just use "php" to install the latest version of php.
sudo apt install phpx.y
# Additional Modules:
sudo apt install php-pear php-curl php-dev php-gd php-mbstring php-zip php-mysql php-xml

Help Links


4. Installing phpMyAdmin

Way One: Install Latest phpMyAdmin

Just run this script to install the latest version of phpMyAdmin. Just run the following command to download and run the script:

curl -sL | sudo bash -

The script will take care all for you.

Way Two: Install default repository version of phpMyAdmin

First install phpMyAdmin form apt:

sudo apt install phpmyadmin

NOTE: The installation will ask some question during installation:

  1. For the server selection, choose apache2 using <space>.
  2. Select yes when asked whether to use “dbconfig-common” to set up the database
  3. You will be prompted for your database administrator’s password, keep it blank and press Enter.
  4. Then restart the Apache server:
     > sudo systemctl restart apache2


1. “localhost/phpmyadmin” not found!

Open “/etc/apache2/apache2.conf” file in any text editor and add the below line at the end of the file:

Include /etc/phpmyadmin/apache.conf

2. Cannot use the user “root”!

#1698 – Access denied for user ‘root’@’localhost’

Just use the below commands to use “root” user:

sudo mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

 3. phpMyAdmin Autologin

Login without a password is forbidden by configuration (see AllowNoPassword)

If you have no password set for the root user, then you will see the upper message. To solve this and make auto login follow the below steps.

Open “/etc/phpmyadmin/” file in any text editor and add the following line below “/* Authentication type */“. If the file not found, then open “/usr/share/phpmyadmin/” file.

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';

Then un-comment or change to TRUE the following line (just remove “//” from the line if there any):

$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

Check and update all instances of this.

4 “no privileges” phpmyadmin create database

Just clear cookies of phpmyadmin.

5. “Warning in ./libraries/sql.lib.php#613
count(): Parameter must be an array or an object that implements Countable”

To solve this follow the steps:

1. Download latest version of phpMyAdmin from here.

2. Make a backup of the directory “/usr/share/phpmyadmin/“, which is the old version, and is for backup.

cd /usr/share/
sudo mv phpmyadmin phpmyadmin_backup
sudo mkdir phpmyadmin

3. Extract all files of the downloaded zip file to “/usr/share/phpmyadmin/” folder.

# Change "" with the file name you downloaded before.
mv phpMyAdmin-x.x.x.x-all-language phpmyadmin
sudo mv phpmyadmin /usr/share/

4. Open “libraries/vendor_config.php” file with any text editor:

sudo gedit /usr/share/phpmyadmin/libraries/vendor_config.php

and change below line:

define('CONFIG_DIR', '');


define('CONFIG_DIR', '/etc/phpmyadmin/');

5. Restart Apache server.

sudo service apache2 restart

6. “The $cfg[‘TempDir’] (./tmp/) is not accessible. phpMyAdmin is not able to cache templates and will be slow because of this.”

To solve this problem, create a “tmp” directory in “/usr/share/phpmyadmin/” folder and change its MODE to 777. Use the following command to do both (Terminal base directory must be “/usr/share/phpmyadmin/“):

mkdir tmp && chmod 777 tmp

7. Increase upload file limitation.

Update the “php.ini” file(s) and change following things:

General location of “php.ini”: (Replace x.y with installed PHP version.)

  • /etc/php/x.y/cli/php.ini
  • /etc/php/x.y/apache2/php.ini

Update following values:

# Here, 2G = 2GB
post_max_size = 2G
upload_max_filesize = 2G

Finally, restart the Apache server:

sudo service apache2 restart

8. phpMyAdmin database not initialized!

The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. Find out why. Or alternately go to ‘Operations’ tab of any database to set it up there.

To solve this just click the “Find out why” clickable link from the warning text. Then click “Create” from the warning text “Create a database named ‘phpmyadmin’ and setup the phpMyAdmin configuration storage there.“. That’s all.

Help Links


5. Installing Composer

Install Composer from here.

To use the composer globally use the following command:

mv composer.phar /usr/local/bin/composer

Help Links


3 thoughts on “How to create a LAMP server for PHP development

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.