It seems that the only way to do this is to install together an Apache server which is very-very unwanted (in our case).
We just want to utilize the simple built-in web server, as the lucky users of some non-ubuntu OSes (like MS Windows 10) have.
It seems that the only way to do this is to install together an Apache server which is very-very unwanted (in our case).
We just want to utilize the simple built-in web server, as the lucky users of some non-ubuntu OSes (like MS Windows 10) have.
Ubuntu package details says php (php7.2) depends on libapache2-mod-php7.2 OR php7.2-fpm OR php7.2-cgi.
It seems to default to the first package, which itself depends on apache2. But if you install one of the latter first, and php afterwards, apache2 will not be installed.
sudo apt install php-cgi
sudo apt install php
or manually put the resolved dependency:
sudo apt install php php7.2-cgi
Then you can run
php -S localhost:8000
For the benefit of anyone still looking up this question: To install PHP without Apache (either to use on its own or with nginx) you have to install FPM directly rather than installing just "php". So just use this:
apt install php-fpm php-cli
(Yes, it's obnoxious that the "php" package assumes Apache.)
And be careful installing some of the PHP module packages; they sometimes try to install Apache as well. (Astonishing that after all these years Ubuntu's PHP packages still try to force the use of Apache mod-php instead of using php-fpm!)
If Apache does get installed against your will, you can purge it with the following (yes, oddly, you have to purge both of these packages):
apt purge apache2 apache2-bin
Also, after installing PHP, always be sure to set the date.timezone option in both /etc/php/7.4/fpm/php.ini and /etc/php/7.4/cli/php.ini (adjust according to the version you've installed).
sudo apt-get --no-install-recommends --dry-run install php
First simulate. I'm not in ubuntu now. If you are happy you can run
sudo apt-get --no-install-recommends install php
php will install a web server to go with it as it defaults to the Apache module first. OP would have to install either the php-cgi package or php-cli package first before trying to install php - however if they install php-cgi or php-cli they'll get all the PHP common dependencies anyways which does not include a web server.
– Thomas Ward
Jul 23 '19 at 19:43
sudo apt install phpwill do. – pLumo Jul 23 '19 at 14:29php-cliwill give you thephpcommand on command line to run PHP scripts, butphp-fpmorlibapache2-mod-php7.2(the most commonly installed PHP package in Ubuntu for Apache PHP support, hence why just doingapt install phpinstalls Apache and that package) will give you a PHP web backend system. We need more details to properly answer you. – Thomas Ward Jul 23 '19 at 14:40php-cliand then launch PHP via a similar command like in the answer below. By default, though, PHP has no Web Server set up for it - this is why you need Apache or nginx+php-fpm to get to a web backend for PHP. – Thomas Ward Jul 23 '19 at 14:58