Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AlenV's avatar
Level 1

Execute php script with axios

Is there a way to execute php script with axios? This is what I am trying and it gives me back all the code back in response instead of executing.

    axios.get('http://localhost:8080/script.php', {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Allow-Control-Allow-Origin': '*'
                },
                params: {
                    'id': 1
                }
            })
            .then((response) => (
                console.log(response)
            ))
            .catch((error) => (
                console.log(error)
            ))
0 likes
2 replies
davorminchorov's avatar

Why are you executing that script? Isn't it easier if you just run the code when the request gets to that route?

MaverickChan's avatar

if you are using a php framework like laravel , you need to give a uri or route url , instead of a php filename .

can you execute the php file directly from php server side?

Please or to participate in this conversation.