How to create a LAMP server for PHP development

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

I used Ubuntu 18.04 LTS (Update: Tested in Ubuntu 20.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

Debug

1. Change “www” folder

change the permission of “www” folder:

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

Help Links

  1. https://launchpad.net/~ondrej/+archive/ubuntu/apache2

2. Installing MySql 5.7

Install MySQL from apt:

sudo apt install mysql-server

3. Installing PHP x.x

Install PHP 7.2 using the following command:

sudo add-apt-repository ppa:ondrej/php
# Replace x.y with your preferred version number, e.g., 7.4 etc.
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

  1. https://launchpad.net/~ondrej/+archive/ubuntu/php
  2. https://thishosting.rocks/install-php-on-ubuntu/

4. Installing phpMyAdmin 4.8.0.1

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

Debug

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/config.inc.php” file in any text editor and add the following line below “/* Authentication type */“:

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

Then un-comment the following line (just remove “//” from the line):

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

There are two instances of this, un-comment both.

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.
Command:

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.
Command:

# Change "phpMyAdmin-x.x.x.x-all-languages.zip" with the file name you downloaded before.
unzip phpMyAdmin-x.x.x.x-all-languages.zip
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', '');

to:

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

5. Restart Apache server.
Command:

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

Help Links

  1. https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-16-04
  2. https://askubuntu.com/questions/668734/the-requested-url-phpmyadmin-was-not-found-on-this-server
  3. https://stackoverflow.com/questions/5687970/auto-login-phpmyadmin
  4. https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04
  5. https://askubuntu.com/questions/763336/cannot-enter-phpmyadmin-as-root-mysql-5-7/763359#763359
  6. https://stackoverflow.com/questions/48001569/phpmyadmin-count-parameter-must-be-an-array-or-an-object-that-implements-co
  7. https://github.com/phpmyadmin/phpmyadmin/issues/14172#issuecomment-380006777

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

  1. https://getcomposer.org/download/

2 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:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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.