How to install and configure a PHP7 environment on Ubuntu

PHPz
Release: 2023-04-21 09:17:26
Original
1350 people have browsed it

Ubuntu is a widely used operating system based on the Linux distribution. Developers and users like Ubuntu because it is relatively fast and easy to use. In this article, we will explain how to install and configure a PHP7 environment on Ubuntu.

Step 1: Update the system

Before installation, we should ensure that the operating system is up to date. Open a terminal and enter the following command:

sudo apt update
sudo apt upgrade
Copy after login

The above two commands will update the system packages and install any available updates. It may take several minutes to complete these tasks.

Step 2: Install the Apache web server

PHP is a scripting language that runs on the web server. Therefore, before installing PHP, we must first install the web server.

Ubuntu uses the Apache web server, let us install it through the following command:

sudo apt install apache2
Copy after login

During the installation process, you will be asked to confirm the installation (select Yes), and then wait for some time until the installation is completed .

Step 3: Install PHP7 and related modules

Next, there are a few more steps required to install PHP and enable the modules. In Ubuntu 18.04 and above, we can install PHP using the following command:

sudo apt install php libapache2-mod-php php-mysql
Copy after login

In Ubuntu 16.04, we can install PHP using the following command:

sudo apt install php7.0 libapache2-mod-php7.0 php7.0-mysql
Copy after login

After the installation is complete, run the following Command to restart the Apache web server:

sudo systemctl restart apache2
Copy after login

Step 4: Check whether the PHP installation is successful

After the installation is completed, we can test whether it is working properly by checking whether the PHP version is correct. Enter the following command in the terminal:

php -v
Copy after login

This command will display the installed PHP version as follows:

PHP 7.4.3 (cli) (built: Feb 24 2020 17:23:43) ( NTS )
Copy after login

Step 5: Test whether PHP is working properly in Apache

To verify that the Apache web server is correctly configured to interpret PHP scripts, you need to create a file containing phpinfo(). The phpinfo() function will display detailed information about the PHP environment.

Let’s create a file called test.php. Enter the following command in the terminal:

sudo nano /var/www/html/test.php
Copy after login

In the open file, enter the following:

<?php
phpinfo();
?>
Copy after login

Save and close the file. Now, access the test.php file through your browser (for example: http://your_ip_address/test.php).

Detailed information about PHP, including installed versions, server settings, etc. are available in this page.

Conclusion

Through the guidance of this article, you have successfully installed and configured the PHP7 environment on Ubuntu. Now you can start developing PHP-based web applications.

The above is the detailed content of How to install and configure a PHP7 environment on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!