Why is Ubuntu behind in PHP version for the official APT repositories, and why is everybody using some random guys private repository to stay up to date?
Seems like a strange situation.
How to run a PHP file from ubuntu? - Stack Overflow
Installing PHP on ubuntu server 22.10 - Stack Overflow
apache - What is best way to install PHP 7.4 FPM on Ubuntu 18.04 - Stack Overflow
How to enable php extensions in ubuntu? - Stack Overflow
Videos
There are two options.
Access the php file through a local webserver(ie thru a local website). The web-server will deal with the requested php file. It will use either,
- Inbuilt PHP module to interpret the php file, or
PHP through CGI (eg.CGI, FastCGI)
If your apache(check if apache is running usingservice apache2 status!!) is set to the default configuration, this could be as simple ashttp://localhost/path/to/your.phpRemember by default, the base directory for apache is
/var/www/html/, so you need not include this in the url.
Use the php binary directly from a terminal.
php /path/to/your/file.php
After installation of Lamp system in Ubuntu. Please follow the below two steps to run your php file.
- Place your php file (.php) in /var/www/html/ (default path)
- Please run url as localhost/withfilename.php
Example : I have placed welcome.php file in the /var/www/html/welcome.php
then url will be http://localhost/welcome.php
You need to install the php5-cli or php5-cgi package.
sudo apt-get install php5-cli
# OR
sudo apt-get install php5-cgi
As Zoredache noted in the comment. cli version doesn't process headers nor dos output them - it's sort of clean PHP interpreter completely unaware of HTTP.
If you want version capable of above mentioned, use the CGI version.
Type the following in your terminal
whereis php
I really recommend installing PHP via Ondřej Surý's PPA
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt search php
You will be able not only to install PHP but also to install most of its popular PECL packages.
Moral of the story: Don't use Bleeding Edge technology to deploy servers. Stay on LTS releases.
Apparently the PHP Library has not been compiled for Ubuntu 22.10 yet, Just downgrade to 22.04 LTS and it works first time, you don't even need to add any repos, just apt install it.
The solution @rogervila providad works too, and you may be able to get it working on ubuntu 22.10, but it's just easier to downgrade to an LTS release.
un-commenting will not work on Ubuntu/Debian libux as you should install extension like
sudo apt install php8.2-curli believe you do not have php-fpm installed with apache and using default .... hence you need to restart apache2 for changes to take effect. you can check if php-fpm is configured with apache either via phpinfo() or via
sudo service php8.2-fpm status.
you may refer this article for detailed information on how to install. Please also note you might have to add Ondřej Surý’s PHP PPA to get latest stable versions of php for ubuntu
You need to restart php-fpm service for the modifications to take effect.
systemctl restart php8.2-fpm