How to Install and Configure Linux, Apache, MySQL, PHP(LAMP) in Ubuntu - Cloud Network

Networking | Support | Tricks | Troubleshoot | Tips

Buymecoffe

Buy Me A Coffee

Thursday, October 24, 2019

How to Install and Configure Linux, Apache, MySQL, PHP(LAMP) in Ubuntu

LAMP Server Installation Steps


LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters of Linux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python. This tutorial describes how to install LAMP stack on Ubuntu 19.04, and previous versions such as Ubuntu 18.04 etc.

Install Apache:
Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI, SSL and virtual domains.

sudo apt-get install apache2

To Verify Apache Installed or Not
Open your web browser and navigate to http://localhost/ or http://server-ip-address/.

Install MySQL:
MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases, though SQLite probably has more total embedded deployments.


MySQL :-
sudo apt-get install mysql-server mysql-client

During installation, you’ll be asked to setup the MySQL “root” user password. Enter the password and click Ok.

Re-enter the password.

To Verify MySQL Installed or Not
sudo systemctl status mysql

Install MariaDB
In case you want to use MariaDB instead of MySQL community edition, follow the steps given below.

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.

First you have to remove existing MySQL packages if any. To completely uninstall MySQL along with its configuration files, enter the following commands one by one:

sudo systemctl stop mysql
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql/
sudo rm -rf /etc/mysql/


After removing MySQL, run the following command to install MariaDB.
sudo apt-get install mariadb-server

Alternatively Method :
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/10.0/ubuntu utopic main'

Update the software sources list and install MariaDB using following commands:
sudo apt-get update
sudo apt-get install mariadb-server
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/10.0/ubuntu utopic main'

Update the software sources list and install MariaDB using following commands:
sudo apt-get update
sudo apt-get install mariadb-server

During installation you will be asked to set mysql ‘root’ user password. Enter the password twice, and complete the installation.

Note: In Ubuntu 18.04, MariaDB won’t ask you to set root user password during installation.

Also, you can’t set password using command:
mysql_secure_installation

It will throw the following error.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'


To fix this error, log in to mysql prompt without password as root user:
sudo mysql -u root

Then, run the following commands one by one in the mysql prompt:
use mysql;
update user set plugin='' where User='root';
flush privileges;
\q
That’s it. Now, set database administrative “root” user password using command. Press Enter and go with the default settings.
mysql_secure_installation

To Verify mariadb Installed or Not
sudo service mysql status

PHP:
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

sudo apt-get install php5 libapache2.mod.php5 
                             or
sudo apt-get install php5 php5-mysql libapache2-mod-php5

To Create a Sample testphp.php in Apache document root folder.
sudo nano /var/www/html/testphp.php

mkdir /var/www

sudo gedit /var/www/testphp.php

<?php phpinfo(); ?>
OR
<?php
phpinfo();
?>


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

To Verify MySQL Installed or Not
http://localhost/testphp.php

PHPMyAdmin: (Optional)
sudo apt-get install libapache2-mod-auth-mysql phpmyadmin
sudo gedit /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

sudo /etc/init.d/apache2 restart

To Verify MySQL Installed or Not
http://localhost/phpmyadmin