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,743
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
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 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?.
- 122,292
- 133
- 301
- 332