To build a website using PHP to execute Rscript. Errors like: there is no package called "XXX". This is probably due to the apache2 server can not access user installed R packages. Only packages installed in non-user directory /usr/local/lib/R/site-library, /usr/lib/R/site-library or /usr/lib/R/library is accessible to apache2. The solution is to change default package installation directory. Check default directory is R command: > .libPaths() . To change the default directory is by editing file /etc/R/Renviron and comment out R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.3'}. Now all new packages will be installed in /lusr/local/lib/R/site-library, which is accessbile to apach2 Rscript. Of course sudo permission is required when installing new packages.