LAMP Stack - Linux, Apache, MySQL, PHP

Learning how to install a LAMP stack on a Linux server is very helpful to understand the backend of Linux based servers, as well as understanding the basics of what makes a web server function to deliver web content to the world. The first set of instructions goes over how to install apache, MySQL, and PHP on a 'yum install' based system (so CentOS, Red Hat, Fedora, etc), and the second set of instructions go over how to install apache, MySQL, and PHP on a 'apt-get' based system. (so Debian, Ubuntu, etc.)


Installing Apache with 'yum'

On most servers, linux will be installed by default. Assuming you already have linux installed, apache will be the next step to get installed on to a server. Type out the following below commands to get apache installed using yum on a CentOS 7 based machine. Make sure you are either using 'root' or a user that has sudo permissions. Let's first set up Apache:


This show tux installing the package 'httpd' on to the server, which is a package name for Apache. When the server prompts you to say yes or no for installing, make sure to put 'Y' for yes.



This is going to start Apache, that way it is running on the server. Plug in the IP address of your server in a URL bar, and if you see the below image, you know you installed Apache correctly.



Next, let's go ahead and enable the httpd service to start on boot, that way you don't have to restart Apache every single time you are inside the server.


Installing MySQL with yum

MySQL is going to be the database functionaility on a server. This will allow databases to be hosted on the server. Follow the steps below to get it installed, and make sure you are in root or a user with sudo permissions.


This shows how to install the maria-db package, which is a MySQL drop in replacement. This will automatically install a database functionaility to work with on the server. Next, we will make sure that it is started.




This shows how to install the maria-db package, which is a MySQL drop in replacement. This will automatically install a database functionaility to work with on the server. Next, we will make sure that it is enabled by default every time the server is booted up.



This enables the mariadb service to be booted up by default everytime the server is booted up.



Last, with MySQL, the package needs to be secured, to avoid any corruption issues. Type out the above command, and it will prompt you for a MySQL password. Since this is just now being set up, there will not be a password yet. Leave it blank and press enter. It will then ask you if you would like to create one, so press 'Y' for yes, and create a password.


Installing PHP with yum

On websites, dynamic content is processed and visible to the end user via PHP. PHP is important to install on to your server as a baseline to work with. Make sure you have sudo or root permissions to accomplish this install.


This above command installs PHP, as well as the PHP-MySQL package. Next, we have to restart the PHP service to get the server to recognize PHP has been installed.



This above command restarts PHP. And, bam! Just like that, you have installed a LAMP stack. You can begin to start using Linux, Apache, MySQL, and PHP now. Good luck!