Cloud Service >> Knowledgebase >> General >> How do I set up a LAMP web server?
submit query

Cut Hosting Costs! Submit Query Today!

How do I set up a LAMP web server?

Anyone who wants to manage dynamic extensions or web applications should first set up a LAMP web server. This tutorial will describe in detail how each part of the LAMP stack can be installed and configured in a Linux system to get to a working state for use in projects.

Prerequisites

Before you begin, ensure you have the following:

- A selected Linux distribution of the server: Any distro, such as Ubuntu, CentOS, or any other, can be chosen.

- A user account with sudo privileges.

- Access to a terminal or command line interface.

Step 1: Update Your System

Start by updating your package manager to ensure all software is current. This step is crucial for security and stability.

For Ubuntu/Debian-based systems, run:

sudo apt update && sudo apt upgrade -y

For CentOS/RHEL-based systems, use:

Sudo yum update -y

Step 2: Install Apache Web Server

Apache is usually the LAMP stack component used as the web server. To install Apache:

For Ubuntu/Debian:

1. Install Apache using the following command:

sudo apt install apache2 -y

2. Check if Apache is running:

Sudo systemctl status apache2

3. If you have a firewall enabled (UFW), allow HTTP traffic:

sudo ufw allow 'Apache Full'

sudo ufw reload

4. Test Apache by entering your server's IP address in a web browser. You should see the default Apache page.

For CentOS/RHEL:

1. Install Apache using:

Sudo yum install httpd -y.

2. Start the Apache service and enable it to run on boot:

sudo systemctl start httpd

sudo systemctl enable httpd

3. Allow HTTP traffic through the firewall:

sudo firewall-cmd --permanent --add-service=http

sudo firewall-cmd --reload

4. Test Apache by entering your server's IP address in a web browser.

Step 3: Install MySQL/MariaDB

MySQL or MariaDB serves as the database management system. Choose one based on your preference; MariaDB is a popular alternative to MySQL.

For Ubuntu/Debian:

1. Install MariaDB:

sudo apt install mariadb-server -y

2. Secure the installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and secure your database server.

For CentOS/RHEL:

1. Install MariaDB:

sudo yum install mariadb-server -y

2. Start the MariaDB service and enable it to run on boot:

sudo systemctl start MariaDB

sudo systemctl enable mariadb

3. Secure the installation:

sudo mysql_secure_installation

Step 4: Install PHP

The website's dynamic content is coded in PHP.

For Ubuntu/Debian:

1. Install PHP along with some standard modules:

sudo apt install php libapache2-mod-php php-mysql -y

2. To test PHP, create a simple PHP file:

echo "" | sudo tee /var/www/html/info.php

3. Access this file via your browser at http://your-server-ip/info.php. You should see the PHP information page.

For CentOS/RHEL:

1. Install PHP and required modules:

Sudo yum install php php-mysqlnd php-fpm -y

2. Create a test PHP file:

echo "" | sudo tee /var/www/html/info.php

Access this file in your browser, as mentioned above.

Step 5: Configure Apache to Use PHP

Ensure the necessary modules are enabled for Apache to process PHP files. This step is typically handled automatically during the PHP installation, but you can verify it.

For Ubuntu/Debian:

1. Enable the PHP module:

sudo a2enmod php

2. Restart Apache to apply changes:

sudo systemctl restart apache2

For CentOS/RHEL:

1. Restart Apache:

sudo systemctl restart httpd

Step 6: Final Testing

To confirm that your LAMP stack is functioning correctly:

- Visit http://your-server-ip/info.php in your web browser. You should get a page giving all sorts of information about PHP, and among them, it will show that PHP is working fine with Apache.

- Another form of application of the setup involves developing a basic web application or creating a content management system, such as WordPress, to determine its functionality.

Conclusion

Deploying a LAMP web server offers a strong atmosphere for web application development and hosting. By following the instructions given above, you have installed and configured Linux, Apache, MySQL/MariaDB, and PHP. Finally, with all the LAMP stack available, you can build, test, and host interactive websites effectively.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!