Basic knowledge of the Linux command line is key if you want to have any luck setting up a system to display your PHP code. Though on Windows and Mac (and Linux) you can install a desktop application that will basically do it all for you:
We don’t recommend it for pro development. XAMPP is cool if you’re learning PHP. Fine. But we’re assuming the readers of these tutorials are serious about getting their application production ready. So again, if you want to just get practicing PHP, XAMPP may be for you. Go install it. It’s really easy.
For everyone else, lets continue delving into the base requirements (i.e. most common commands) you need to know to run a professional Ubuntu setup (note: I actually started with XAMPP myself).
To navigate around directories use “cd” like this:
# cd /var/www
That will take you to the /var/www directories.
# cd ..
will take you one directory lower back to /var. And when in /var if you type
# cd www
that will take you back to /var/www. I.e. when you’re in a directory you can move to its sub-directories by simply typing its name after “www” rather than the complete path.
To edit files in a text editor, type:
# vim filename
To move files type:
# mv /var/www/file-name /var/file-name-moved
That will move the file name and change its name. To simply change the name of a file of your current working directory type:
# mv file-name new-file-name
To copy a file in a similar way type:
# cp /var/www/file-name /var/file-name-copied
To delete a file type:
# rm file-name
or if not in the current working directory:
# rm /var/www/file-name
To extract a gzipped archive (i.e. the most popular archive format on linux) type:
# tar -xzvf archivename.tgz -C result-folder-name
To compress a directory and all its sub-directories and files type:
# tar -czvf archivename.tgz input-folder-name
The extract and compress commands are so important because so often you’ll download compressed libraries of code you want to use, and of course you often want to back stuff up. It’s clearly the equivalent of unzipping and zipping up folders/files on your Mac/Windows desktop computer that you’ve been used to doing.
The next very important skill is being able to change permissions of your files and folders. For example, often you’ll want your files accessible by Apache, or more specifically the Apache user group, which is called “www-data”. And of course you’ll often want to protect files for security reasons. Here’s how you change the group that owns a directory and all its sub-directories and sub-files:
# chgrp -R www-data yourfolder
And to change the user do this:
#chown -R root yourfolder
The -R specifies to do it recursively, i.e. to get all the sub-folders and the sub-folders’ sub-folders and so on. Look up what “recursion” is some time: http://en.wikipedia.org/wiki/Recursion . It’s an extremely important programming concept.
Next, now that you have groups and users that own your files, you can adjust the permissions of these files like this:
# chmod -R 777 yourfolder
That will give all users, groups and the public read/write access to the file. To give just the user owner read/write access type:
# chmod -R 755 yourfolder
The first number corresponds to the permission of the owner, the second the group, and the 3rd the plug. 7 is the most loose permission and 5 is tighter. 6 is in between obviously. There is also an alternate sytax for creating such permissions. Google “Chmod tutorial” some time to learn more.