I am trying to get Drupal 8 installed on Ubuntu 18.04. I have installed LAMP and composer. I will install Drupal 8 with this (I think this is the latest recommended way) ...

composer create-project drupal/recommended-project my_site_name_dir

Where should my_site_name_dir be?

Some guides suggest it should be at apache2's web directory: /var/www/html/my_site_name_dir. And then change the directory owner to www-data (for apaches benefit?). But how then does Composer or myself write files to this directory if the owner is changed?

This guide Using Composer to Install Drupal says:

Your 'my_site_name_dir' will contain files that should be outside of your web root and not accessible by the web server. The web root will be 'my_site_name_dir/web'

So am I right in thinking that my_site_name_dir should not be visible by apache, but my_site_name_dir/web should be? If so how to I tell apache to find it?

I was imaging that my_site_name_dir would be somewhere in my home directory (easier for dealing with file permissions?) and I would view it in a browser with something like: http://localhost/my_site_name_dir

(I'm struggling a bit trying to grasp file ownership and how composer works.)


1 Answer 1


It all depends on whether your Ubuntu 18.04 machine is intended for use as a local workstation or a web server exposed to the Internet.

If it's your local workstation, you should absolutely just make a sub-directory in your home directory.

I like to keep my projects in ~/repos/clientname/projectname/ directories. I call the directory repos because I recommend always keeping your project in a local git repository and pushing all your changes to a private repository on github/gitlab/bitbucket or wherever. That way you can always pick up work on a new computer if yours crashes.

Your local workstation is probably not (indeed, hopefully not!) the server where you will expose your Drupal site to the Internet. You want a local copy that you can break and fix a dozen times a day without taking the real site offline.

Then, you want a way to serve that to yourself on localhost. Check out my other answer here to see one way of serving the files locally. I recommend Lando for newbies because it manages a lot of the complexity for you, providing Docker containers for web server, database server and other services as needed. And you can easily free up system resources with lando stop and switch to another project with lando start. See my linked answer for more details.

Then you can worry about deploying the site to a production server ... ideally, multiple environments for Dev, Stage (Test), and Prod (Live) environments.

There are many ways to approach this depending on your hosting. Just take things one step at a time, start with local development and work your way up to DevOps concepts like automated testing and deployment.

If your Ubuntu 18.04 installation is intended to be a web server, then you'll want to install a complete LAMP stack and set up the directories as @pinueve suggests in his answer.

There is also a middle ground. You can test deploying your site from the local dev instance in your home directory to the local Apache server, but just be aware that you can run into port conflicts between your Ubuntu host's Apache server and the Docker guest's Apache server if you try to start both at once. This can be mitigated by changing your default Apache ports.

Edit the VirtualHost entries in /etc/apache2/sites-available/000-default.conf and change port 80 to something like port 8080:

<VirtualHost *:8080>

If you do this, you can browse the host machine's Apache on http://localhost:8080 and you will still be able to start and stop your Docker containers with Lando.

  • 1
    Thanks very much for the advice on location. Though I'm not keen on the extra challenge of using lando at the moment. For others finding this question, I found advice on allowing apache to access other directories here: askubuntu.com/questions/337874/… Commented May 21, 2020 at 13:04
  • You don’t have to use Lando. I still think it’s a good idea to keep your project in a git repository, and git ignore Drupal core, contrib, vendor. Then you can clone the repo in another environment and run composer install to rebuild your assets. Note also that if you are working directly in /var/www/html/ you should never run composer as root. Build the project in your home directory, then use sudo rsync to copy the project to /var/www/html. Good luck! Commented May 21, 2020 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.