Steps to Install Linux, Apache, MySQL, PHP (LAMP) in CentOS
About LAMP:
A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.
Step 1 – Install Apache:
Apache is used to establish a connection between a server and the browsers of website visitors (Firefox, Google Chrome, Safari, etc.) while delivering files back and forth between them (client-server structure).
sudo yum install httpd
Once it installed, you can start apache on your VPS:
sudo systemctl start httpd.service
The last thing you will want to do is enable apache to start on boot. Use the following command to do so:
sudo systemctl enable httpd.service
Step 2 – Install MySQL (MariaDB):
Presently that we have our web server up and running, it is time to introduce MariaDB, a MySQL drop-in substitution. MariaDB could be a community-developed fork of the MySQL social database administration framework. Essentially, it’ll organize and give get to to databases where our location can store data.
sudo yum install mariadb-server mariadb
When the installation is complete, we need to start MariaDB with the following command:
sudo systemctl start mariadb
We want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:
sudo mysql_secure_installation
The last thing you will want to do is enable MariaDB to start on boot. Use the following command to do so:
sudo systemctl enable mariadb.service
Step 3 – Install PHP:
PHP (recursive acronym for PHP: Hypertext Preprocessor) could be a widely-used open source general-purpose scripting dialect that’s particularly suited for web improvement and can be implanted into HTML.
sudo yum install php php-mysql
We need to restart the Apache web server in order for it to work with PHP. You can do this by typing this:
sudo systemctl restart httpd.service
Install PHP Modules
To improve the usefulness of PHP, we will alternatively introduce a few extra modules.
PHP modules and libraries, you’ll be able sort this into your framework:
yum search php-
The results are all optional components that you can install. It will give you a short description for each:
To get more information about what each module does, you can either search the internet, or you can look at the long description in the package by typing:
yum info package_name
For example, to find out what the php-fpm module does, we could type this:
yum info php-fpm
If we decided that php-fpm is something that we need, we could type:
sudo yum install php-fpm
If you want to install more than one module, you can do that by listing each one, separated by a space, following the yum install command, like this:
sudo yum install package1 package2 ...
Step 4 – Test PHP Processing on your Web Server:
In order to test that our system is configured properly for PHP, we can create a very basic PHP script.
We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the “web root”.
sudo vi /var/www/html/info.php
Copy and paste Below Text:
<?php phpinfo(); ?>
When you are finished, save and close the file.
If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Check your Server’s Public IP Address:
If you do not know what your server’s public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's//.*$//'
The address you want to visit will be
http://your_server_IP_address/info.php
The page that you come to should look something like this: