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..
- 1,572
- 2
- 19
- 38
- 41
- 1
- 1
- 2
-
Try using **vim** instead, unless you are completely unable to load/install any software. **`sudo apt-get install vim build-essential`** – david6 Dec 22 '14 at 07:13
-
2what error you are getting? – smali Dec 22 '14 at 07:33
-
@david6 `vi` is a synonym of `vim` in Ubuntu. – Melebius Feb 11 '20 at 10:57
3 Answers
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.
- 171
- 1
- 6
-
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 – Vinit Kadkol Feb 11 '20 at 10:40
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
- 101
- 1
Install a more user-friendly text editor with many additional features.
sudo apt-get install vimvim is run from the terminal.
If you have installed Apache HTML Server (apache2), the right location to place your local website is
/var/www/html/. That's where to keep your php files so that you can access them from your web browser. For more information see: Where to place my local website starting with the 2.4.7 version of apache2?.
- 110,292
- 102
- 269
- 299
-
Isn't vim comes in the default install of Ubuntu, and vi is just a sim-link to it? – Sergiy Kolodyazhnyy Dec 22 '14 at 08:59
-
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: http://releases.ubuntu.com/14.04/ – karel Dec 22 '14 at 09:31