I built a LAMP environment with Sakura VPS for learning, so I will summarize the procedure.
OS : macOS Mojave 10.14.6
VPS OS : centOS
Visit Sakura's website> VPS> Free trial for 2 weeks
Add the server to the cart and apply.
Log in with the ID and password provided in the email and log in to the VPS control panel.
Settings> OS installation
This completes the process from applying for Sakura VPS to installing the OS.
Next, I will summarize the procedure for setting up an SSH connection to connect to a VPS on the Internet from a local PC.
Start Terminal with your MAC.
Then connect with the following ssh command. The password was entered when the OS was installed.
$ ssh root@IP address of VPS
$ yum update
$ adduser jun1 #user added
$ passwd jun1 #password setting
Set to use sudo
$ visudo
wheel ALL=(ALL) ALL #Uncomment
Add jun1 user to wheel group
$ usermod -aG wheel jun1
$ groups jun1
jun1 : jun1 wheel
Check if you can log in with jun1
$ ssh jun1@IP address of VPS
$password input
Start and run the terminal on your local PC
MAC$ ssh-keygen -t rsa -v
MAC$ ls ~/.ssh
config id_rsa id_rsa.pub known_hosts
Connect to VPS with ssh
VPS$ mkdir .ssh
VPS$ chmod 700 .ssh
Transfer public key from local PC to VPS
Local PC
MAC$ scp ~/.ssh/id_rsa.pub jun1@IP address of VPS:~/.ssh/authorized_keys
MAC$Enter VPS password
Log in to the server using the key
Local PC
MAC$ ssh -i ~/.ssh/id_rsa jun1@IP address of VPS
VPS
$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ort #Backup of configuration file
$ sudo vim /etc/ssh/sshd_config
Search for Port, delete #, 22-> 56789 (any number is acceptable)
Search for PasswordAuthentication and Change to no
Search with PermitRootLogin and change to no
VPS
$ sudo sshd -t #Check the configuration file for syntax errors.OK if nothing comes out
$ sudo systemctl restart sshd #Restart sshd
VPS
$ sudo cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh-56789.xml
$ sudo vim /etc/firewalld/services/ssh-56789.xml
Change port number to 22-> 56789
VPS
$ sudo firewall-cmd --reload
>success
$ sudo firewall-cmd --permanent --add-service=ssh-56789
>success
$ sudo firewall-cmd --reload
>success
$ sudo firewall-cmd --list-all
>ssh-56789
Open another tab without closing the terminal opened above
MAC
$ ssh -p 56789 -i ~/.ssh/id_rsa jun1@IP address of VPS
VPS
$ sudo firewall-cmd --permanent --remove-service=ssh
$ sudo firewall-cmd --reload
Finally, just in case, check if you can connect with ssh
MAC
$ ssh -p 56789 -i ~/.ssh/id_rsa jun1@IP address of VPS
VPS
$ sudo yum install httpd
VPS
$ sudo systemctl start httpd
$ systemctl status httpd
#Check if it is displayed as Active
VPS
$ sudo firewall-cmd --add-service=http --zone=public --permanent
$ sudo firewall-cmd --add-service=https --zone=public --permanent
$ sudo systemctl restart firewalld
Sakura VPS Control Panel> Settings> Packet Filters> Allow WEB
Enter the IP address of the VPS in the browser, and if the following test page is displayed, it is OK
VPS
$sudo systemctl enable httpd
Change ownership of the document root to apache.
VPS
$sudo groupadd web #Creating a group
$sudo usermod -aG web jun1 #Add user to group
VPS
$sudo chown apache:web /va/www/html/
$sudo chmod -R 775 /var/www/html/
VPS
$ vim /var/www/html/index.html
#Edit and save as appropriate
Open from a browser and check
This time, register as a member of the value domain and purchase.
Log in to your value domain and set up your DNS Check the details from each domain site.
Value domain setting screen
a VPS IP address
Enter the domain in the browser and check if it is displayed
Install two repositories.
epel repository (Linux repository) remi repository (PHP repository)
VPS
$sudo yum repolist
#If there is no epel repository, execute the following
$sudo yum install epel
Copy the remi repository URL from your browser
VPS
$sudo yum localinstall remi url
Check the version that can be installed
VPS
$ yum list available | grep php-
Check php71-common.x86_64
VPS
$ sudo yum --enablerepo=remi-php71 install php php-devel php-mysql php-gd php-mbstring
Apache restart
VPS
$ sudo systemctl restart httpd
VPS
$ sudo cp /etc/php.ini /etc/php.ini.org #Backup of configuration file
$ sudo vim /etc/php.ini
Change file upload limit
php.ini
post_max_size = 128M #8M -> 128M
upload_max_filesize = 128M #2M -> 128M
Apache restart
VPS
$ sudo systemctl restart httpd
/var/www/html/index.php
<?php
echo 'Hello World';
Enter the domain name in your browser and check index.php
VPS
$ sudo yum remove mariadb-libs
$ sudo rm -rf /var/lib/mysql
Install MySQL 5.7
VPS
$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
$ sudo yum install mysql-community-server
VPS
$ sudo systemctl start mysqld
$ sudo cat /var/log/mysqld.log | grep 'temporary password' #Check the initial connection password
VPS
$ mysql_secure_installation
#Below, set as instructed
VPS
$ mysql -u root -p
#Check if you can log in
Change character code to UTF
VPS
$ sudo vim /etc/my.conf
my.conf
character-set-server=utf8
VPS
$ sudo systemctl restart mysqld
Auto start settings
VPS
$ sudo systemctl enable mysqld
VPS
$ sudo vim /etc/httpd/conf.d/Domain name.conf
Domain name.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName Domain name
</VirtualHost>
Select software and OS from the certbot website
VPS
$ sudo vim install certbot-apache
VPS
$ sudo certbot --apache
Enter the domain name in the browser and check if it is https
VPS
$ mysql -u root -p
mysql> create database myblog;
mysql> create user 'myblog_user'@'localhost' identified with mysql_native_password by 'Any password'
mysql> grant all privileges on myblog.* to 'myblog_user'@'localhost';
mysql> flush privileges;
VPS
$ wget https://ja.wordpress.org/latest-ja.tar.gz
$ sudo tart -zxvf latest-ja.tar.gz
-C /var/www/
#Extract the compressed file
$sudo chown -R apache:web wordpress/
$sudo vim /etc/httpd/conf/httpd.conf
httpd.conf
DocumentRoot "/var/www/wordpress"
<Directory "/var/www/wordpress">
Domain name.conf
DocumentRoot /var/www/wordpress
Domain name-le-ssl.conf
DocumentRoot /var/www/wordpress
Access the domain and check if the following page is displayed
This time, I summarized the contents of learning to build a LAMP environment on Sakura VPS.
I learned Linux commands.
Recommended Posts