Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP built-in server serving only .php files

Tags:

php

I created a dir named "test", and inside this dir, i created 3 files: 1.jpg, 2.html and 3.php. If i run php -S localhost:80 and try to visit localhost/3.php, it works. But if i visit 1.jpg or 1.html, or any file that is not a php, it gives me a 404 not found error. I'm using PHP 7.1 NTS on Windows 10. I tried with PHP TS and PHP 7.2 but the error persists.

enter image description here

like image 410
André Avatar asked Dec 01 '17 23:12

André


People also ask

What is PHP built-in server?

Built-in web server ¶ This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server.

Can you run PHP files on a server?

On most servers, this is the default extension for PHP files, but ask your server administrator to be sure. If your server supports PHP, then you do not need to do anything. Just create your . php files, put them in your web directory and the server will automatically parse them for you.

Can PHP run locally?

XAMPP is a Web development tool, created by Apache, that makes it easy to run PHP (Personal Home Pages) scripts on your computer locally.

How does PHP work on a server?

Step 1: The client requests the webpage on the browser. Step 2: The server (where PHP software is installed) then checks for the . php file associated with the request. Step 3: If found, it sends the file to the PHP interpreter (since PHP is an interpreted language), which checks for requested data into the database.


2 Answers

The issue may be caused by the accented e in your file path, please test in a different location. Why does PHP built-in web server not serve file called é.txt (on Windows)

like image 196
Jacob Mulquin Avatar answered Sep 28 '22 07:09

Jacob Mulquin


I had a similar problem: my php page would display fine but no other page, including images on the php page would be served. The problem was asking the php development server to serve a specific page:

php -S 127.0.0.1:8000 myPage.php

Rather than:

php -S 127.0.0.1:8000

In the later I have to include myPage.php in the url, but images and other files now display.

like image 29
user1794469 Avatar answered Sep 28 '22 07:09

user1794469