Install PHP 7.4 | PHP 7.4-FPM On Ubuntu 18.04 With Apache2 | Nginx (ok)
https://websiteforstudents.com/install-php-7-4-php-7-4-fpm-on-ubuntu-18-04-with-apache2-nginx/
CHú ý nếu gặp lỗi không cài được mysql thì đọc bài này :)
Install PHP 7.4 | PHP 7.4-FPM On Ubuntu 18.04 With Apache2 | Nginx
With tutorial, We’re going to show students and new users how to install or upgrade to PHP 7.4 | PHP 7.4-FPM on Ubuntu 18.04 | 16.04 servers..
If you’re a students and to develop PHP application, you’re mostly going to need PHP or PHP-FPM (if you’re going to be using Nginx HTTP server) and related modules installed….
PHP or PHP-FPM (for Nginx) is an open source server scripting language use for creating dynamic web applications and websites….
It is a widely used, free, and efficient alternative language to competitors such as Microsoft’s ASP and others…. Most popular content management systems like WordPress, Joomla, Drupal use PHP or PHP-FPM to function….
For more about this release, please check its homepage
PHP is used with Apache2 HTTP server PHP-FPM is used with Nginx HTTP server
When you’re ready to set up PHP with Apache2 or PHP-FPM with Nginx, follow the steps below:
Step 1: Setup PHP with Apache2 HTTP Server
To use PHP with Apache2 HTTP server, you should first install Apache2… You can do that by simply running the commands below:
After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always startup when the server boots up.
Step 2: Install PHP 7.4 to Support Apache2
PHP 7.4 may not be available in Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.
Run the commands below to add the below third-party repository to upgrade to PHP / PHP-FPM 7.4
Then update and upgrade to PHP 7.4
sudo apt update
Next, run the commands below to install PHP 7.4 and related modules.
There are many PHP modules that perform different functions…. however, these are some popular ones that may be needed when developing PHP based websites…
sudo apt-get install php7.4 libapache2-mod-php7.4 php7.4-cli php7.4-mysql php7.4-gd php7.4-imagick php7.4-tidy php7.4-xmlrpc
The line above will allow PHP to function with many popular PHP based websites and applications.
Step 3: Configure PHP 7.4 for Apache2
Now that Apache2 and PHP are installed, you may want to configure Apache2 to use PHP properly. The default Apache2 PHP configuration file is at /etc/php/7.4/apache2/php.ini
Open PHP Apache2 configuration file by running the commands below
sudo nano rr/php.ini
Then edit the file to suit your environments. Some important lines to consider:
Next, lookup Apache2 dir.conf file and confirm the line below:
If you don’t see the index.php definition on the line, please add it and save the file.
Restart Apache2 and PHP services
sudo systemctl restart apache2.service
That’s it! That is how one installs PHP with Apache2 support.
For PHP 7.4-FPM with Nginx HTTP server, follow the steps below:
Step 1: Setup PHP 7.4-FPM with Nginx HTTP server
To use PHP 7.4-FPM with Nginx HTTP server, you should first install Nginx… To do that, run the commands below:
After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always startup when the server boots up.
Step 2: Install PHP 7.4-FPM for Nginx
If you’re running Nginx then the commands below should get PHP-FPM and related modules installed….
There are many PHP-FPM modules that perform different functions…. however, these are some popular ones that may be needed when developing PHP based websites…
sudo apt-get install php7.4-fpm php7.4-cli php7.4-mysql php7.4-gd php7.4-imagick php7.4-tidy php7.4-xmlrpc
The line above will allow PHP to function with many popular PHP based websites and applications.
Step 3: Configure PHP 7.4-FPM for Nginx
Now that Nginx and PHP 7.4-FPM are installed, you may want to configure Nginx to use PHP 7.4-FPM properly. The default Nginx PHP-FPM configuration file is at /etc/php/7.4/fpm/php.ini
Open PHP Apache2 configuration file by running the commands below
sudo nano /etc/php/7.4/fpm/php.ini
Then edit the file to suit your environments. Some important lines to consider:
Save the file and exit….
Restart Nginx and PHP-FPM
At this point Apache2 or Nginx with PHP or PHP-FPM should be installed and ready to use.. you can test PHP / PHP-FPM settings by creating a blank file…..
r
Then add the line in the file and save.
<?php phpinfo( ); ?>
Save the file and open your browser and browse to the server name or IP address followed by /phpinfo.php
You should see something similar to the image below… if you do, then you’re all good!
Enjoy!
Congratulations! You’ve successfully installed and configured Apache2 / Nginx with PHP / PHP-FPM support on Ubuntu servers
You may also like the post below:
Last updated