Add New Domain

David Herrera edited this page Jan 14, 2014 · 6 revisions

Add a New Domain for WordPress Development

Your Files

The files for your new domain should be located somewhere in {vvv-dir}/www/ for them to be accessible via Nginx on the virtual machine. By default you'll see that directories for a stable WordPress installation— {vvv-dir}/www/wordpress-default/ —and a trunk WordPress installation— {vvv-dir}/www/wordpress-trunk/ —are included. If you would like your own WordPress installation, you should mimic this.

Nginx Configuration

The included configuration for Nginx is located in {vvv-dir}/config/nginx-config/ on your local machine. This directory includes a default configuration for Nginx itself, a common configuration for WordPress sites, and individual site configurations under the {vvv-dir}/config/nginx-config/sites/ directory.

Follow these steps to configure Nginx to respond to your custom domain:

  1. Copy the included {vvv-dir}/config/nginx-config/sites/local-nginx-example.conf-sample to a new .conf file in that same directory such as {vvv-dir}/config/nginx-config/sites/my-custom-domain.com.conf
  2. Edit this file, paying attention to the included examples for server configuration.
    • server_name is that domain that Nginx will respond to in this configuration. The domain entered here should not be entered in any other config file.
    • root is the directory inside the virtual machine where your WordPress installation is located. Files on your local machine in {vvv-dir}/www/ are automatically mapped to /srv/www/ in the virtual machine. The WordPress files for your custom domain should be in a directory such as {vvv-dir}/www/my-new-wp-site/, which will lead to a nginx config of root /srv/www/my-new-wp-site;
  3. At the command line in the {vvv-dir} directory, type vagrant provision. This will cause services to restart so that your domain is accessible.
  4. Edit your local hosts file so that your new domain points to 192.168.50.4

At this point, if a database has been properly configured for WordPress, you can access the site via your browser. If a database has not yet been configured, continue on...

Database Configuration

Setting up a new database for WordPress

If you want to start a WordPress installation from scratch on a custom domain, a fresh database will be needed so that you can go through the installation process.

  1. Copy the included {vvv-dir}/database/init-custom.sql.sample to {vvv-dir}/database/init-custom.sql. This is the file that will control the initial setup of your custom databases.
  2. Follow the example included with init-custom.sql.sample to configure the database name, username, and password that you want to use with your WordPress installation.
  3. Configure the WordPress wp-config.php file to use this new information.
  4. At the command line in the {vvv-dir} directory, type vagrant provision. This will cause the database import script to run, making your database accessible to WordPress.

At this point, if you want to start a WordPress site from scratch, you can access the installer at the custom domain configured in the Nginx section.

If you would like to import a database exported from a previous MAMP setup as an SQL file, see the next section.

Setting up an existing database for WordPress

If you want to setup a WordPress installation using a custom domain that uses an existing database that you have exported from MAMP or elsewhere, be sure to follow the above steps for a new database and then continue.

  1. Copy the SQL file containing your database from MAMP or other source to {vvv-dir}/database/backups/new_database_name.sql
  2. Verify that the name of the SQL file matches that of the new database. If your database is named custom_database, your SQL file should be named custom_database.sql. If these names do not match, it will not work.
  3. At the command line in the {vvv-dir} directory, type vagrant provision. This will cause the database import script to run, setting up any new databases and importing existing data.

At this point, accessing the custom domain setup in Nginx will lead you to a WordPress site containing the data from your SQL export.