Change language

How do I execute PHP code using the command line?

Install PHP for Windows Users:Follow the instructions for installing PHP on Windows.
  • Step 1:First, we have to download PHP from the official site . We have to download the .zip file from the appropriate section depending on the architecture of our system (x86 or x64).
  • Step 2:Extract the .zip file to the desired location. It is recommended to select the boot drive (C drive) inside a folder named php (i.e. C: / php).
  • Step 3:Now we need to add a folder (C: / php) to the path of the environment variable to make it available from the command line. To do this, right-click the My Computer or This Computer icon, and then select Properties from the context menu. Then click on the Advanced System Settings link and select Environment Variables. In the System Variables section, we have to find the PATH environment variable and then select and edit it. If the PATH environment variable does not exist, we must click New. In the Edit system variable (or new system variable) window, we have to specify the value of the PATH environment variable (C: / php or the location of our extracted php files). After that we have to click OK and close all the remaining windows by clicking OK.
  • Install PHP for Linux users:
    • Linux users can install php using the following command.
      apt-get install php5-common libapache2-mod -php5 php5-cli 
      It will install PHP with Apache server. For more information click here .
      • Install PHP for Mac users:
        • Mac users can install php using the following command.
          curl -s https://php-osx.liip. ch / | bash -s 7.3 
          It will install php on your system. For more information click here .
          • After installing PHP, we are ready to run the PHP code via the command line. You just follow the instructions to run the PHP program using the command line.
            • Open a terminal or command prompt window.
            • Change to the specified folder or directory where the php files are present.
            • Then we can run the php code with the following command:
              php file_name.php 
            • We can also start the server to test php code using the command line with the following command:
              php -S localhost: port -t your_folder / 
            Note.When using the built-in PHP server the PHP file name inside the root folder should be index.php, and all other PHP files can be hyperlinked through the main index page.


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method