Introduction
PHP is a popular server scripting language known for creating dynamic and interactive web pages. Getting up and running with your language of choice is the first step in learning to program.
This tutorial will guide you through installing PHP 7.4 on Ubuntu and setting up a local programming environment via the command line. You will also install a dependency manager, Composer, and test your installation by running a script.
If you’re a student and to develop a 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….
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:
sudo apt update
sudo apt install apache2
After installing Apache2, the commands below can be used to stop, start and enable the Apache2 service to always start up when the server boots up.
sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
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
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
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-recode 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 /etc/php/
7.4
/apache2/php.ini
Then edit the file to suit your environment. Some important lines to consider:
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago
Next, lookup Apache2 dir. conf file and confirm the line below:
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
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:
sudo apt update
sudo apt install nginx
After installing Nginx, the commands below can be used to stop, start and enable the Nginx service to always start up when the server boots up.
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
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-recode 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 is 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 environment. Some important lines to consider:
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 64M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago
Save the file and exit.
Restart Nginx and PHP-FPM
sudo systemctl restart nginx.service
sudo systemctl restart php7.4-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.
sudo nano /var/www/html/phpinfo.php
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!
Conclusion
Congratulations! You’ve successfully installed and configured Apache2 / Nginx with PHP / PHP-FPM support on Ubuntu servers.
Its like you read my mind! You appear to know so much about this, like you
wrote the book in it or something. I think
that you can do with some pics to drive the message home a bit, but other
than that, this is wonderful blog. A fantastic read.
I will definitely be back.
Thank you for your article post.Much thanks again.
Appreciate you sharing, great article.Much thanks again. Great.
Enjoyed every bit of your blog article.Thanks Again. Want more.
Really appreciate you sharing this article.Much thanks again. Much obliged.
Really informative article.Really looking forward to read more. Awesome.
I am so grateful for your article post.Much thanks again. Great.
I appreciate you sharing this article.Much thanks again. Great.
Looking forward to reading more. Great article post.Really thank you! Keep writing.
Enjoyed every bit of your blog post. Cool.
Major thanks for the article post. Want more.
Really enjoyed this post.Much thanks again. Really Great.
Awesome article post.Thanks Again. Great.
Fantastic blog article.Much thanks again. Will read on…
I appreciate you sharing this article post. Keep writing.
Great blog article.Really thank you! Will read on…
Very neat article post.Thanks Again. Want more.
Thanks for sharing, this is a fantastic post.Thanks Again. Fantastic.
Hey, thanks for the blog article.Thanks Again. Much obliged.
Wow, great blog article.Much thanks again. Will read on…
Major thanks for the blog.Really looking forward to read more. Great.
Great, thanks for sharing this blog article.Really thank you! Want more.
I value the blog.Much thanks again. Want more.
I appreciate you sharing this post.Really looking forward to read more. Want more.
Say, you got a nice blog post.Thanks Again. Will read on…
This is one awesome blog.Really looking forward to read more. Keep writing.
Im thankful for the blog article.Much thanks again. Really Cool.
Thanks for the blog.Really thank you! Awesome.
Very good blog post.Really looking forward to read more.
I cannot thank you enough for the article.Really looking forward to read more.
This is one awesome article.Much thanks again. Much obliged.
Really enjoyed this article post.Much thanks again. Cool.
Thanks for the blog article.Thanks Again. Cool.
Thanks for sharing, this is a fantastic article.Much thanks again. Will read on…
Very good blog article.Much thanks again. Great.
Thanks again for the article post.Really thank you! Really Cool.
Say, you got a nice blog article. Want more.
A round of applause for your blog article.Really looking forward to read more. Fantastic.
Fantastic post. Awesome.
Im thankful for the article post.Thanks Again. Keep writing.
Very good blog post.Much thanks again. Keep writing.
Great article.Thanks Again.
Im obliged for the blog article. Much obliged.
A big thank you for your blog post.Much thanks again. Really Cool.
A big thank you for your article.Really looking forward to read more. Fantastic.
I think this is a real great post.Really looking forward to read more. Great.
Thanks for sharing, this is a fantastic post.Really thank you! Will read on…
I value the blog article.Really thank you! Really Great.
This is one awesome post.Really looking forward to read more. Awesome.
Im obliged for the article post.Thanks Again. Much obliged.
Major thankies for the blog.Thanks Again. Will read on…
Really informative blog article.Thanks Again. Great.
I really like and appreciate your blog.Really looking forward to read more. Great.
Great article post. Really Great.
I appreciate you sharing this article.Much thanks again. Really Great.
Really informative article post.Thanks Again.
Very informative blog post.Really thank you! Great.
I truly appreciate this blog post.Thanks Again. Really Great.
I think this is a real great article.Really thank you! Fantastic.
Fantastic article post.Thanks Again. Awesome.
Enjoyed every bit of your article post.Really thank you! Really Great.
Thanks for the blog post.Thanks Again.
I really enjoy the article. Cool.
I appreciate you sharing this article post.Really thank you! Cool.
This is one awesome article.Thanks Again. Want more.
Great, thanks for sharing this article post.Really looking forward to read more. Awesome.
Fantastic blog post. Really Great.
I value the blog article.Really thank you! Awesome.
Really informative article post. Will read on…
Wow, great blog.Much thanks again. Keep writing.
Thanks so much for the article post. Really Cool.
Major thankies for the blog article.Really looking forward to read more.
Thanks a lot for the blog. Really Cool.
Thanks a lot for the blog article.
Thanks for the blog article.Thanks Again. Want more.
I appreciate you sharing this article post. Really Great.
I appreciate you sharing this blog article.Much thanks again. Want more.
Major thanks for the blog article.Much thanks again. Keep writing.
Really enjoyed this blog post.Much thanks again. Keep writing.
Looking forward to reading more. Great article post.Thanks Again. Cool.
A big thank you for your post.Thanks Again. Keep writing.
Thanks a lot for the blog article.Really thank you! Want more.
Im thankful for the blog.Much thanks again. Want more.
Muchos Gracias for your article post.Really looking forward to read more. Really Cool.
Really appreciate you sharing this blog. Want more.
Thanks-a-mundo for the post.Really thank you! Keep writing.
I really like and appreciate your article.Thanks Again. Keep writing.
Thanks-a-mundo for the post.Really thank you! Fantastic.
Thanks a lot for the article post.Thanks Again. Really Cool.
Very good blog article.Really looking forward to read more.
Thanks again for the blog.Really thank you! Really Cool.
I think this is a real great blog article.Really thank you! Cool.
Enjoyed every bit of your blog article.Thanks Again.
Fantastic article post. Cool.
Very good article.Much thanks again. Great.
This is one awesome blog article.Thanks Again. Really Cool.
Wow, great blog post.Much thanks again. Great.
Looking forward to reading more. Great blog.Really thank you! Really Great.
Very good blog post. Great.
Thanks for sharing, this is a fantastic post.Really thank you! Much obliged.
Thanks so much for the blog post.Really thank you! Want more.
Thanks so much for the blog article. Awesome.
Major thanks for the blog post.Thanks Again. Will read on…
I really liked your blog.Much thanks again. Really Cool.
Im grateful for the blog article.Really thank you!
A round of applause for your post.Thanks Again. Awesome.
Great, thanks for sharing this article post.Thanks Again. Will read on…
Thanks for the blog post.Much thanks again. Want more.
Thanks-a-mundo for the article.Much thanks again. Cool.
This is one awesome blog. Keep writing.
Awesome article. Great.
Thank you ever so for you article post.Really thank you!
Very good blog post.Really looking forward to read more. Really Great.
I value the article.Much thanks again.
Im thankful for the post.Really thank you! Awesome.
Thanks again for the article.Much thanks again. Fantastic.
This is one awesome post.Much thanks again. Great.
I value the blog.Much thanks again. Really Cool.
Say, you got a nice post.Really thank you!
A big thank you for your article. Awesome.
Great article.Really thank you! Really Great.
I really liked your article post. Will read on…
Great, thanks for sharing this blog.Thanks Again.
How can I reach you? I am interested in more info.
Interested in more information. How can I contact you?
Thx so much !! Appreciate the helpful information.
info@adglob.in
info@adglob.in
This article is genuinely a fastidious one it assists new web visitors, who are wishing in favor of blogging.
I read this post completely regarding the resemblance of most recent and earlier technologies, it’s awesome article.
I just saved your page.
This information is so amazing thanks!
Wow, great article.Really looking forward to read more. Awesome.
Thank very much for helping me.