This brief tutorial shows students and new users how to install LAMP + phpMyAdmin on Ubuntu 16.04 | 18.04 | 18.10 servers….
LAMP is an acronym for Linux (Ubuntu), Apache2 HTTP Server, MariaDB or MySQL Database Server and PHP Scripting Language… It is a group of open source software and building blocks of many of the web applications and majority of the content management systems (CMS) in use today…
phpMyAdmin is a web-based tool that allows you to interact with MariaDB databases, manage user accounts and privileges, execute SQL-statements, import and export data and much, much more.
If you’re going to be developing any PHP based applications or websites, then you’re probably going to be using the LAMP and phpMyAdmin allows you to easily manage your databases from your favorites web browsers…
This brief tutorial is going to show students and new users how to install Apache2, MariaDB, PHP with phpMyAdmin support on Ubuntu Linux 16.04 | 18.04 and 18.10 servers…
To get started with installing the LAMP Stack, follow the steps below:
Step 1: Prepare Ubuntu Linux
The LAMP stack includes the Linux machine… in this case, Ubuntu… To get LAMP you must first install a Linux machine… this post assumes you’ve already install Ubuntu server..
After installing Ubuntu server, run the commands below to update the server…
sudo apt update && sudo apt dist-upgrade && sudo apt autoremove
Step 2: Install Apache2 HTTP Server
Apache2 HTTP Server represents the E in the LAMP stack… It’s the probably the second most popular web server installed today… not far behind the most popular web server, Apache2…
To install Apache2 HTTP on Ubuntu server, run the commands below…
sudo apt update sudo apt install apache2
After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.
sudo systemctl stop apache2.service sudo systemctl start apache2.service sudo systemctl enable apache2.service
To test Apache2 setup, open your browser and browse to the server hostname or IP address and you should see Apache2 default test page as shown below.. When you see that, then Nginx is working as expected..
ex.. http://localhost
Step 3: Install MariaDB Database Server
MariaDB stands for M in LAMP and it’s a great place to start when looking at open source database server… Although MySQL was originally the default database server among Linux systems, MariaDB has taken over.. To install it run the commands below.
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB database server, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots..
On Ubuntu 16.04 LTS
sudo systemctl stop mysql.service sudo systemctl start mysql.service sudo systemctl enable mysql.service
On Ubuntu 18.04 LTS and 18.10
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Restart MariaDB server
To test if MariaDB is installed, type the commands below to logon to MariaDB server
sudo mysql -u root -p
Then type the password you created above to sign on… if successful, you should see MariaDB welcome message
Step 4: Install PHP 7.2-FPM and Related Modules
The last component of the LAMP stack is PHP-FPM… It’s the P in the LAMP stack…
PHP 7.2-FPM may not be available in Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.
Run the commands below to add the below third-party repository to upgrade to PHP 7.2-FPM
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
Then update and upgrade to PHP 7.2-FPM
sudo apt update
Then run the commands below to install PHP 7.2-FPM and related modules…
sudo apt install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl
After installing PHP, run the commands below to find the version installed on the server…
php -v
You should see an output like the one below:
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
The version number determines the location of PHP default configuration file… For PHP 7.2, the location is as shown below:
sudo nano /etc/php/7.2/apache2/php.ini
Replace the version number above with the version of PHP installed..,..
When the file opens, make the changes on the following lines below in the file and save. The value below is great settings to apply in your environments.
file_uploads = On allow_url_fopen = On memory_limit = 256M upload_max_filesize = 100M max_execution_time = 360 date.timezone = America/Chicago
After making the change above, save the file and close out.
Step 5: Install phpMyAdmin
Now that LAMP is in place, run the commands below to install phpMyAdmin…
sudo apt install phpmyadmin
When prompted to choose the web server, don’t select apache2…
+------------------------+ Configuring phpmyadmin +-------------------------+ | Please choose the web server that should be automatically configured to | | run phpMyAdmin. | | | | Web server to reconfigure automatically: | | | | [x] apache2 | | [ ] lighttpd | | | | | | <ok> | | | +---------------------------------------------------------------------------+
When prompted again to allow debconfig-common to install a database and configure select Yes.
+------------------------+ Configuring phpmyadmin +-------------------------+ | | | The phpmyadmin package must have a database installed and configured | | before it can be used. This can be optionally handled with | | dbconfig-common. | | | | If you are an advanced database administrator and know that you want to | | perform this configuration manually, or if your database has already | | been installed and configured, you should refuse this option. Details | | on what needs to be done should most likely be provided in | | /usr/share/doc/phpmyadmin. | | | | Otherwise, you should probably choose this option. | | | | Configure database for phpmyadmin with dbconfig-common? | | | | <Yes> <No> | | | +---------------------------------------------------------------------------+
You will be prompted to create a password for phpMyAdmin to register with the database… Please provide a password for phpmyadmin to register with the database… After that, phpMyAdmin should be installed and ready to use..
Step 6: Connecting to phpMyAdmin
Now open your browser and browse to the hostname followed by phpmyadmin
http://example.com/phpmyadmin
When you attempt to logon using MariaDB root account it will fail… That’s because MariaDB and MySQL have switch their authentication method to auth_socket
The auth_socket plugin authenticates users that connect from the localhost through the Unix socket file… which prevents users from connecting with password… So, you won’t be able to connecto via phpMyAdmin…
When you attempt to logon, you see the error “#1698 – Access denied for user ‘root’@’localhost’”
To fix that, run the commands below:
sudo mysql -u root
That should get you into the database server. After that, run the commands below to disable plugin authentication for the root user
use mysql; update user set plugin='' where User='root'; flush privileges; exit
Restart and run the commands below to set a new password.
sudo systemctl restart mariadb.service
Now try again to logon… this time it should work!
Congratulations! You’re successfully installed the LAMP Stack with phpMyadmin on Ubuntu 16.04 | 18.04 | 18.10…