This write-up will discuss the procedure to set up LAMP Stack on Ubuntu 22.04. So, let’s start!
How to Set up LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu 22.04
To set up LAMP Stack on Ubuntu 22.04, you must follow the below-given step-by-step instructions.
Step 1: Update system repositories
Press “CTRL+ALT+T” to open the terminal of your Ubuntu 22.04 and run the below-given command to update system repositories:
Step 2: Set up PHP on Ubuntu 22.04
Decide the PHP version which you want to install on Ubuntu 22.04 system. For instance, we will install “PHP 8.1”. To do the same, firstly, add the “ondrej/php” repository:
After adding the repository, execute the following command to install PHP version “8.1”:
Wait for a few minutes as the PHP installation will take some time to complete:
Step 3: Set up Apache on Ubuntu 22.04
PHP also installs Apache and its related modules on Ubuntu 22.04. However, you can still run the below-given command for confirmation:
Next, open port numbers “80” and “43” in the UFW firewall:
After performing the specified operation, open up your favorite web browser and navigate to the server address. Upon doing so, the following default page of the Apache Server will be displayed:
Step 4: Set up MySQL server on Ubuntu 22.04
In the next step, install the MySQL server on your system with the help of the following command:
Now, write out the below-given command for performing an initial and interactive configuration of the MySQL server:
In the configuration manual, you will be first asked to set the level for the password validation policy. Input a number from the given menu according to your password validation requirements:
After doing so, type out the new password for “root” and enter “y” to continue with the provided password:
Also, set the other configuration options accordingly:
Next, log in to the MySQL server to check if the connection with the server is established or not:
Step 5: Install other required packages
You may also need to install modules such as PHP extensions based on application requirements. Execute the following command in Ubuntu 22.04 terminal to check the available PHP extensions:
As you can see, the given command will print out the list of available PHP modules:
Lastly, install the required PHP modules with the help of the following command:
Step 6: Verify set up of LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu 22.04
By carefully following the previous steps, you must successfully set up LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu 22.04. To validate the integration between Apache and PHP, create a PHP script named “phpinfo.php” in the document root website directory:
Add the below-given content in the created “phpinfo.php” test script and press “CTRL+O” to save it:
Lastly, utilize the web browser to access the created PHP test script with the server IP address:
The content of the above web page signifies that we have successfully set up LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu.
To set up LAMP Stack on Ubuntu 22.04, firstly, execute the “$ sudo add-apt-repository ppa:ondrej/php” command to add “ondrej/php” repository, then run “$ sudo apt install php8.1” to install PHP and “$ sudo apt-get install mysql-server” to set up MySQL. The PHP package will also comprise Apache installation for Ubuntu 22.04. This write-up discussed the method to set up LAMP Stack on Ubuntu 22.04.