Aim to build a LAMP environment using Vagrant and VirtulBox.
Use MAC.
All free software
・ VirtualBox ・ Vagrant
The L part of LAMP. First, add a CentOS 7 box.
console
$ 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.
console
$ vagrant box list
centos/7 (virtualbox, 1905.1)
console
$ vagrant box remove centos/7
Create a folder for the virtual machine and move it to the created folder.
console
$ mkdir CentOS/
$ cd CentOS/
Select the added box called centos / 7.
console
$ vagrant init centos/7
OK if Vagrantfile is created in the folder.
Comment out the following in the Vagrantfile.
Vagrantfile
config.vm.network "private_network", ip: "192.168.33.10"
Start a virtual machine
console
$ vagrant up
Check the status of the virtual machine. If it is running, it is running.
console
$ vagrant status
Current machine states:
default running (virtualbox)
console
$ vagrant ssh
OK if the command line looks like this.
[vagrant@localhost ~]$
Now Linux is ready.
You can stop the virtual machine with the halt command.
console
$ vagrant halt
You can delete the virtual machine with the destroy command.
console
$ vagrant destroy
console
$ sudo su
When returning to vagrant user
console
$ su vagrant
Part A of the LAMP environment.
vagrant
$ 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.
http://192.168.33.10/
「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.
vagrant
$ sudo systemctl stop firewalld
The M part of the LAMP environment.
vagrant
$ 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.
vagrant
Start-up
$ 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
The P part of the LAMP environment.
vagrant
$ 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
Create index.html under html.
vagrant
$ cd /var/www/html
$ sudo vi index.html
index.html
<html>
<head></head>
<body>
<h1>Hello World</h1>
</body>
</html>
At this point, if you connect to the IP address, you should see "Hello World".
http://192.168.33.10/
Make PHP compatible with Apache.
vagrant
$ 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.
httpd.conf
# 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.
vagrant
$ cd /var/www/html
$ sudo vi test.php
test.php
<html>
<head></head>
<body>
<?php
echo('Hello World');
?>
</body>
</html>
If you connect to the IP address below and "Hello World" is displayed, it's OK.
http://192.168.33.10/test.php/
Recommended Posts