Introduction
Setting up a local development environment with PHP, MySQL, and Apache is essential for web developers. In this comprehensive guide, we will walk you through the step-by-step process of installing and configuring PHP, MySQL, and Apache on Ubuntu 22.04, allowing you to create and test web applications efficiently.

Step 1: Update System Packages
Before getting started, it’s important to ensure that your system is up to date. Open a terminal and execute the following commands:sudo apt update sudo apt upgrade
Step 2: Install Apache
Apache is a widely used web server. Install it by running the following command in the terminal:sudo apt install apache2
Once the installation is complete, Apache will start automatically. You can verify its status by entering sudo systemctl status apache2 in the terminal. If Apache is running, you should see an active status message.
Step 3: Install MySQL
MySQL is a popular relational database management system. Install it by executing the following command in the terminal:sudo apt install mysql-server
During the installation process, you’ll be prompted to set a password for the MySQL root user. Make sure to choose a strong and secure password.
Step 4: Secure MySQL Installation
To enhance the security of your MySQL installation, execute the following command in the terminal:sudo mysql_secure_installation
Follow the on-screen prompts to secure your MySQL installation. This includes setting a password policy, removing anonymous users, disabling remote root login, and removing test databases.
Step 5: Install PHP
PHP is a server-side scripting language. Install PHP along with some common extensions by running the following command in the terminal:sudo apt install php libapache2-mod-php php-mysql
Step 6: Test PHP
To ensure that PHP is installed and working correctly, create a test file. Use the following command in the terminal:sudo nano /var/www/html/info.php
Inside the file, add the following line:<?php phpinfo(); ?>
Save the changes and exit the text editor. Now, open a web browser and visit http://localhost/info.php. If PHP is configured correctly, you should see the PHP information page.
Step 7: Configure Apache for PHP
Next, we need to configure Apache to recognize PHP files. Open the Apache configuration file in a text editor using the following command:sudo nano /etc/apache2/mods-enabled/dir.conf
Move the index.php file to the beginning of the list, so it becomes the default index file. It should look like this:<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
Save the changes and exit the text editor.
Step 8: Restart Apache
To apply the changes made to the Apache configuration, restart the Apache service by executing the following command:sudo systemctl restart apache2
Conclusion:
Congratulations! You have successfully set up PHP, MySQL, and Apache on Ubuntu 22.04. You now have a fully functional local development environment to create and test your web applications. Enjoy coding and building amazing projects!

Leave a Reply