Install LAMP in Ubuntu Server

You are currently viewing Install LAMP in Ubuntu Server

To install a LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack on Ubuntu, you can follow these steps:

Step 1: Update Package List

Update your package list to make sure you have the latest information about available packages:

sudo apt update

Step 2: Install Apache

Install the Apache web server:

sudo apt install apache2

Step 3: Start Apache

Start the Apache service and enable it to start on boot:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 4: Install MySQL (MariaDB)

Install the MySQL (or MariaDB) database server:

sudo apt install mariadb-server

Secure your MySQL installation:

sudo mysql_secure_installation

Follow the on-screen prompts to set a root password and answer security-related questions.

Step 5: Install PHP

Install PHP and the required modules:

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

Step 6: Test the Installation

Create a simple PHP info file to test the setup:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit your server’s IP address in a web browser with /info.php appended (e.g., http://your_server_ip/info.php). You should see the PHP information page.

Step 7: (Optional) Install Additional PHP Modules

Depending on your project requirements, you may need to install additional PHP modules. You can search for available modules using:

sudo apt search php-

Step 8: Configure Firewall

If you’re using a firewall, you may need to open the necessary ports. For example, for UFW:

sudo ufw allow 'Apache Full'
sudo ufw allow 'OpenSSH'
sudo ufw enable

These steps provide a basic LAMP stack setup. Depending on your specific requirements, you may need to customize configurations further. Always refer to the official documentation for each component for more detailed information.

Leave a Reply