Before getting started, ensure that your Kali Linux system is up to date. You can update your system by running the following command:
<span class="fun">sudo apt update && sudo apt upgrade</span>
By running this command, you ensure that all your software packages are up to date, which is important for the upcoming PHP deployment process.
To set up the PHP environment, you first need to install a web server. Apache is a commonly used option. Install it by running the following command:
<span class="fun">sudo apt install apache2</span>
Once installed, you can check if Apache is running by visiting http://localhost. If you see Apache's default page, the installation was successful.
Next, you need to install PHP and its related extensions. Run the following command:
<span class="fun">sudo apt install php libapache2-mod-php php-mysql</span>
This command will install PHP along with the necessary modules to interact with MySQL databases.
After PHP is installed, verify if it is working correctly. You can create a test file in Apache's root directory:
<span class="fun">echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php</span>
Then, you can view the PHP configuration page by visiting http://localhost/info.php. If you see PHP's configuration information, PHP is successfully installed.
Depending on your needs, you may want to adjust the PHP configuration. You can edit the PHP configuration file using the following command:
<span class="fun">sudo nano /etc/php/7.4/apache2/php.ini</span>
In this file, you can modify settings like error reporting, file upload sizes, and more. After making changes, don't forget to restart Apache for the changes to take effect:
<span class="fun">sudo systemctl restart apache2</span>
Security is an important consideration when deploying PHP applications. On Kali Linux, you can protect your server using a firewall. For example, you can use the ufw firewall and allow Apache with the following command:
<span class="fun">sudo ufw allow 'Apache'</span>
Proper firewall configuration helps prevent unauthorized access to your server.
With the steps outlined in this guide, you now have a solid understanding of how to deploy PHP on Kali Linux. By following best practices and paying attention to security, you can successfully launch your PHP projects. Whether developing websites or applications, a properly configured environment forms the foundation of successful development.