First LAMP environment construction (Linux)

I'm finally (sparsely) around the infrastructure, I tried to build a LAMP environment to overcome it, so it is a memorandum.

【environment】 ・ A 2-week trial server borrowed from Sakura's VPS ・ CentOS8 ・ MariaDB ・ PHP

【Caution】

What is LAMP?

LINUX  OS ** Apache ** web server ** MySQL / MariaDB ** database ** PHP, Perl ** program Happy set.

It's like a classic figure that creates a dynamic site.

Apache

Install Apache!

We use the popular web server Apache. https://httpd.apache.org/

Install with the following command.

$ sudo yum -y install httpd

The Apache configuration file is /etc/httpd/conf/httpd.conf. If you look at this file, you can see that the setting file is written in the format of setting item name setting value. Those starting with "#" are commented out.

Let's edit the ** Server Name ** item below. This is an item for setting the web server name.

$ sudo vim /etc/httpd/conf/httpd.conf

The ServerName is commented out, so remove the "#" to enable it. Basically, it seems to describe the host name here.

ServerName www.example.com:80

When you are done, check the syntax with the following command.

$ httpd -t

If Syntax is OK, it's okay. If it fails, an error message will appear, so make corrections referring to it.

Apache startup settings

$ sudo systemctl start httpd.service
$ sudo systemctl enable httpd.service

It is a command to set to start automatically when the system starts with start and enable.

Apache initialization

First, set the firewall. Initially, access to number 80 is not allowed.

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --reload

Reloading is completed after setting with the above command.

You can open the initial Apache page with http: // VPS IP address /.

.. .. .. .. I had a hard time not opening here. Sakura's VPS people should be careful. By default, Sakura's VPS has a service called "packet filter". If you do not allow number 80 here, it will be played even if the firewall settings are allowed.

Click here Control Panel After logging in, click the Packet Filter tab. Add the connection permission port. This explanation was easy to understand. https://vps-news.sakura.ad.jp/vps-pf/

If the initial page is displayed without any problem, please try arranging various html. If you place html directly under / var / www / html, it will be viewable according to the routing.

MariaDB

MariaDB installation

Next is the database.

$ sudo yum -y install mariadb-server mariadb

The above will download the complete set of things you need for mariaDB. Next, edit the configuration file so that it can handle Japanese.

$sudo vim /etc/my-cnf
datadir=/var/lib/nysql
socket=/var/lib/mysql/mysql.sock

Since there is a description like the above at the beginning, please add the following immediately after.

character-set-server=utf8

MariaDB startup settings

$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb

As with Apache, set it to start automatically.

MariaDB initial settings

MariaDB comes standard with interactive commands for initial setup.

$ sudo mysql_secure_installation

Basically you can answer with y, but On the way, you will be asked to set a password with New password:. Enter the character string you want to use as the administrator password.

PHP Next is the installation of PHP, the programming language.

sudo -y install php php-mbstring php-gd php-mysql

There are a lot of things, so I will summarize them roughly. -** php ** ・ ・ ・ PHP itself -** php-mbstring ** ・ ・ ・ Package for multi-byte support such as Japanese -** php-gd ** ・ ・ ・ Package for handling image library -** php-mysql ** ・ ・ ・ Package for linking with MySQL / MariaDB

If you hit the following and the version comes out, you have successfully installed it.

$ php -v

You also need to restart Apache once to get Apache and PHP working together.

$ sudo systemctl restart httpd.service

php operation check

To check if PHP is working properly, create and edit the file with the following command.

sudo vim /var/www/html/test.php

test.php


<?php echo phpinfo(); ?>

Go to http: // VPS IP address /test.php on the web and It's OK if PHP information comes out safely. After checking, please delete test.php for security.

DB preparation for wordpress

First, connect to MariaDB.

$ mysql -u root -p

You will be asked for the password, so I set it when executing the mysql_secure_installation command. Enter your password.

Once the database operation is possible, use the SQL language to create the database user.

CREATE DATABASE db;

Create a database called "db" above.

GRANT ALL PRIVILEGES ON db.* TO "dbuser"@"localhost" IDENTIFIED BY "jfei0a3laas";

Set the user "dbuser" and the password "jfei0a3laas" above. These are optional.

FLUSH PRIVILEGES;

Reload the permission table above.

If the command input is successful, Query OK will be displayed. After entering all of the above, enter ʻexit` to exit MariaDB.

Place Wordpress

Finally install wordpress.

$ curl -LO http://ja.wordpress.org/latest-ja.tar.gz

Unzip and unpack the installed tar.gz data.

$ tar zxf latest-ja.tar.gz

Move these installed to / var / www / html Make it viewable.

$ sudo mv wordpress /var/www/html

Use the following command to set the right holder. With the -R option You can change the right holder of the files under wordpress at once.

$ sudo chown -R apache:apache /var/www/html/wordpress

Below, wp-config is generated from the template.


$ cd /var/www/html
$ sudo mv wp-config-sample.php wp-config.php

Edit wp-config.

$ sudo vim wp-config.php

There are three changes below.

Database name define ('DB_NAME','/ * enter here * /');

username define ('DB_USER','/ * fill in here * /');

password define ('DB_HOST','/ * fill in here * /');

Originally it is not good for security, but Disable SELinux for study purposes. (Wordpress will not work if it is enabled)

sudo setenforce 0

If you access the route where wordpress is placed, you will see the familiar wordpress screen. You did it!

What I used as a reference

[Linux server construction / operation guide starting from scratch How to make a web server to learn while running](amazon.co.jp/ Amazon.co.jp/ Linux server construction / operation guide to start from zero-How to make a web server to learn while running-Nakajima- Nowa / dp / 4798146374)

How to use the packet filter [What is the lamp environment? Benefits of building a lamp environment](https://forthewin.co.jp/ikeda_blog/lamp%E7%92%B0%E5%A2%83%E3%81%A3%E3%81%A6%E4%BD% 95% EF% BC% 9Flamp% E7% 92% B0% E5% A2% 83% E3% 82% 92% E6% A7% 8B% E7% AF% 89% E3% 81% 99% E3% 82% 8B% E3% 83% A1% E3% 83% AA% E3% 83% 83% E3% 83% 88) Mysql related memorandum Qiita

Recommended Posts

First LAMP environment construction (Linux)
Linux environment construction
About Linux environment construction (CentOS)
Linux environment construction (on WSL environment)
About Linux environment construction (VMware VirtualBOX)
[Linux] Docker environment construction on Redhat
Django environment construction
DeepIE3D environment construction
Emacs-based environment construction
Linux (CentOS) construction
Environment construction (python)
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Deployment method (2) (EC2 environment construction / Linux / MySQL settings)
First python ① Environment construction with pythonbrew & Hello World !!
Environment construction: GCP + Docker
Django project environment construction
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
Linux PATH environment variable
pyenv + fish environment construction
python2.7 development environment construction
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Anaconda environment construction memo
Golang environment construction [goenv]
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Anaconda environment construction on CentOS7
Django development environment construction memo
SSH restrictions in Linux environment
What are environment variables? (Linux)
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
Build a LAMP environment [CentOS 7]
[Memo] Construction of cygwin environment
ML environment construction with Miniconda
Python environment construction For Mac
Anaconda3 python environment construction procedure
Docker + Django + React environment construction
Anaconda3 × Pycharm environment construction memo
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
NumPy and matplotlib environment construction
Machine learning environment construction macbook 2021