How to create php files in /var/www folder?

58,387

Open /var/www/

cd /var/www/

Create the file

sudo touch hello.php

Open the file

sudo vi hello.php

Enter write mode (we were in command mode initially) by pressing a (note that vi is case sensitive)

After that, press Esc (to change to command mode) and type :wq. Check if everything is fine with cat hello.php.

However, it's probably a better idea to use editors such as vim or nano as work with them is a lot simpler than that.

Share:
58,387

Related videos on Youtube

Sri
Author by

Sri

Updated on September 18, 2022

Comments

  • Sri
    Sri over 1 year

    I am new to Ubuntu(Linux) and I am trying to create a php file in /var/www, file name hello.php. I am typing vi hello.php and then I write my code <?php......?>, however, when I am trying to save the file by :wq, I get an error and no file by the name of Hello.php is created..

    • david6
      david6 over 9 years
      Try using vim instead, unless you are completely unable to load/install any software. sudo apt-get install vim build-essential
    • smali
      smali over 9 years
      what error you are getting?
    • Melebius
      Melebius about 4 years
      @david6 vi is a synonym of vim in Ubuntu.
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy over 9 years
    Isn't vim comes in the default install of Ubuntu, and vi is just a sim-link to it?
  • karel
    karel over 9 years
    In Ubuntu 14.04, vim comes in the default installation of Ubuntu server, but vim doesn't come in the default installation of Ubuntu desktop. Source: releases.ubuntu.com/14.04
  • Vinit Kadkol
    Vinit Kadkol about 4 years
    Go to the folder root$: cd /var/www/html create file sudo touch hello.php check your file in the list by typing "ls" root$:/var/www/html$ ls edit the file and save root:/var/www/html$ sudo nano hello.php