[LINUX] How to build a LAMP environment using Vagrant and VirtulBox Note

Aim to build a LAMP environment using Vagrant and VirtulBox.

Use MAC.

Software to prepare

All free software

・ VirtualBox ・ Vagrant

Virtual machine preparation

The L part of LAMP. First, add a CentOS 7 box.


$ vagrant box add centos/7

Since I am using virtualbox, select "3"

1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 3

Check if the box for CentOS 7 is included.


$ vagrant box list
centos/7 (virtualbox, 1905.1)


$ vagrant box remove centos/7

Create a folder for the virtual machine and move it to the created folder.


$ mkdir CentOS/ 
$ cd CentOS/

Select the added box called centos / 7.


$ vagrant init centos/7
OK if Vagrantfile is created in the folder.

Comment out the following in the Vagrantfile.


config.vm.network "private_network", ip: ""

Start virtual machine

Start a virtual machine


$ vagrant up

Check the status of the virtual machine. If it is running, it is running.


$ vagrant status

Current machine states:

default                   running (virtualbox)

Connect to virtual machine


$ vagrant ssh

OK if the command line looks like this.
[vagrant@localhost ~]$

Now Linux is ready.

If you want to stop the virtual machine

You can stop the virtual machine with the halt command.


$ vagrant halt

If you want to delete a virtual machine

You can delete the virtual machine with the destroy command.


$ vagrant destroy

Switch to root user


$ sudo su

When returning to vagrant user


$ su vagrant

Install apache

Part A of the LAMP environment.


$ sudo yum -y update
$ sudo yum -y install httpd
Check version
$ httpd -v
Server version: Apache/2.4.6 (CentOS)
Installation confirmation
$ rpm -qa | grep httpd

At this point, connect to the IP address and you should see the Apache test screen.
「Testing 123..Is displayed.

If it does not appear, it may be due to the firewalld command. Stop firewalld with the following command, and then try reconnecting.


$ sudo systemctl stop firewalld

Install MySQL

The M part of the LAMP environment.


$ sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
$ sudo yum install -y mysql-community-server
$ sudo yum install -y mysql-devel
$ mysqld --version

Check the startup.


$ sudo systemctl start httpd.service
$ sudo systemctl start mysqld.service
Automatic start
$ sudo systemctl enable httpd.service
$ sudo systemctl enable mysqld.service
status check
$ sudo systemctl status httpd.service
$ sudo systemctl status mysqld.service
Start confirmation
$ ps aux | grep httpd
$ ps aux | grep mysqld

Install PHP

The P part of the LAMP environment.


$ sudo yum -y install epel-release
$ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo yum -y install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt
$ php --version

Visit website

Create index.html under html.


$ cd /var/www/html
$ sudo vi index.html


        <h1>Hello World</h1>

At this point, if you connect to the IP address, you should see "Hello World".

Make PHP compatible with Apache.


$ sudo vi /etc/httpd/conf/httpd.conf

Add the following to httpd.conf.

  AddType application/x-httpd-php .php          //add to
  AddType application/x-httpd-php-source .phps  //add to

Add as follows.


# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
  AddType application/x-compress .Z
  AddType application/x-gzip .gz .tgz
  AddType application/x-httpd-php .php          //add to
  AddType application/x-httpd-php-source .phps  //add to

Create a php file.


$ cd /var/www/html
$ sudo vi test.php


        echo('Hello World');

If you connect to the IP address below and "Hello World" is displayed, it's OK.

Recommended Posts

How to build a LAMP environment using Vagrant and VirtulBox Note
How to build a python2.7 series development environment with Vagrant
How to build a sphinx translation environment
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
[Note] How to create a Ruby development environment
[Note] How to create a Mac development environment
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
How to set up a Python environment using pyenv
Build a LAMP environment [CentOS 7]
How to build a Django (python) environment on docker
How to build a development environment for TensorFlow (1.0.0) (Mac)
How to build a Python environment on amazon linux 2
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Install LAMP on Amazon Linux 2 and build a WordPress environment.
How to build a new python virtual environment on Ubuntu
How to transpose a 2D array using only python [Note]
A note on how to load a virtual environment in PyCharm
Build a Python environment and transfer data to the server
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Build a go environment using Docker
Build a Chainer environment using CUDA and cuDNN on a p2 instance
The simplest way to build a Spleeter usage environment using Windows
How to format a table using Pandas apply, pivot and swaplevel
How to build Python and Jupyter execution environment with VS Code
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
How to split and save a DataFrame
How to draw a graph using Matplotlib
I want to build a Python environment
How to install a package using a repository
How to divide and process a data frame using the groupby function
Build Linux on a Windows environment. Steps to install Laradock and migrate
Build a LAMP environment on your local Docker
Build a LAMP environment in a very short time
How to share a virtual environment [About requirements.txt]
How to create a Python virtual environment (venv)
How to code a drone using image recognition
[Latest] How to build Java environment on Ubuntu
Build a Django environment with Vagrant in 5 minutes
Build a virtual environment with pyenv and venv
How to use pip3 under proxy environment Note
Try using tensorflow ① Build python environment and introduce tensorflow
How to build Java environment on Ubuntu (Linux)
How to upload to a shared drive using pydrive
[TF] How to build Tensorflow in Proxy environment
How to uninstall a module installed using setup.py
[PyTorch] Sample ⑧ ~ How to build a complex model ~
How to quickly create a morphological analysis environment using Elasticsearch on macOS Sierra
How to build an environment for using multiple versions of Python on Mac
Flutter in Docker-How to build and use a Flutter development environment inside a Docker container
A complete guidebook to using pyenv, pip and python in an offline environment
Build a python environment to learn the theory and implementation of deep learning
How to run a Django application on a Docker container (development and production environment)
Install and set Jupyter Notebook to create a study note creation environment [Mac]
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Suddenly I needed to work on a project using Python and Pyramid, so a note of how I'm studying
How to build two CentOS7 environments / Windows10 + VirtualBox + Vagrant
How to write a GUI using the maya command
Build a Django development environment using pyenv-virtualenv on Mac
Build a python virtual environment with virtualenv and virtualenvwrapper
Note: CGI (during trial and error) in Vagrant environment