How to install php 7 on ubuntu 18

Upgrade PHPhường version khổng lồ PHPhường 7.4 on Ubuntu. You can nâng cấp yourcurrent PHPhường version lớn the lathử nghiệm release PHPhường 7.4 on your Ubuntu 18.04.

Bạn đang xem: How to install php 7 on ubuntu 18

This nâng cấp is tested on virtual machine instance running Ubuntu 18.04 OS on Google Cloud Compute Engine. So the steps mentioned in this guide works on any cloud servers like AWS, DigitalOcean, Linode, Vultr or any VPS or Dedicated servers running Ubuntu 18.04.


Here is a brief guide to lớn show you how to lớn install & upgrade to PHP 7.4 on Ubuntu 18.04 LTS with Apabít & PHP7.4-fpm with Nginx.


Choose Best Hosting for your Business

PlatformReviewsPricing
Siteground★★★★★$3.95
Kinsta – Google Cloud★★★★★$30

Add PPA for PHP. 7.4

Add the ondrej/php which has PHPhường. 7.4 package và other required PHPhường. extensions.

suvì chưng apt install software-properties-commonsudo add-apt-repository ppa:ondrej/phpsudo apt updateOnce you have added the PPA you can install PHPhường 7.4.

Install PHP 7.4 for Apache

Exexinh đẹp the following commvà to install PHP 7.4


subởi apt install php7.4

Install PHP 7.4 Extensions

Installing PHPhường extensions are simple with the following syntax.

suvì chưng apt install php7.4-extension_nameNow, install some commonly used php-extensions with the following commvà.

suvị apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagiông xã php7.4-cli php7.4-dev php7.4-imaps php7.4-mbstring php7.4-opcabịt php7.4-soap php7.4-zip php7.4-intl -yAfter the installation has completed, you can confirm the installation using the following command

php -v

Enable PHPhường 7.4 for Apache

Now you need to lớn tell Apabít to lớn use the installed version of PHP.. 7.4 by disabling the old PHP module (below I have sầu mentioned php7.0, you need to lớn use your current php version used by Apache) và enabling the new PHP module using the following commvà.

suvì chưng a2disthủ thuật php7.0subởi a2enthủ thuật php7.4Restart Apache for the changes to lớn take effect.


subởi vì service apache2 restart

Install PHPhường 7.4 FPM for Nginx

For Nginx you need khổng lồ install FPM, execute the following commvà to lớn install PHPhường. 7.4 FPM

subởi apt install php7.4-fpmFollow the same method above mentioned to install the extensions

After the installation has completed, confirm that PHP. 7.4 FPM has installed correctly with this command

php-fpm7.4 -v

Modify Nginx configuration khổng lồ use PHPhường 7.4

For Nginx you need khổng lồ update the PHP-FPM socket in your Nginx configration located inside the sites-available directory. This will be located inside the location block location~.php$

Edit your configuration…


sudo nano /etc/nginx/sites-available/your.confThe line you need to lớn modify will look lượt thích this…

fastcgi_passunix:/run/php/php7.0-fpm.sock; You need to replace the old PHP. version with the new version.

fastcgi_passunix:/run/php/php7.4-fpm.sock; Test your configration.

sudo nginx -tSave the tệp tin và exit the editor & restart Nginx for the changes to lớn take effect.

suvì chưng service nginx restart

Configure PHPhường 7.4

Now we configure PHP for Web Applications by changing some values in php.ini tệp tin.

Xem thêm: How It Works Dig This! - How It Works Digital Downloads


For PHPhường. 7.4 with Apache the php.ini location will be in following directory.

subởi nano /etc/php/7.4/apache2/php.iniFor PHPhường 7.4 FPM with Nginx the php.ini location will be in following directory.

suvị nano /etc/php/7.4/fpm/php.iniHit F6 for tìm kiếm inside the editor và update the following values for better performance.

upload_max_filekích cỡ = 32M post_max_kích cỡ = 48M memory_limit = 256M max_execution_time = 600 max_input_vars = 3000 max_input_time = 1000Once you have sầu modified your PHP settings you need to lớn restart your Apabịt for the changes lớn take effect.

Configure PHP 7.4 FPM Pools

PHPhường 7.4 FPM allows you to configure the user & group that the service will run under. You can modify these with these commands


suvì chưng nano /etc/php/7.4/fpm/pool.d/www.confChange the following lines by replacing the www-data with your username.

user = username group = username listen.owner = usernamelisten.group = usernameHit CTRL+X và Y to save sầu the configuration & check if the configuration is correct and restart PHP..

Restart PHP 7.4 FPM

Once you have sầu updated your PHP. FPM settings you need lớn restart it lớn apply the changes.

suvì php-fpm7.4 -t suvì service php7.4-fpm restartBecome a Linux System Administrator & maintain virtual servers in a multi-user environment.

Conclusion

Now you have learned how khổng lồ upgrade PHP lớn PHP.. 7.4 on Ubuntu 18.04.


Thanks for your time. If you face any problem or any feedback, please leave a comment below.


Compute EngineGoogle Cloud PlatformUbuntu 18.04

How lớn Install IonCube Loader on Ubuntu


January 15, 2021

How khổng lồ Install PHP 8 on Ubuntu


November 27, 2020

Automated CI/CD Deployment khổng lồ App Engine with Cloud Build


November 24, 2020
24 Comments
*

Joffer1 year ago Reply

thanks for your help, that was quite easy to lớn update php version with this article


Mike1 year ago Reply

Wow, after looking all over the website and at least two dozen different & very confusing page results, I thankfully found this article — so straight-forward và simple I almost couldn’t believe it was going lớn work! Easy-peasy, thank you!


john doe12 months ago Reply

Thanks, this helps me a lot!


Harold Callahan12 months ago Reply

Can’t get around the following error:

sudo a2enmod php7.4Considering dependency mpm_prefork for php7.4:Considering conflict mpm_event for mpm_prefork:ERROR: Module mpm_sự kiện is enabled – cannot proceed due lớn conflicts. It needs to lớn be disabled first!Considering conflict mpm_worker for mpm_prefork:ERROR: Could not enable dependency mpm_prefork for php7.4, aborting

-Callahan-


Harold Callahan12 months ago Reply

Fixed it!!

subởi vì a2dismod mpm_eventModule mpm_event disabled.To activate the new configuration, you need to lớn run:systemctl restart apache2:/etc# suvì a2enthủ thuật php7.4Considering dependency mpm_prefork for php7.4:Considering conflict mpm_sự kiện for mpm_prefork:Considering conflict mpm_worker for mpm_prefork:Enabling module mpm_prefork.Considering conflict php5 for php7.4:Enabling module php7.4.To activate the new configuration, you need to lớn run:systemctl restart apache2

-Callahan-


Pixel Maker5 months ago Reply

I did all of this but

sudo a2enmod php7.4Considering dependency mpm_prefork for php7.4:Considering conflict mpm_sự kiện for mpm_prefork:Considering conflict mpm_worker for mpm_prefork:Module mpm_prefork already enabledConsidering conflict php5 for php7.4:Module php7.4 already enabled

& still I see php -v as 7.2.

Please let me know what I was missing

Thanks


Write A Comment Cancel Reply


Save sầu my name, email, and website in this browser for the next time I phản hồi.


This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.
Trending Articles
Subscribe for Newsletter

Enter your email address below khổng lồ subscribe khổng lồ my newsletter