How to Install PHP on Fedora
PHP is a popular server-side scripting language used for web development. It allows developers to create dynamic web pages and applications that can interact with databases and handle user input. In this tutorial, we will walk through the step-by-step process of installing PHP on Fedora, a Linux distribution.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- A Fedora system with administrative privileges.
- Access to the internet to download the necessary packages.
Step 1: Update System Packages
Before installing PHP, it's always a good practice to update the system packages to their latest versions. Open a terminal and execute the following command:
sudo dnf update
This command will update all the installed packages on your Fedora system.
Step 2: Install PHP
To install PHP on Fedora, we will use the dnf
package manager. Open a terminal and run the following command:
sudo dnf install php
The package manager will resolve all the dependencies and prompt you to confirm the installation. Press 'y' and hit Enter to proceed.
Step 3: Verify PHP Installation
Once the installation is complete, we can verify if PHP is installed correctly. Open a terminal and execute the following command:
php -v
This will display the PHP version installed on your Fedora system. For example, you might see an output like this:
PHP 7.4.12 (cli) (built: Oct 29 2020 16:57:34) ( NTS )
Step 4: Install Additional PHP Extensions
By default, the PHP installation on Fedora includes only the core PHP modules. Depending on your project requirements, you may need to install additional PHP extensions. For example, if you want to connect to a MySQL database, you will need the php-mysqlnd
extension.
To install additional PHP extensions, use the following command syntax:
sudo dnf install php-<extension-name>
Replace <extension-name>
with the desired extension name. For example, to install the PHP MySQL extension, run the following command:
sudo dnf install php-mysqlnd
Step 5: Restart Web Server
If you are using PHP with a web server such as Apache or Nginx, you will need to restart the server for the changes to take effect. Use the following command to restart Apache:
sudo systemctl restart httpd
Replace httpd
with the appropriate service name if you are using a different web server.
Step 6: Test PHP Installation
To ensure PHP is working correctly, let's create a simple PHP script and test it.
Create a new file named test.php
using a text editor of your choice. For example, using the nano
text editor:
nano test.php
Add the following code to the test.php
file:
<?php
phpinfo();
?>
Save the file and exit the text editor.
Now, open a web browser and navigate to http://localhost/test.php
. You should see a page displaying detailed information about your PHP installation, including PHP version, configuration settings, and loaded modules.
Conclusion
Congratulations! You have successfully installed PHP on your Fedora system. You can now start developing dynamic web applications using PHP. Remember to keep your PHP installation up to date and install additional extensions as per your project requirements. Enjoy coding!