Introduction
A LAMP stack, which stands for Linux, Apache, MySQL, and PHP, is a popular web hosting environment for running dynamic websites and web applications. CentOS, a robust and stable Linux distribution, is an excellent choice for hosting a LAMP stack. In this tutorial, we will guide you through the step-by-step process of setting up a LAMP stack on CentOS for web hosting.
Step 1:Update Your System
Before we begin, it’s essential to ensure your CentOS server is up-to-date. Open a terminal and run the following commands:
sudo yum update
This command will update the package repository and install any available updates.
Step 2: Install Apache Web Server
Apache is a widely used web server that serves web pages to visitors. To install Apache, run:
sudo yum install httpd
Once the installation is complete, start Apache and enable it to start at boot.
sudo systemctl start httpd
sudo systemctl enable httpd
You can verify Apache’s status with:
sudo systemctl status httpd
Step 3: Install MySQL Database Server
MySQL is a popular relational database management system. To install MySQL, run:
sudo yum install mariadb-server
Start MySQL and enable it to start at boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Run the MySQL secure installation script to set a root password and secure your MySQL installation:
sudo mysql_secure_installation
Step 4: Install PHP
PHP is a server-side scripting language that is essential for dynamic web applications. Install PHP along with common modules:
sudo yum install php php-mysql
Step 5: Create a PHP Info Page
To test if PHP is working correctly, create a PHP info page. Create a file named info.php
in the Apache webroot directory:
sudo nano /var/www/html/info.php
Add the following content to the info.php
file:
phpinfo();
Save the file and exit the text editor.
Step 6: Configure Firewall
If you have a firewall enabled on your server, you need to allow HTTP (port 80) and HTTPS (port 443) traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 7: Test Your LAMP Stack
Open a web browser and enter your server’s IP address or domain name. If you created the PHP info page (step 5), you can access it by navigating to http://your_server_ip/info.php
. You should see a page displaying PHP information. This confirms that your LAMP stack is working correctly.
Conclusion
You’ve successfully set up a LAMP stack on CentOS, creating a solid foundation for hosting websites and web applications. You can now deploy your websites or web applications on your CentOS server and take advantage of the power and flexibility offered by this robust web hosting environment.
Leave a Reply