By mikevrind
I followed a small guide on how to install PHP7 (http://www.zimuel.it/install-php-7/). The installation went successful but could someone give some advice on how to use PHP in combination with Apache (Setting up servers isn’t my thing haha)? I couldn’t find anything about how to setup PHP7 with Apache2 which makes sense since the official release is still a few months away. But I would like to do some testing with it :)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi Mike,
All DigitalOcean servers managed by ServerPilot have PHP 7 available by default. There’s nothing you need to customize, it’s part of the standard server configuration which uses Apache behind Nginx.
A quick search found this guide which should assist you in getting PHP 7 working with Apache on Ubuntu.
To set up Apache2 with PHP 7.x or PHP 8.x on a Linux-based system, you’ll need to follow a series of steps. Below are instructions for both PHP 7.x and PHP 8.x installations.
sudo apt update
sudo apt install apache2
Install PHP 7.x: Install PHP 7.x and its commonly used extensions:
For PHP 7.4:
sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-xsl
Replace `7.4` with the desired PHP 7.x version (e.g., 7.3, 7.2) if needed.
sudo a2enmod php7.4
sudo systemctl restart apache2
info.php in your web server’s document root directory (usually /var/www/html/) with the following content:<?php phpinfo(); ?>
Save the file and open it in your web browser by navigating to `http://your-server-ip/info.php` (replace `your-server-ip` with your server's IP address). You should see a page displaying PHP information.
sudo apt update
sudo apt install apache2
Install PHP 8.x: Install PHP 8.x and its commonly used extensions:
For PHP 8.0:
sudo apt install php8.0 libapache2-mod-php8.0 php8.0-mysql php8.0-curl php8.0-json php8.0-cgi php8.0-xsl
Replace `8.0` with the desired PHP 8.x version (e.g., 8.1, 8.2) if needed.
sudo a2enmod php8.0
sudo systemctl restart apache2
info.php in your web server’s document root directory (usually /var/www/html/) with the following content:<?php phpinfo(); ?>
Save the file and open it in your web browser by navigating to `http://your-server-ip/info.php` (replace `your-server-ip` with your server's IP address). You should see a page displaying PHP information.
That’s it! You’ve successfully set up Apache2 with PHP 7.x or PHP 8.x on your Linux system. You can now start hosting PHP-based web applications on your server.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.