Hello everyone, I am Internet old xin, this is my 26th day to participate in wen Challenge, the activity details: Wen Challenge

preface

Linux after learning the lamp architecture, you can build your own blog, build your own blog has several advantages:

  1. What you post is up to you, no one else is policing it
  2. Better promotion of personal brand
  3. Free domain name

Yum yum yum yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum If this part is easy for you, there are few techniques that will stick you.

The environment

I use: Huawei Cloud: 2-core 4G cloud server Domain name: www.zmkjedu.cn System: centos7

The architecture used this time is LAMP, which can be upgraded in the future

Building LAMP architecture

Build Apache

1. Install dependency packages
A. Installation environment dependence
[root@ecs-c13b ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel 
Copy the code
B. Compile and install the dependency package APR
[root@ecs-c13b ~]Wget # http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
[root@ecs-c13b ~]# tar xf apr - 1.6.2. Tar. Gz
[root@ecs-c13b ~]# CD apr - 1.6.2[root @ ecs - c13b apr - 1.6.2]# ./configure --prefix=/usr/local/apr[root @ ecs - c13b apr - 1.6.2]# make && make install
Copy the code
C. Install the apR-util dependency package
[root@ecs-c13b ~]Wget # http://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz

[root@ecs-c13b ~]# tar xf apr - util - 1.6.0. Tar. Gz
[root@ecs-c13b ~]# CD apr - util - 1.6.0[root @ ecs - c13b apr - util - 1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config[root @ ecs - c13b apr - util - 1.6.0]# make && make install
Copy the code
D. Install the PCRE dependency package

[root@ecs-c13b ~]# tar xf pcre-8.41.tar.gz [root@ecs-c13b pcre-8.41]# CD pcre-8.41 root@ecs-c13b pcre-8.41]#./configure –prefix=/usr/local/pcre root@ecs-c13b pcre-8.41]#./configure –prefix=/usr/local/pcre

2. Start compiling Apache
A. download apache
[root@ecs-c13b ~]Wget # https://mirrors.aliyun.com/apache/httpd/httpd-2.4.43.tar.gz
Copy the code
B. Decompress and compile
[root@ecs-c13b ~]# tar xf HTTPD - 2.4.43. Tar. Gz
[root@ecs-c13b ~]# HTTPD CD - 2.4.43[root @ ecs - c13b HTTPD - 2.4.43]# 
Copy the code
[root @ ecs - c13b HTTPD - 2.4.43]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=event
Copy the code

Options:

parameter instructions
–prefix=/usr/local/apache The installation path
–enable-so Dynamic loading of modules is supported
–enable-rewrite Support site address rewrite
–enable-ssl Support SSL encryption
–with-pcre=/usr/local/pcre Pcre path
–with-apr=/usr/local/apr Apr path
–with-apr-util=/usr/local/apr-util Apr – util path
[root @ ecs - c13b HTTPD - 2.4.43]# make && make install
Copy the code
C. Configuration files and corresponding directories

Configuration file path: / usr/local/apache2 / conf/HTTPD. Conf site root directory: / usr/local/apache/htdocs /

D. Generate a startup script and start it

root@ecs-c13b ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/ [root@ecs-c13b ~]# chmod +x /etc/init.d/apachectl [root@ecs-c13b ~]# [root@ecs-c13b ~]# /etc/init.d/apachectl restart

E. Set the systemctl startup mode (Startup Method 2)
vim /usr/lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Copy the code

systemctl start apache.service

3. Check whether the system is started
[root@ecs-c13b ~]# lsof -i:80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   1579   root    4u  IPv6  58850      0t0  TCP *:http (LISTEN)
httpd   1580 daemon    4u  IPv6  58850      0t0  TCP *:http (LISTEN)
httpd   1581 daemon    4u  IPv6  58850      0t0  TCP *:http (LISTEN)
httpd   1582 daemon    4u  IPv6  58850      0t0  TCP *:http (LISTEN)
[root@ecs-c13b ~]# 

Copy the code
4. Test on the browser

Source code to compile mysql

1. Download the mysql package

Wget/root @ ecs – c13b ~ # www.mysql.com/Downloads/M…

2. Download boost library

Boost_1_59_0.tar. gz boost_1_59_0.tar.gz boost_1_59_0.tar.gz boost_1_59_0.tar.gz boost_1_59_0.tar.gz

3. Install the dependency packages
 [root@ecs-c13b ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel
Copy the code
4. Add mysql users and user groups

[root@ecs-c13b ~]# groupadd mysql [root@ecs-c13b ~]# useradd -M -s /sbin/nologin -r -g mysql mysql

5. Decompress and plan the installation directory

[root@ecs-c13b ~]# tar xf boost_1_59_0.tar.gz -C /usr/local/src/ [root@ecs-c13b ~]# tar xf mysql-5.7.19.tar.gz -C /usr/local/src/

Plan the installation directory: Installation directory: /var/lib/mysql Data directory: /var/lib/mysql.data

Create a planned directory and give permissions:

[root@ecs-c13b ~]# mkdir -p /var/lib/mysql/data [root@ecs-c13b ~]# chown -R mysql:mysql /var/lib/mysql/ [root@ecs-c13b ~] #

6. Start compiling mysql

Enter the corresponding directory

[root@ecs-c13b ~]# cd /usr/local/src/
[root@ecs-c13b src]# pwd
/usr/local/src
[root@ecs-c13b src]# CD mysql - 5.7.19 /[root @ ecs - c13b mysql - 5.7.19]# 
Copy the code

cmake:

cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \ -DMYSQL_DATADIR=/var/lib/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \  -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/src/boost_1_59_0

Copy the code

Where to find parameters:

www.mysql.com→→Documentation→→ Select the corresponding version (5.7) Installation & Upgrades→→Installing MySQL from Source →→MySQL The Source – the Configuration Options directly click on the url: dev.mysql.com/doc/refman/…

[root @ ecs - c13b mysql - 5.7.19]# make -j 4
Copy the code

It takes a long time to compile, so smoke a cigarette and so on

[root @ ecs - c13b mysql - 5.7.19]# make install
Copy the code
7. Edit the mysql configuration file
A. This parameter is unavailable by default. You need to enter it manually
[root@ecs-c13b ~]# cat /etc/my.cnf 
[mysqld]
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
port=3306
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/var/lib/mysql/mysql.sock 
[client]
socket=/var/lib/mysql/mysql.sock

[root@ecs-c13b ~]# 
Copy the code
B. Add path so that the system can read mysql commands
[root@ecs-c13b ~]# cat ! $
cat /etc/profile.d/mysql.sh
export PATH=/var/lib/mysql/bin:$PATH
Copy the code
C. The Settings take effect

root@ecs-c13b ~]# . /etc/profile.d/mysql.sh

D. Generate a startup script

[root@ecs-c13b ~]# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld [root@ecs-c13b ~]# chmod +x /etc/init.d/mysqld [root@ecs-c13b ~]#

E. Modify the permission and initialize the database
[root@ecs-c13b ~]# chown -R mysql:mysql /var/lib/mysql

[root@ecs-c13b ~]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
Copy the code
F. Start the mysql test
[root@ecs-c13b ~]# /etc/init.d/mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/tmp/mysqld.pid).
[root@ecs-c13b ~]# cd /var/lib/mysql/data/
[root@ecs-c13b data]# ls
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
[root@ecs-c13b data]# rm -rf ./*
[root@ecs-c13b data]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
[root@ecs-c13b data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
Copy the code

Here, the first startup failed, then deleted the contents of the data directory, reinitialized, and then started successfully

G. Change the database password
[root@ecs-c13b ~]# mysql
mysql> set password for root@localhost=password('12345678');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Copy the code

Compile PHP

Download the PHP7 package

/ root @ ecs – c13b ~ # wget jp2.php.net/distributio…

2. Install dependency packages
[root@ecs-c13b ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2  libxml2-devel zlib curl curl-devel re2c php-pear
Copy the code
3. Compile and install PHP
A. decompression
[root@zmgaosh ~]# tar xf php-7.1.24.tar.gz -C /usr/local/src 
[root@zmgaosh ~]# CD/usr/local/SRC/PHP - 7.1.24 /
Copy the code
B. to compile
[root @ ecs - c13b PHP - 7.1.24]# ./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-curl --with-gd --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/php/etc/ --with-mysqli=mysqlnd  --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-maintainer-zts[root @ ecs - c13b PHP - 7.1.24]# make -j 4 && make install
Copy the code
C. Generate a configuration file

Root @ ecs – c13b – 7.1.24] # cp PHP. PHP ini – production/usr/local/PHP/etc/PHP ini

Compile the Apache configuration file to support PHP

[root @ ecs - c13b PHP - 7.1.24]# vim /usr/local/apache/conf/httpd.conf

 AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Copy the code

DirectoryIndex index.php index.html

D. Create a test page to test
[root @ ecs - c13b PHP - 7.1.24]# cd /usr/local/apache/htdocs/
[root@ecs-c13b htdocs]# pwd
/usr/local/apache/htdocs


[root@ecs-c13b htdocs]# vim index.php
[root@ecs-c13b htdocs]# /etc/init.d/apachectl restart

[root@ecs-c13b htdocs]# cat index.php <? php phpinfo(); ? >Copy the code

4. WordPress installation

1. Upload the wordpress Chinese version

2. Unzip

[root@ecs-c13b htdocs]# ls index.html index.php wordpress-5.4.2-zh_cn.zip [root@ecs-c13b htdocs]# [root@ecs-c13b Htdocs]# unzip wordpress-5.4.2-zh_cn. zip [root@ecs-c13b blog]# mv wordpress blog

3. Web installation
A. Enter the IP address and installation path in the browser

blog/wp-amdin/setup-config.php

B. Configure the database

Here, before clicking Submit, create a database called blog

[root@ecs-c13b blog]# mysql -p12345678
mysql> create database blog;
Query OK, 1 row affected (0.00 sec)
Copy the code

When you’re done, click Submit

C. Create file wp-config.php

[root@ecs-c13b blog]# vim wp-config.php Create this file and copy the contents of the text box shown above to save and exit

Then click Install Now

D. Set the blog installation information

Click install wordpress

E. After the installation, log in to the background

Install the theme

Choose your favorite theme and install it

conclusion

Isn’t it easy to set up a personal blog? In less than 2 hours, we have our own website.