If you have reached this page then you most likely know about a LAMP stack.
LAMP stack is a group of basic applications that most websites running on a Linux server are served. LAMP stands for Linux, Apache, MySQL/ MariaDB and PHP.
With this article, let us learn how to install this LAMP stack on CentOS. This will help you run your website from any VPS.
Prerequisite – the latest version of CentOS!
Let us dive in!
INSTALLING APACHE WEB SERVER
All you need to install the Apache web server is to type in this command in the terminal :
dnf install httpd httpd-tools
Once this is done, let us move on to starting the Apache web server :
systemctl start httpd
Make sure you enable Apache to auto start at system boot time with this command :
systemctl enable httpd
Status check :
systemctl status httpd
If you notice Enabled in the output, then Apache is running and will auto-start at boot time.
To test if Apache is running steadily, create an index.html
file under the default document root with this below command :
echo "Welcome to this site!" > /var/www/html/index.html
Now, type 127.0.0.1 or localhost
in your browser address bar. You should be able to see the welcome message from before. This means Apache web server is running without any problem!
INSTALLING MySQL/MariaDB
To handle your website database you need to install MySQL or MariaDB. Since MariaDB is becoming more widely used, let use it for installation. MariaDB and MySQL are both similar in configuration.
To install MariaDB, type in the following command :
yum -y install mariadb-server
systemctl start mariadb
Let us now enable MariaDB to auto start when the server starts :
systemctl enable mariadb
Here are some important server locations to be remembered for MariaDB/ MySQL. These defaults can be changed to your preference.
MariaDB binary: /bin/mysql
MariaDB Configuration file: /etc/my.cnf
Database location: /var/lib/mysql
MariaDB logs: /var/log/mariadb/mariadb.log
Status check :
systemctl status mariadb
At this point we need to run the security script :
mysql_secure_installation
The output will ask you to enter your MariaDB root password. Since the root password isn’t set yet, press the Enter key. Then type y to set a new root password.
After this, press Enter for all the remaining questions. This is a basic step in database security.
Now, run the following command to enter the MariaDB root password and log in to the MariaDB shell :
mysql -u root -p
INSTALLING PHP
To install PHP and modules, type in this command :
dnf install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring -y
So, Apache by default uses PHP-FPM instead of mod_php on centos to run a PHP code. With the help of the above command, we have also installed PHP-FPM. All we need to do is start it.
systemctl start php-fpm
Remember to enable it to auto start at system boot time :
systemctl enable php-fpm
Status check :
systemctl status php-fpm
If the output shows enabled then PHP-FPM id up and running. Since PHP-FPM package installs a php.config file we need to restart Apache web server to run the PHP code :
systemctl restart httpd
We also need to run the following command so that SELinux can allow Apache to execute the PHP code via PHP-FPM :
setsebool -P httpd_execmem 1
AND CONCLUSION…
Give yourself a pat on the back because you have successfully installed the AMP of LAMP Stack!
We hope this article helped.
Do share your thoughts!
Share Your Comments & Feedback