Public service announcement:
Don't ever use chmod 777 to fix problems
It's a security risk if you run any services available to the public,
especially web applications (eg PHP).
The OS's security model assumes that many services (such as your
web server) run with reduced privileges, preventing them being able to modify files. Setting 777 on files breaks that secure design.
A remote user could write to or upload files and then trick the server (or some other process on your system) into reading or executing them. Scripts or software may have flaws that allow this. It's very difficult to be sure you have locked down every single way this could happen if there are world-writable directories.
Used in certain system directories (/usr, /etc, /var, and so on), it can break your system in surprising ways.
Some essential system files need special permissions such as setuid/setgid permissions in order to run. For example, sudo. Avoid changing any file permissions on directories and files set up by the system itself.
There's no way to undo it and get back all the old permissions.
That is, if you had files and folders with various different permissions before, there's no way to go back to those specific permissions - only to change them all to the same thing, which may lose any specific permission settings that were needed on specific files.
There is always a more appropriate way of achieving what it is you want to achieve.
The default setup Ubuntu (and other OSes) use of running the web server as an unprivileged user and having the website files world-readable is a reasonable secure choice and in the interests of consistency, shouldn't be varied unless necessary. So, to ensure that the unprivileged server process can read your website files they will need to be world-readable.
Giving world-writable permission is way more than you need to do.
When tracking down why the web server process can't read your files, remember that not only do the files themselves need to be world-readable (eg, 644) their parent directories should be world-readable and traversable (eg, 755). Set your home directory to something like 755, or if you don't want your home directory world-readable, move your www dir outside your home into somewhere like /var/www or /srv).
Note about making files writable:
Occasionally, you need your web server to be able to write to certain files. To achieve this, make sure you only allow write permission on the specific files you want to give that permission for, and it's still better to use group ownership and group-write bit to give that permission that make them world-writable.