Introduction:
Vesta Control Panel (VestaCP) is a popular open-source web hosting control panel that simplifies server management tasks. Keeping your server’s PHP version up-to-date is essential for security, performance, and compatibility with the latest web applications. In this guide, we will walk you through the process of updating PHP 7.2 to PHP 7.4 and PHP 8.0 on a VestaCP-powered server running Ubuntu 18.04.
Prerequisites:
Before we begin, ensure that you have:
- Access to a VestaCP-powered server running Ubuntu 18.04.
- SSH access to the server with administrative privileges.
- Backed up your website files and databases for safety.
Step 1: Connect to Your Server
Open your terminal and establish an SSH connection to your VestaCP server:
ssh your_username@your_server_ip
Replace your_username
with your SSH username and your_server_ip
with your server’s IP address.
Step 2: Update Package Lists
Update the package lists to ensure you are working with the latest information:
sudo apt update
Step 3: Add PHP Repositories
To update PHP to a newer version, you’ll need to add the corresponding repositories. For PHP 7.4 and PHP 8.0, use the following commands:
For PHP 7.4:
sudo add-apt-repository ppa:ondrej/php
For PHP 8.0:
sudo add-apt-repository ppa:ondrej/php8.0
Step 4: Update the Package Lists Again
After adding the repositories, update the package lists again:
sudo apt update
Step 5: Install PHP 7.4 and PHP 8.0
Install PHP 7.4 and PHP 8.0 along with necessary extensions:
sudo apt install php7.4 php8.0 php7.4-fpm php8.0-fpm php7.4-mysql php8.0-mysql php7.4-common php8.0-common php7.4-curl php8.0-curl php7.4-json php8.0-json php7.4-zip php8.0-zip php7.4-gd php8.0-gd php7.4-mbstring php8.0-mbstring php7.4-intl php8.0-intl php7.4-bcmath php8.0-bcmath php7.4-xml php8.0-xml php7.4-cli php8.0-cli php7.4-zip php8.0-zip
Step 6: Switch PHP Versions
Now, you need to switch the active PHP version for your web server. You can do this using the update-alternatives
command:
For PHP 7.4:
sudo update-alternatives --set php /usr/bin/php7.4
For PHP 8.0:
sudo update-alternatives --set php /usr/bin/php8.0
Step 7: Restart Your Web Server
Restart your web server to apply the changes:
sudo service apache2 restart
Step 8: Verify PHP Versions
To verify that the PHP versions have been updated successfully, you can create a PHP info page. Create a file named phpinfo.php
in your web server’s root directory with the following content:
<?php
phpinfo();
?>
Access this file in your web browser, and it should display the PHP 7.4 or PHP 8.0 information, depending on the version you switched to.
Conclusion:
Updating PHP on your VestaCP server is a crucial step to ensure security and compatibility with modern web applications. By following the steps outlined in this guide, you can smoothly transition from PHP 7.2 to PHP 7.4 or PHP 8.0 on your Ubuntu 18.04 server. Remember to test your websites thoroughly after the update to ensure everything works as expected.