This tutorial will cover How to run php script from the command line and Run MySQL from the command line in windows, Sometimes we have big file and run through the command line instead of browser.
Therefore, we must use the command line to execute the PHP script. While PHPMyAdmin UI cannot import huge data files, we can import them using the command line from a SQL file to the database.
So, in this section, I’ll talk about how setup MySQL and PHP in Windows using the command line. PHP and MySQL need to be set up on Windows computers.
We can run PHP code from the command line using the following ways. You can use any of them and run a PHP script from the command line.
You can set your application path in the windows environment variable and access that application at root of the window command.
To access PHP from the command line you need to set the PHP path (‘c:\wamp\bin\php\php5.x.x1’) as an environment variable in windows.
When you set this variable you need to check with help of the below command it’s working fine.
php -v
If the above command returns the PHP version, everything is in order; otherwise, reopen the window and check the aforementioned command again.
You can also run PHP script from the command line without setting an environment variable in windows, Sometimes you don’t want to set the environment variable you just need to run your script from the window command window. You need to follow the following steps:
a) To open start>run->cmd window
.
b) go to you php path c:\wamp\bin\php\
and run the below command.
php -v
It will give you php version number if you are on right path.
When you have configured php as command line in windows, You are ready to run php script using below command.
php script.php
Sometimes you will get errors like,
‘file not found on location/not included’
that means you have included the file as a relative path, so you need to be changed relative to an absolute path.
include_once __DIR__ . '/../config.php';
We can run MySQL from command line using following way.You can use any of them and run MySQL from command line.You need to go mysql path (where you have installed mysql) with help of below steps.
a) Open start>run->cmd window
.
b) Go to your MySQL path c:\wamp\bin\mysql\
and run the below command from the command window.
mysql -u user -p
This command will ask root password , enter root password now you have login as root admin on mysql.
c)Now select db
use test
d) Check db is updated.
mysql \r
Now you have connected with 'Test'
db you can run your sql query here.
Sometimes, we need to set a PHP script as a background process in the system. Here, we learn about setting a PHP script in the LINUX system through the command line, it’s very easy to use. We need to run the below command and the script will run as a background process.
nohup php test.php &
the & puts your process in the background.
If you want to stop/kill this PHP script, then you need to run the below command:
kill processid
This quick article explains how to set up PHP on the command line and how to execute PHP scripts from the command line. MySQL is also used via the window command line. MySQL is available for command-line use.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
Thanks for finally talking about >How To run PHP and Mysql Through Command line in windows <Loved it!