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.

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 7.2

Install PHP 7.2 using the following command:

sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.2
# Additional Modules:
sudo apt install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-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.
  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”!

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

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:

    sudo mv phpmyadmin phpmyadmin_backup
    sudo mkdir phpmyadmin
  3. Extract all files of the downloaded zip file to “/usr/share/phpmyadmin/” folder.
  4. Open “libraries/vendor_config.php” file with any text editor 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

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

4. Installing Composer

Follow the below command to install composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

To use the composer globally use the following command:

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

Help Links

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

One thought 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.