How to Install Apache with PHP on Debian
To install Apache with PHP on Debian 12, you can follow the steps below. These commands will help you set up a web server with PHP support.
Step 1: Update the System
First, make sure your system is up to date:
sudo apt update
sudo apt upgrade -y
Step 2: Install Apache
Install the Apache web server:
sudo apt install apache2 -y
After installation, check if Apache is running:
sudo systemctl status apache2
Step 3: Install PHP
Install PHP and the required modules. You can install the latest version of PHP available in the Debian repository with the following command:
sudo apt install php libapache2-mod-php php-mysql -y
This command installs PHP, the Apache module for PHP, and the PHP module for MySQL. If you need additional PHP modules, you can install them as needed. For example:
sudo apt install php-cli php-curl php-gd php-mbstring php-xml php-zip -y
Debian is one of the Linux distributions with the most PHP packages available. You can see a list of available packages with the command:
apt list php-*
Step 4: Restart Apache
After installing PHP, you need to restart Apache so it recognizes PHP:
sudo systemctl restart apache2
Step 5: Verify PHP Installation
To verify that PHP is working correctly with Apache, you can create an info.php file in the web server root directory:
sudo nano /var/www/html/info.php
Add the following content to the file:
<?php
phpinfo();
?>
Save and close the file. Then open a web browser and access http://ip_do_seu_servidor/info.php (replace seu_servidor with the IP address or domain name of your server). You should see the PHP information page, which confirms that PHP is working correctly with Apache.
You can also test from the command line using the curl command:
curl localhost/info.php
Step 6: Configure the Firewall (Optional)
If you are using a firewall, you may need to allow HTTP and HTTPS traffic. Here is how to do it using ufw:
sudo ufw allow in "Apache Full"
If this command returns an error message, it is because the UFW firewall is not installed on your system.
Conclusion
With these steps, you will have an Apache web server with PHP support running on Debian 12. Make sure to adjust the settings according to your specific needs and add additional PHP modules as needed for your project.
That was just one piece. The course teaches the whole path — from your first command to exam day.