How to Install PHP on Ubuntu
PHP is a popular server-side scripting language used to create dynamic web pages. If you’re looking to run PHP on your Ubuntu server, you’re in the right place! In this guide, we’ll walk you through the steps to install PHP on your Ubuntu machine.
Step 1: Update System
Before we begin, it’s important to make sure your system is up to date. Run the following commands to update the package list and upgrade any outdated packages:
sudo apt update
sudo apt upgrade
Step 2: Install PHP
Next, we’ll install PHP on your Ubuntu machine. Run the following command to install PHP along with some commonly used extensions:
sudo apt install php libapache2-mod-php php-mysql
Step 3: Verify Installation
To confirm that PHP has been successfully installed, you can check the version by running the following command:
php -v
If everything is set up correctly, you should see the PHP version displayed on your terminal.
Step 4: Test PHP
Now that PHP is installed, let’s create a test file to make sure it’s working properly. Create a new file named test.php
in your web server’s root directory with the following content:
<?php
phpinfo();
?>
Save the file and navigate to http://localhost/test.php
in your browser. If you see a page displaying PHP information, congratulations! PHP is up and running on your Ubuntu server.
Step 5: Additional Steps
Depending on your project requirements, you may need to install additional PHP extensions or configure PHP settings. You can install more extensions using the apt
package manager and modify PHP settings in the php.ini
configuration file.
That’s it! You now have PHP installed on your Ubuntu machine and are ready to start building dynamic web applications. If you encounter any issues during the installation process, feel free to consult the official Ubuntu documentation or seek help from the vibrant online community.
- Update your system using
apt update
andapt upgrade
. - Install PHP and necessary extensions with
apt install php libapache2-mod-php php-mysql
. - Verify the installation by running
php -v
. - Create a test file to confirm PHP functionality.
- Explore additional steps to customize your PHP installation.