How to LAMP install on AWS Ubuntu 22 04 Server Stepwise.

To install LAMP (Linux, Apache, MySQL, PHP) on an AWS Ubuntu server, you can follow these step-by-step instructions:

Connect to your AWS Ubuntu server using SSH.

Update the package list by running the command:

Install Apache web server by running the command:

Once Apache is installed, start the service and enable it to start at boot time by running the following commands:

Verify that Apache is running by opening a web browser and entering your server’s public IP address in the address bar. You should see the Apache default page.

Install MySQL server by running the command:

During the installation, you’ll be prompted to set the root password for MySQL. Choose a strong password and remember it.

Once MySQL is installed, start the service and enable it to start at boot time by running the following commands:

This is an optional step and will allow the root MySQL user to login through phpMyAdmin.

Change authentication method for the root account to mysql_native_password by executing the following query.

Replace password by the root password you entered while installing MySQL.

To put the changes into effect, execute the following query :

Following this, we can now do a root login through phpMyAdmin. The username is root and password is the one that was setup earlier while installing MySQL.

Return back to the command line.

Secure your MySQL installation by running the command:

  1. In the next screen we will be asked whether we need to setup VALIDATE PASSWORD plugin. We selected no.
  2. Set the password for the root MySql account.
  3. Remove anonymous users? We selected yes.
  4. Disallow root login remotely? We selected no.
  5. Remove test database and access to it? We chose yes.
  6. Reload privilege tables now? We again chose yes.

This will prompt you to configure some basic security settings for MySQL.

Install PHP and some common PHP modules by running the command:

Once PHP is installed, restart Apache for the changes to take effect by running the command:

Create a test PHP file to verify that PHP is working correctly. Create a file called info.php in the document root of your web server (/var/www/html/) with the following contents:

Paste the key and hit “ctrl-x”, hit “y” to save and “enter” to exit

Save the file and navigate to http://your_server_ip/info.php in a web browser. You should see a page displaying information about your PHP installation.

That’s it! You’ve now installed LAMP on your AWS Ubuntu server.

Optionally, you can also install some additional PHP modules that you may need for your web application. You can search for available PHP modules by running the command:

For example, if you need the PHP GD module, you can install it by running the command:

If you want to host multiple websites on your server, you’ll need to create separate directories in /var/www/html for each website and configure Apache virtual hosts. To create a new virtual host, create a new configuration file in the /etc/apache2/sites-available directory. For example, create a file called mywebsite.conf with the following contents:

Replace and with your actual domain names, and /var/www/html/mywebsite with the path to your website’s root directory. Then, enable the virtual host by running the command:

Finally, restart Apache for the changes to take effect by running the command:

Your new virtual host should now be accessible via its domain name.

That’s the complete process of installing LAMP on an AWS Ubuntu server, and you can now start deploying your web applications on your server.

To access MySQL database from PHP code, you can use the MySQLi or PDO extension. For example, to connect to a MySQL database using MySQLi, you can use the following code:

Replace “your_mysql_root_password” and “your_database_name” with your actual MySQL root password and database name, respectively.

To manage your MySQL databases and users, you can use the MySQL command line tool or a graphical user interface such as phpMyAdmin. To install phpMyAdmin, run the command:

During the installation, you’ll be prompted to configure some basic settings for phpMyAdmin, such as the web server to use and the database administrator password. Once installed, you can access phpMyAdmin by navigating to http://your_server_ip/phpmyadmin in a web browser.

Finally, to keep your LAMP stack up-to-date and secure, you should regularly update your Ubuntu packages and LAMP components using the following commands:

You should also configure a firewall to restrict incoming traffic to your server and set up backups to protect your data in case of a disaster.

That’s it! You now have a fully functional LAMP stack running on your AWS Ubuntu server.


To be able to upload files using FileZilla we need to change the ownership and access modes of the server directory.

any file unzip

When php file not then follow this process

Share on:

Hello, I am Dharmendra Yadav and I am a Python Developer with experience in web development using Django, Flask, REST API, SQL, MySQL, HTML, CSS, JavaScript, WordPress, Oracle Cloud, AWS and Git. I also write technical articles where I explain web development and Software Engineering. Facebook , Linkedin

Leave a Comment