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,662
- 2
- 20
- 39
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
Install a more user-friendly text editor with many additional features.
sudo apt-get install vim
vim 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?.

- 114,770
-
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
sudo apt-get install vim build-essential
– david6 Dec 22 '14 at 07:13vi
is a synonym ofvim
in Ubuntu. – Melebius Feb 11 '20 at 10:57