Setting up a LAMP Stack on CentOS 7

Comments ยท 12 Views

Setting up a LAMP (Linux, Apache, MySQL, and PHP) stack on CentOS 7 allows you to host dynamic websites and web applications. In this blog post, we will walk through the process of setting up a LAMP stack on CentOS 7.

Setting up a LAMP (Linux, Apache, MySQL, and PHP) stack on CentOS 7 allows you to host dynamic websites and web applications. In this blog post, we will walk through the process of setting up a LAMP stack on CentOS 7.

Step 1: Update the System.

Before installing any new software, update the system to ensure you have the latest security patches and updates:-
# [sudo yum update]

Step 2: Install Apache.
Install the Apache web server using the following command:-
# [sudo yum install httpd]

After the installation is complete, start the Apache service and enable it to start automatically on boot:-
# [sudo systemctl start httpd]
# [sudo systemctl enable httpd]

 Step 3: Install MySQL (MariaDB).
Install the MariaDB database server, which is a fork of MySQL, using the following command:-
# [sudo yum install mariadb-server]

Start the MariaDB service and enable it to start automatically on boot:-
# [sudo systemctl start mariadb]
# [sudo systemctl enable mariadb]

Run the MySQL secure installation script to improve the security of your MySQL installation:-
# [sudo mysql_secure_installation]

 Step 4: Install PHP.
Install PHP and the PHP MySQL extension using the following command:-
# [sudo yum install php php-mysql]

 Step 5: Configure Apache to Use PHP.

Edit the Apache configuration file to enable PHP support. Open the file '/etc/httpd/conf/httpd.conf' and uncomment the following line (remove the '#' at the beginning of the line):-
# [#LoadModule php7_module modules/libphp7.so]

 Step 6: Test PHP.
Create a test PHP file in the web server's document root directory to test PHP. For example, create a file named 'info.php' in '/var/www/html/' with the following content:
# [<?php

phpinfo();

?>]
Access this file in a web browser by visiting http://your_server_ip/info.php. You should see a PHP info page displaying information about your PHP installation.

Step 7: Configure Firewall.
If the firewall is enabled on your system, allow HTTP and HTTPS traffic:-
# [sudo firewall-cmd --permanent --add-service=http]
# [sudo firewall-cmd --permanent --add-service=https]
# [sudo firewall-cmd --reload]

Step 8: Restart Apache.
After making any changes to the Apache configuration, restart the Apache service to apply the changes:-
# [sudo systemctl restart httpd]

Step 9: Test the LAMP Stack.
To test your LAMP stack, create a MySQL database, add a MySQL user, and deploy a PHP application that connects to the database. Access your PHP application in a web browser to see if it works correctly.

 

Congratulations! You have successfully set up a LAMP stack on CentOS 7.

Comments