If you’ve been hearing a lot about the LAMP stack lately, that’s because some of the world’s most popular open source apps (including WordPress) run on LAMP. The LAMP stack (usually hosted on a VPS server) is widely considered to be the best platform for developing new custom web apps, and it’s so ubiquitous that you’re bound to run into it eventually.
Here’s everything you need to know about LAMP.
What is a LAMP stack?
LAMP is a software stack designed to host web content like websites and apps.
It’s called the LAMP stack because of its four components (Linux, Apache, MySQL and PHP) and because each piece of software builds on the other – like a stack.
Introducing the LAMP stack
- Linux: This is your operating system, which is the base layer. It is a free, open source operating system that’s been around since the mid-90s. Linux is more flexible and has more configuration options than most other operating systems, so it makes a great base layer for your software stack.
- Apache: At the second layer of the stack, we have the Apache web server. It uses HTTP to process requests. Apache is open source and its many features make it the go-to server for many websites.
- MySQL database: MySQL is an open source database system that stores application data in a format that can easily be queried using the SQL language. MySQL is versatile enough to run any website, no matter how complex.
- PHP scripting language: The PHP scripting language sits on top of the stack, controlling things like user experience and the way your website looks to your visitors.
NOTE: Some developers replace MySQL with MariaDB and PHP with Perl, Python, or some other programming language. But MySQL and PHP are still considered part of the original LAMP dream team.
How the LAMP stack works together
Everything starts when a user’s browser sends a request to the Apache web server. If the request is for a PHP file, Apache sends the request to PHP, which loads the file and executes the code in it. PHP then communicates with MySQL to retrieve any data referenced in the code. PHP then uses the code in the file and the data in the MySQL database to create the HTML that the browser needs to load the web page. And, of course, everything is fueled by the Linux Operating System at the base of the stack.
3 Reasons Why LAMP Stack Rules
1. It’s efficient
Because it’s open source, the LAMP stack helps reduce development time. The wide availability of resources means you rarely have to start from scratch. You can just build on what other people have done.
2. It’s flexible
Classic LAMP uses Linux as the OS, MySQL as the database and PHP as the scripting language, but you can always change any of the components to suit your needs.
3. Apache is highly customizable
Apache has a modular design, and you can find lots of modules for many different extensions, including authentication capabilities.
How to install a LAMP stack
To begin, you will need:
Installing a LAMP stack on Ubuntu 16.04/Ubuntu 18.04
- Run tasksel from the command line by typing $ sudo tasksel
- Tick LAMP server
- On your keyboard, press Tab, followed by Enter
- Enter your for MySQL
The installation will be complete in a few minutes.
Installing a LAMP stack on CentOS 6 or CentOS 7
NOTE: If you’re using CentOS 6 or CentOS 7, you’ll need to install each LAMP element separately, since they aren’t grouped like they are in Ubuntu.
This can be a little overwhelming, so just do it in sections:
- Update your system
- Adjust your firewall
- Install Apache
- Install MySQL
- How to add PHP
- Restart Apache
1. Update your system
Update your system using this yum command:
$ sudo yum update && sudo yum upgrade
2. Adjust your firewall
If the firewall is running, open port number 80 using firewall-cmd. (This lets web traffic pass through the firewall.)
3. Steps to Install Apache
If you’re using CentOS 7, enter the following two commands:
$ sudo firewall-cmd --zone=public --permanent --add-service=http $ sudo firewall-cmd --reload
To install Apache, enter the following command in the terminal:
$ sudo yum install httpd
If you’re using CentOS 6, enter these commands to enable Apache to start automatically during system boot:
$ sudo chkconfig httpd on $ sudo service httpd start
If you’re using CentOS 7, enter these commands to enable Apache to start automatically during system boot:
$ sudo systemctl enable httpd.service $ sudo systemctl start httpd.service
4. Install MySQL
In CentOS 6, enter the following commands to install MySQL:
$ sudo yum install mysql-server $ sudo service mysqld start $ sudo mysql_secure_installation $ sudo chkconfig mysqld on
In CentOS 7, enter the following commands to install MySQL:
$ sudo yum install mysql-server $ sudo systemctl start mysql $ sudo mysql_secure_installation $ sudo systemctl enable mysql
5. How to add PHP
In CentOS 6, enter the following commands to install PHP:
$ sudo yum install epel-release yum-utils $ sudo yum install http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
In CentOS 7, enter the following commands to install PHP:
$ sudo yum install epel-release yum-utils $ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Enable the remi repository by entering the following command (This works for both CentOS 6 and CentOS 7):
$ sudo yum-config-manager --enable remi-php72 $ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql
6. Restart Apache
In CentOS 6, to apply the new settings, restart Apache by typing the following command:
$ sudo service httpd restart In CentOS 7, to apply the new settings restart Apache by typing the following command: $ sudo systemctl restart httpd.service
How to test your LAMP stack
- Create a phpinfo file in Apache’s root directory (/var/www/html) by typing the following:
$ cd /var/www/html $ sudo echo "<?php echo phpinfo();?>" > info.php
- Point a web browser to http://enter your IP address here/info.php. (Enter your IP address where it says “enter your IP address here”. Don’t type “enter your IP address here”.) When the webpage loads, you’ll know you’ve successfully installed your LAMP stack, and now you can use it to host websites!