elfsightSkip to content
Installing and Configuring LAMP on Ubuntu Step by

Installing and Configuring LAMP on Ubuntu Step by Step

Installing and Configuring LAMP on Ubuntu Step by Step. Installing and configuring the LAMP stack on Ubuntu is a straightforward process accessible to any user with basic knowledge in Linux server administration.

Once configured, this infrastructure allows running web applications written in PHP, managing MySQL databases and customizing the server through Apache configuration files.

Installing and Configuring LAMP on Ubuntu

The LAMP stack (Linux, Apache, MySQL, PHP) is one of the most popular solutions for developing and hosting web applications.

This guide shows you how to install and configure LAMP on an Ubuntu server, step by step, to be able to run dynamic websites or PHP applications.

1. System Update

Before starting the installation, it is recommended to update the system packages:

sudo apt update && sudo apt upgrade -y

2. Installing Apache Server

sudo apt install apache2 -y

To verify that Apache is running correctly, access the server’s IP in a browser.

You should see the default page “Apache2 Ubuntu Default Page”.

3. Installing MySQL Database Server

sudo apt install mysql-server -y

After installation, run the security script:

sudo mysql_secure_installation

You will be guided to set the password for the root user and configure other security options.

4. Installing PHP Language

To allow Apache to interpret PHP files:

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

To check the installed version:

php -v

5. Testing PHP

Creating a test file in the web directory:

sudo nano /var/www/html/info.php

Add the following code:

<?php phpinfo(); ?>

Save the file and access http://server-IP/info.php to see the PHP information.

6. Configuring Permissions and Root Directory

To work more easily with files in /var/www/html:

sudo chown -R $USER:$USER /var/www/html
sudo chmod -R 755 /var/www

7. Configuring Virtual Hosts (Optional)

To host multiple websites on the same server, you can create virtual host files:

sudo nano /etc/apache2/sites-available/example.com.conf

Configuration example:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the virtual host and restart Apache:

sudo a2ensite example.com.conf
sudo systemctl reload apache2

8. Enabling Required Modules

Make sure the rewrite module is active for proper functioning of web applications:

sudo a2enmod rewrite
sudo systemctl restart apache2

9. Accessing MySQL from Terminal

sudo mysql -u root -p

Command to create a database:

CREATE DATABASE database_name;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Special SEO Services – We offer specialized SEO optimization and search engine marketing services. Contact us now!

Previous post
Next article

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top
ROEN