SSL with VagrantPress – closingtags </>
Categories
PHP Plugins Themes WordPress

SSL with VagrantPress

I’m trying to be a better developer. And somewhere in the vastness of the internet, someone told me I should be using Vagrant. So I did. It was cool and I liked it, but then I found out about VagrantPress and it got even easier. You just clone that repo, and start working. Pretty simple really.

But the other day, I was working on something that required an HTTPS connection, and I thought you should know how to do this with VagrantPress.

Firstly, startup your machine and login via SSH:

vagrant up
vagrant ssh

We’re going to need to do a few things with the SSL certificates, but I promise it’s painless.

sudo make-ssl-cert generate-default-snakeoil --force-overwrite
sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo service apache2 reload

Credit for these handy commands goes to vtalbot here. Then, we need to edit a few files.

sudo nano /etc/apache2/sites-enabled/default-ssl.conf

Change the DocumentRoot /var/www/html to /vagrant/wordpress. Then we need to tell apache that it’s ok to share that directory so run this command:

sudo nano /etc/apache2/apache2.conf

and scroll waaaay down to all of the directives that look like

<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>

and create another one that looks like this

<Directory /vagrant/wordpress/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

After all of that, run

sudo service apache2 reload

Also, you’ll want to make sure your .htaccess file looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

The final step then is to navigate to your WordPress settings > General, and change both URLs to be HTTPS instead of HTTP.

And that should be all there is to it! You should now be able to access https://vagrantpress.dev/ and https://vagrantpress.dev/wp-admin/ problem free. Of course, your browser will probably tell you the connection isn’t trusted, but that’s just because you’re not using a signed SSL certificate.

The next step might be to go and change the URL in the WordPress settings, fiddle with your .htaccess if you want to force the SSL connection but for basic development purposes, this should get you where you need to go.

By Dylan Hildenbrand

Dylan Hildenbrand smiling at the camera. I have tossled, brown hair, rounded glasses, a well-trimmed and short beard. I have light complexion and am wearing a dark sweater with a white t-shirt underneath.

Author and full stack web developer experienced with #PHP, #SvelteKit, #JS, #NodeJS, #Linux, #WordPress, and #Ansible. Check out my book at sveltekitbook.dev!

Do you like these posts? Consider sponsoring me on GitHub!

2 replies on “SSL with VagrantPress”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.