How to install WordPress locally with Vagrant/WordPress

Local development is one of the best things it can happen to you It not only allows you to distribute with upload/download time, you can create as many projects as you want, work with real domains locally and in general speed up everything you do.

Vagrant is a great piece of software create reproducible and portable virtual machines which you can use as a local web server environment. In this article I will show you why Vagrant is so great and how you can get up and running with a great WordPress test environment pretty quickly.

You may also be interested in the following articles:

  • Install WordPress via command line
  • Install WordPress locally with ServerPress
  • Set up WordPress using OpenShift
  • 10 Most Common WordPress Mistakes

What is a vagina?

In Vagrant parlance, it can be used to “create and configuration light, reproduceand handed development environment”. Find out what each of those terms mean, relative to your local environment.

Configuration:

Your virtual machine is easy to create, easy to configure, and more importantly: it can widely configuration. The default setting is just fine for most projects and normal testing, so you don’t yes to fiddle with it but if you need power, it’s there.

You can set up everything just like you would in a real server environment; from configuring IPs to automatically installing git and other software, it’s all possible and up to you.

Light:

I run multiple virtual machines on my computer, each with two configuration files with a combined size of no more than 4KB – That’s right, 2 files in total, 4KB. To be honest, my setups are all pretty basic but even if you have something extremely elaborate it will amount to 10-100KB Most.

Mobile:

Portability comes with the fact that the file has a tight waistline. One is a special Vagrantfile, the other is a bash file; each contains plain text, nothing special. As a result, you can send emails back and forth, saving them on Evernote, Google Drive, or Dropbox.

Reproduce:

This is one of the best features of Vagrant. Due to the size and portability of the required files, specific server configurations can be replicated easily. Let’s say you create an application that requires a highly tuned server. Create a Vagrantfile and an installation bash file for it and start it.

You can now email the configuration to your team members and they will run the same server within a few minutes.

Setting

In general, there are three parts to getting started with a development environment using Vagrant.

  • Install Vagrant & Virtualbox
  • Create server configuration
  • Create your web environment (e.g. install WordPress)

Install Vagrant

Vagrant can be installed by going to the download page, selecting your OS and running the downloaded package. Since Vagrant relies on virtualization, you will need virtualization software. Vagrant has built-in support for VirtualBox but can be made to work with others, but for this example we will use VirtualBox. Get it here.

Create server configuration

You can use ready-made scripts to do everything for you. Jeffrey Way has put together a great guide on ditching MAMP and using Vagrant instead. Take a look and make sure to document the code at the top:

curl -L -o 'install.sh' http://bit.ly/1hBfq57 && curl -L -o 'Vagrantfile' http://bit.ly/1mE3Qt9 && mơ hồ

If you create a directory, navigate to it using the terminal or command prompt, and paste the code above, you’ll create a local environment in one quick move. Let’s dissect this and see what’s going on.

Read More:   Top 10 Female Bodybuilding Blogs and Websites in 2021

It includes 3 parts:

cuộn tròn -L -o 'install.sh' http://bit.ly/1hBfq57

This order Download pre-installed files: the cài đặt file responsible for installing and configuring software while the virtual machine is running. PHP, Apache, MySQL and the like are taken care of here.

cuộn tròn -L -o 'Vagrantfile' http://bit.ly/1mE3Qt9

This will Download Vagrantfile which contains information about server configuration and other basic installation instructions. This determines the operating system the server uses, the network IP it is mapped to; it can be used to control file permissions and ownership and more.

mơ hồ lên

This order start the server.

When you do this for the first time, it will take about 5-20 minutes. The so-called “box” needs to be downloaded (this example contains the OS), probably around 700+ MB. Then the server is provisioned (installed and configured) and should be up and running..

If you restart your computer or shut down the virtual machine (VM), you will need to run the command again. This time it will only take a few seconds for it to run.

In a nutshell, this is very similar to installing your operating system and environment on a computer. Vagrantfile assumes responsibility of Windows/Linux/Mac installation disk; it has everything needed for the underlying system to work. The install.sh file automates the initial software needs. For your computer, this is like installing the latest video driver, Photoshop, your favorite text editor, browser, etc.

The mơ hồ lên command is similar to turn on your computer. When you do this for the first time it will take quite a while as you will need to install the OS and software. Then it takes 10-20 seconds to get up and running.

Install WordPress

If you followed the instructions here you should now have a working server, but what can you do with it, how can you use it?

Here are a few things to know:

  • You can reach the local environment through http://192.168.33.21
  • The html the directory in the installation directory is your root directory
  • Access your MySQL database as follows: user name: source, Password: root and Host: localhost.

The first thing we should do is use SSH to gain access to our server so that we can set up our database, getting it ready for WordPress.

Use the terminal to go to the directory where you installed your virtual machine and type ssh mơ hồ.

When you enter, you can enter mys -uroot -p to get access to MySQL, type nguồn gốc when prompted for a password.

All we need is a simple empty database for WordPress which we will create with the following command: TẠO RA cơ sở dữ liệu

Next, visit the WordPress download page and get the latest version. Extract it in html folder (root folder) and make sure to move all files from created file wordpress Level up subdirectories.

In the end you will see two WordPress folders (wp-admin, wp-includes) and default WordPress files right inside of you html category.

Detour: Troubleshooting

If you follow these instructions, you will find that you cannot upload files through the WordPress interface. This has to do with user and group problems can be easily repaired.

Read More:   Tweak Windows XP Settings with TweakUI / Windows XP

SSH into the server and type the following sudo vi /etc/apache2/apache.conf. This will open the VI editor that you can use to edit this file.

Type /Người dùng. This searches the document for the occurrence of “User”. You will see a section where you can define users and groups.

press “me” to enter Edit mode. Use arrow keys to navigate with pointer and user editing and the “vague” group, like this:

 Nhóm người dùng vagrant

Once done, press esc, then type the following command: : wq. This will save the file and exit the vi editor.

Now you should type dừng lại to stop the virtual machine, followed by mơ hồ lên to restart it.

That’s it, file manipulation should work in WordPress.

At this point, you can go to http://192.168.33.21 and install WordPress as usual. Make sure to use the above database credentials and the database name you created. You can install plugins, themes, create your own code and do anything else you would normally do on a real server.

Change server name

http://192.168.33.21 is not exactly the most user-friendly way to open a project. Fortunately, it’s easy to change this to something easier to remember, such as http://wordpress.local.

SSH into the server and navigate to the site configuration directory by typing cd / etc / apache2 / site-Available.

Type ls to list the contents of the directory. You will see a file named 000-default.conf. Let’s edit this file to see what it contains by typing sudo vi 000-default.conf.

press “me” to enter Insert mode and navigate down to line 8 will say #ServerName www.example.com. Using the ServerName directive you can create a named route to a website.

Uncomment it by removing the hash at the beginning and changing the hostname to whatever you want. It’s customary to use something like wordpress.dev, wordpress.local or maybe even just wordpress – it’s up to you. In fact, you can even use facebook.com!

Save the file by pressing escape and typing : wq issue the command and restart the server by typing sudo dịch vụ apache2 khởi động lại.

Finally, outside of your virtual machine (make sure you are Not SSH-d in) edit your hosts file using sudo vi command. On Windows, this can be found at C: windows system32 driver etc hostson linux-based systems it can be found at / etc / host

Add the following line to the file anywhere:

192.168.33,21 wordpress.local

Make sure to use the hostname you defined in the config file and save the hosts file. This file is basically tell our computer where to load the hostname and how to resolve it. By default, your computer will look to the Internet. If you type in facebook.com, it will load it from the web.

However, if you linked facebook.com to the virtual machine IP and defined it as Hostname it will load locally.

You can now type wordpress.local and see the same results as if you typed 192.168.33.21.

If you do this after you install WordPress, you may see things like broken styles and scripts. The reason is that WordPress stores the install target location in the database and it will be set to the IP.

To make sure this doesn’t happen, you should create your named server first and install WordPress by going to wordpress.local (or any other name you chose) instead of using IP.

Read More:   How to Install a Network Printer on Your Home or Office Network / Windows XP

Use a virtual server

Now we are doing fine but since now we will have to run one virtual machine per project which is a waste. By use virtual server you can run as many standalone sites as you want from the same virtual machine.

The key to this lies in site configuration file, the same file we used to change the Hostname. Let’s create two virtual servers now.

First, go to the folder where you created the virtual machine and create two subfolders: blog and store. Your original html folder is still there.

Next, SSH into the server and navigate to / etc / apache2 / các trang web có sẵn category.

Create two new files by copying the default configuration file:

cp 000-default.conf blog.conf; cp 000-default.conf store.conf

Editing cửa hàng file using the method we discussed before. Make sure the Hostname is set to shop.dev and set the DocumentRoot directive to / var / www / cửa hàng – this is the folder we just created.

Do the same with blog.conf file, use the correct values.

Use sudo a2ensite blog and cửa hàng sudo a2ensite commands to activate these pages and use sudo dịch vụ apache2 khởi động lại command to restart server and exit SSH connection using lối thoát hiểm command.

Now let’s edit the hosts file to make sure our computer knows how to deal with virtual hosts:

 192.168.33,21 blog.dev 192.168.33,21 shop.dev

You now have two more sites to work with: one can be accessed by typing blog.dev in the URL bar, and the site’s root directory will be the blog directory. The other is the shop.dev site that uses the shop directory as the root directory.

This is much easier than creating multiple virtual machines and will require less resources to be used from your computer.

Conclusion

We went through a lot in this article: we installed Vagrant, learned how to create a local environment, and installed WordPress. We also learned a few tricks like using hostnames and virtual hosts.

This will get you started on the path to local development. Don’t forget that you can easily recreate your environment anywhere, all you need is the Vagrantfile and the install.sh file.

Do more!

We’ve only scratched the surface of what Vagrant can do. You can find custom boxes for working with Vagrantcloud, or you can even look for boxes that will mimic your actual online server environment.

A lot of tasks can be automated and/or customized, and you can use automation tools like WP-CLI to install WordPress and related plugins/themes with a few commands.

Finally, take a look at some of the WordPress-specific Vagrant environments like VCCW, Vagrantpress, and 13 Vagrant Resources from WPTavern.

Last, Ched All sent you details about the topic “How to install WordPress locally with Vagrant/WordPress
❤️️”.Hope with useful information that the article “How to install WordPress locally with Vagrant/WordPress
” It will help readers to be more interested in “How to install WordPress locally with Vagrant/WordPress
[ ❤️️❤️️ ]”.

Posts “How to install WordPress locally with Vagrant/WordPress
” posted by on 2023-01-17 16:47:03. Thank you for reading the article at Chedall.com

Check Also
Close
Back to top button