How do i run php?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    PHP Installation for Windows Users: Follow the steps to install PHP on the Windows operating system.

    • Step 1: First, we have to download PHP from it’s official website. We have to download the .zip file from the respective section depending upon on our system architecture[x86 or x64].
    • Step 2: Extract the .zip file to your preferred location. It is recommended to choose the Boot Drive[C Drive] inside a folder named php [ie. C:\php].
    • Step 3: Now we have to add the folder [C:\php] to the Environment Variable Path so that it becomes accessible from the command line. To do so, we have to right click on My Computer or This PC icon, then Choose Properties from the context menu. Then click the Advanced system settings link, and then click Environment Variables. In the section System Variables, we have to find the PATH environment variable and then select and Edit it. If the PATH environment variable does not exist, we have to 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 remaining windows by clicking OK.

    PHP Installation 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.

      • PHP Installation for Mac Users:

        • Mac users can install php using the following command.
          curl -s //php-osx.liip.ch/install.sh | bash -s 7.3

          It will install php in your system. For more information click here.

          • After installation of PHP, we are ready to run PHP code through command line. You just follow the steps to run PHP program using command line.

            • Open terminal or command line window.
            • Goto the specified folder or directory where php files are present.
            • Then we can run php code using the following command:
              php file_name.php

            • We can also start server for testing the php code using the command line by the following command:
              php -S localhost:port -t your_folder/

            Note: While using the PHP built-in server, the name of the PHP file inside the root folder must be index.php, and all other PHP files can be hyperlinked through the main index page.

            PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

    Could anyone please tell me how to run a php file locally on my system.
    Currently I am using a server to run files.
    I know both php & Apache to be installed.
    I need to see out put of this program, for example:

    
    

    Can you please tell how I can run these files of if I need anything more.

    asked Dec 20, 2011 at 18:37

    12

    php have a easy way to run a light server:
    first cd into php file directory, then

    php -S 127.0.0.1:8000
    

    then you can run php

    answered May 10, 2019 at 3:32

    peter zhangpeter zhang

    1,0977 silver badges19 bronze badges

    2

    You have to run a web server [e.g. Apache] and browse to your localhost, mostly likely on port 80.

    What you really ought to do is install an all-in-one package like XAMPP, it bundles Apache, MySQL PHP, and Perl [if you were so inclined] as well as a few other tools that work with Apache and MySQL - plus it's cross platform [that's what the 'X' in 'XAMPP' stands for].

    Once you install XAMPP [and there is an installer, so it shouldn't be hard] open up the control panel for XAMPP and then click the "Start" button next to Apache - note that on applications that require a database, you'll also need to start MySQL [and you'll be able to interface with it through phpMyAdmin]. Once you've started Apache, you can browse to //localhost.

    Again, regardless of whether or not you choose XAMPP [which I would recommend], you should just have to start Apache.

    Pacerier

    82.8k99 gold badges354 silver badges623 bronze badges

    answered Dec 20, 2011 at 18:43

    BhaxyBhaxy

    5,19610 gold badges36 silver badges40 bronze badges

    1

    I just put the content in the question in a file called test.php and ran php test.php. [In the folder where the test.php is.]

    $ php foo.php                                                                                                                                                                                                                                                                                                                                    
    15
    

    answered Feb 6, 2020 at 15:14

    If you have apache running, put your file in server folder for html files and then call it from web-browser [Like //localhost/myfile.php ].

    answered Dec 20, 2011 at 18:40

    ProdoElmitProdoElmit

    1,0676 silver badges21 bronze badges

    1

    3 easy steps to run your PHP program is:

    1. The easiest way is to install MAMP!

    2. Do a 2-minute setup of MAMP.

    3. Open the localhost server in your browser at the created port to see your program up and runing!

    answered Dec 8, 2020 at 6:17

    How do I open PHP in browser?

    Click the button Open In Browser on StatusBar..
    In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser..
    Use keybindings Shift + F6 to open more faster [can be changed in menu File -> Preferences -> Keyboard Shortcuts ].

    How do I run a PHP file locally?

    To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL. There are various web servers for running PHP programs like WAMP & XAMPP. WAMP server is supported in windows and XAMP is supported in both Windows and Linux.

    What do you need to run PHP?

    You'll need at least PHP, MySQL, and a server like Apache or Nginx. MySQL is used to set up databases your PHP applications can work with. Of course, you can choose to work with other database engines, but MySQL is one of the most popular databases used with PHP.

    Does PHP run in browser?

    PHP Is Not Part of Your Browser. And here's where things change from the easy, browser-centric view of the world. When you download a web browser, you get HTML, CSS, and JavaScript, but you do not get PHP. PHP scripts—which you'll soon be writing—have to be interpreted by the PHP interpreter program, called php.

    Chủ Đề