How to configure LAMP stack in Ubuntu?By Team Editor - 2 years and 1 month ago / Feb 2018
LAMP stack is a group of tools installed on a server to enable hosting dynamic websites and web apps. LAMP stands for: Linux, Apache, MySQL, PHP. LAMP is an archetypal model of web service stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system (RDBMS), and the PHP programming language. The LAMP components are largely interchangeable and not limited to the original selection. As a solution stack, LAMP is suitable for building dynamic web sites and web applications.
So, we will break the LAMP as following and their setup as follows:
1. L = Linux, Our Base operating System. In this tutorial we will be setting up LAMP Server in our fresh Ubuntu.
2. A = Apache, Apache is the open source web server that is free to use as it is open source software. 67% of the total world’s web server are operated on Apache web server.
3. M = MySQL, MySQL is the open source relational database management. Now-a-days, Maria db are gaining more popularity.
4. P = Perl, PHP, Python. Well Perl seems to be having low popularity, generally PHP and Python are used as the scripting language.
In this tutorial we’ll look on how to install and configure the LAMP stack running Ubuntu. Before Starting any configuration always check for the available update and make sure your system is up to date. In ubuntu you can check for the update as follow:
$ sudo apt-get update//won’t provide you the available package update information
$ sudo apt update//will provide how many packages are available to update.
If there are updates, install all of them:
$ sudo apt-get upgrade//won’t display the progress bar in the bottom
$ sudo apt upgrade//will display the percentage bar in the bottom to show the actual progress!
Since, we are wanting to configure the LAMP server in the Ubuntu 17.04, our ‘L’ setup is already completed as we have Ubuntu 17.04 as GNU/Linux. So, we need to move further to configure the Apache server
Install Apache Install the Apache web server, which is available in the Ubuntu repositories:
$ sudo apt-get install apache2
apache2 version (2.4.25-3ubuntu2.2)
Start an Apache configuration test:
$ sudo apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe80::5054:ff:fe69:a3e0. Set the 'ServerName' directive globally to suppress this messag Syntax OK
There are no syntax errors, however the test returns a warning message saying that we didn’t set up a FQDN (fully qualified domain name). This warning message is harmless, but it will show up when checking your Apache configuration for syntax errors.
Edit the Apache main configuration:
$ sudo $EDITOR /etc/apache2/apache2.conf
//replace $Editor by your preferred for ex. NANO, gedit, emacs, vim etc.
At the end of this file, add directive, pointing to server domain or IP. For the purpose of this tutorial we’ll write
ServerName 192.168.111.111 //any IP you would like to setup
Save, close the file and check for syntax errors in configuration:
$ sudo apache2ctl configtest
Now, the result will be:
$ sudo systemctl restart apache2
Open a web browser and go to your server URL. If you see the following page, Apache is correctly running:
Install MySQL At this point, you also have a web server up and running. Next step is to install the database management system, MySQL.
MySQL is available in Ubuntu repositories, so use apt
$ sudo apt-get install mysql-server
[We can also use Mariadb as database. However this is little too complicated. We will leave that for now.] During the installation, you will be asked for the root account password.
At the end of this process, we’ll change some default configurations, running the following script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 $ mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y/Y for Yes, any other key for No: N Using existing password for root. Change the password for root ? ((Press y/Y for Yes, any other key for No) : ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y/Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y/Y for Yes, any other key for No) : y Dropping test database... Success. Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y/Y for Yes, any other key for No) : y Success. All done! The database system is now set up!
Install PHP The next part of the LAMP stack is a PHP environment. This is the part that will process the code to display dynamic content. Install PHP using apt:
$ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Test PHP To test PHP, create a new basic file named info.php in the Apache web root, which, for Ubuntu, is /var/www/html:
$ sudo $EDITOR /var/www/html/info.php
In this file, paste the following code:
Save and close this. Next, with a web browser, go to: http://your_domain_or_ip/info.php. If everything is working well, it should display the following page
Conclusion: This marks the complete installation of LAMP in ubuntu 17.04.