linux g++ 关闭 ‘typedef’ 警告_Linux服务器个人博客搭建——LNMP

推荐阅读:

ShowDoc安装部署

K8S学习实验 kubernetes-1-组件简介

一.部署数据库

1.1 二进制部署 MySQL

# 安装依赖
[root@VM_0_2_centos ~]#yum install vim gcc gcc-c++ wget autoconf  net-tools lrzsz iotop lsof iotop bash-completion  curl policycoreutils openssh-server openssh-clients postfix numactl.x86_64 -y

# 准备二进制包
[root@VM_0_2_centos src]#tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
# 创建软连接
[root@VM_0_2_centos src]#ln -sv /usr/local/src/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql
‘/usr/local/mysql’ -> ‘/usr/local/src/mysql-5.6.46-linux-glibc2.12-x86_64’
# 创建mysql用户
[root@VM_0_2_centos src]#useradd  mysql -s /sbin/nologin
[root@VM_0_2_centos src]#mkdir -pv /data/mysql /var/lib/mysql
mkdir: created directory ‘/data/mysql’
mkdir: created directory ‘/var/lib/mysql’
# 数据目录权限授权给mysql用户
[root@VM_0_2_centos src]#chown  -R mysql.mysql  /data   /var/lib/mysql -R
# 安装初始化数据库
[root@VM_0_2_centos src]#/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
# 准备启动文件
[root@VM_0_2_centos src]#cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@VM_0_2_centos src]#chmod a+x /etc/init.d/mysqld
# 准备配置文件
[root@VM_0_2_centos src]#vim /etc/my.cnf
[root@VM_0_2_centos src]#cat /etc/my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
max_connections=1000

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/tmp/mysql.pid

1.2 创建数据库和用户并授权

# 使用启动文件启动数据库
[root@VM_0_2_centos src]#cd
[root@VM_0_2_centos ~]#/etc/init.d/mysqld  start
Starting MySQL.. SUCCESS! 
[root@VM_0_2_centos ~]#ln -sv /data/mysql/mysql.sock /var/lib/mysql/mysql.sock
‘/var/lib/mysql/mysql.sock’ -> ‘/data/mysql/mysql.sock’

[root@VM_0_2_centos ~]#/usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.13 sec)

mysql>  GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"175.xx.xx.%"  IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database            |
+--------------------+
| information_schema  |
| mysql                |
| performance_schema  |
| test                 |
| wordpress           |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

1.3 验证账户访问权限

[root@VM_0_2_centos ~]#/usr/local/mysql/bin/mysql -uwordpress -h175.xx.xx.xx -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database            |
+--------------------+
| information_schema |
| test                |
| wordpress           |
+--------------------+
3 rows in set (0.00 sec)

mysql>

二.部署 PHP

2.1 编译安装 PHP 7.3.10

[root@VM_0_2_centos ~]#yum repolist  #更新仓库源

[root@VM_0_2_centos ~]#yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
# 准备源码
[root@VM_0_2_centos src]#cd /usr/local/src/
[root@VM_0_2_centos src]#tar xvf php-7.3.10.tar.xz
[root@VM_0_2_centos src]#cd php-7.3.10/
# 生成Makefile文件
[root@VM_0_2_centos php-7.3.10]#./configure  --prefix=/apps/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-pear --with-curl  --with-png-dir --with-freetype-dir --with-iconv   --with-mhash   --with-zlib --with-xmlrpc --with-xsl --with-openssl  --with-mysqli --with-pdo-mysql --disable-debug --enable-zip --enable-sockets --enable-soap   --enable-inline-optimization  --enable-xml --enable-ftp --enable-exif --enable-wddx --enable-bcmath --enable-calendar   --enable-shmop --enable-dba --enable-sysvsem --enable-sysvshm --enable-sysvmsg
# 使用4个核心编译
[root@VM_0_2_centos php-7.3.10]#make -j 4
# 安装
[root@VM_0_2_centos php-7.3.10]#make  install
Installing PEAR environment:      /apps/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.7
[PEAR] Console_Getopt - installed: 1.4.2
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.3
[PEAR] PEAR           - installed: 1.10.9
Wrote PEAR system config file at: /apps/php/etc/pear.conf
You may want to add: /apps/php/lib/php to your php.ini include_path
/usr/local/src/php-7.3.10/build/shtool install -c ext/phar/phar.phar /apps/php/bin
ln -s -f phar.phar /apps/php/bin/phar
Installing PDO headers:           /apps/php/include/php/ext/pdo/

2.2 准备 PHP 配置文件

# 注意区分配置文件所在的位置
[root@VM_0_2_centos php-7.3.10]#cd /apps/php/etc/php-fpm.d/
[root@VM_0_2_centos php-fpm.d]#cp www.conf.default www.conf
[root@VM_0_2_centos php-fpm.d]#cp /usr/local/src/php-7.3.10/php.ini-production /apps/php/etc/php.ini
[root@VM_0_2_centos php-fpm.d]#useradd www -s /sbin/nologin  -u 1001
[root@VM_0_2_centos php-fpm.d]#vim www.conf
[root@VM_0_2_centos php-fpm.d]#grep -v ";" www.conf | grep -v "^$"
[www]
user = www
group = www
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.status_path = /pm_status
ping.path = /ping
ping.response = pong
access.log = log/$pool.access.log
slowlog = log/$pool.log.slow

[root@VM_0_2_centos php-fpm.d]#cd ..
[root@VM_0_2_centos etc]#mkdir /apps/php/log/
[root@VM_0_2_centos etc]#cd  /apps/php/etc/          
[root@VM_0_2_centos etc]#cp php-fpm.conf.default php-fpm.conf

2.3 启动 php-fpm 服务

# 检测语法并启动php-fpm:
[root@VM_0_2_centos etc]#/apps/php/sbin/php-fpm -t
[07-Apr-2020 23:13:26] NOTICE: configuration file /apps/php/etc/php-fpm.conf test is successful

# 验证php-fpm:             
[root@VM_0_2_centos etc]#/apps/php/sbin/php-fpm -c /apps/php/etc/php.ini 
[root@VM_0_2_centos etc]# ps -ef | grep php-fpm
root      2518     1  0 23:14 ?        00:00:00 php-fpm: master process (/apps/php/etc/php-fpm.conf)
www       2519  2518  0 23:14 ?        00:00:00 php-fpm: pool www
www       2520  2518  0 23:14 ?        00:00:00 php-fpm: pool www
www       2521  2518  0 23:14 ?        00:00:00 php-fpm: pool www
www       2522  2518  0 23:14 ?        00:00:00 php-fpm: pool www
[root@VM_0_2_centos etc]#netstat  -tanlp | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      2518/php-fpm: maste 

三.部署 Nginx

3.1 下载 nginx

# 安装依赖
[root@VM_0_2_centos src]#yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget  ntpdate  gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel systemd-devel net-tools iotop bc  zip unzip zlib-devel bash-completion nfs-utils automake libxml2  libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

# 下载源码
[root@VM_0_2_centos src]#cd /usr/local/src/

[root@VM_0_2_centos src]#wget https://nginx.org/download/nginx-1.12.2.tar.gz
[root@VM_0_2_centos src]#tar xf nginx-1.12.2.tar.gz
[root@VM_0_2_centos src]#cd nginx-1.12.2
[root@VM_0_2_centos nginx-1.12.2]#

3.2 修改源码 server 信息

自定义 Response Hearders 中 server 信息

[root@VM_0_2_centos nginx-1.12.2]#vim src/core/nginx.h
13 #define NGINX_VERSION      "1.12"
14 #define NGINX_VER          "Kaivi/" NGINX_VERSION  #开启server_tokens显示此信息


[root@VM_0_2_centos nginx-1.12.2]#vim src/http/ngx_http_header_filter_module.c 
49 static u_char ngx_http_server_string[] = "Server: kaivi-engine" CRLF;  # 关闭server_tokens显示此信息

3.3 编译安装

# 生成Makefile文件
[root@VM_0_2_centos nginx-1.12.2]#./configure --prefix=/apps/nginx --user=www  --group=www --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module  --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

# 编译
[root@VM_0_2_centos nginx-1.12.2]#make
# 安装
[root@VM_0_2_centos nginx-1.12.2]#make install

3.4 准备 php 测试页面

[root@VM_0_2_centos nginx-1.12.2]#cd
[root@VM_0_2_centos ~]#mkdir /data/nginx/wordpress -p
[root@VM_0_2_centos ~]#vim /data/nginx/wordpress/index.php
[root@VM_0_2_centos ~]#cat /data/nginx/wordpress/index.php
<?php
  phpinfo();
?>

3.5 配置 Nginx

[root@VM_0_2_centos ~]#vim /apps/nginx/conf/nginx.conf
[root@VM_0_2_centos ~]#grep -v "#" /apps/nginx/conf/nginx.conf | grep -v "^$"
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.likai.tech;
        location / {
            root   /data/nginx/wordpress;
            index  index.php index.html index.htm;
    if ($http_user_agent ~ "ApacheBench|WebBench|TurnitinBot|Sogou web spider|Grid
Service") {
         return 403;

       }
     }
      location ~ \.php$ {
           root          /data/nginx/wordpress;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    }

3.6 重启访问 php 状态页

[root@VM_0_2_centos ~]#/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@VM_0_2_centos ~]#/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf

四.部署 Wordpress

4.1 部署 Wordpress

# 移走测试页面
[root@VM_0_2_centos ~]#cd
[root@VM_0_2_centos ~]#cd /data/nginx/wordpress/
[root@VM_0_2_centos wordpress]#ll
total 4
-rw-r--r-- 1 root root 22 Apr  7 23:31 index.php
[root@VM_0_2_centos wordpress]#mv index.php /opt/
# 准备wordpress程序包

[root@VM_0_2_centos wordpress]#ll
total 12136
-rw-r--r-- 1 root root 12423575 Apr  7 23:53 wordpress-5.3-zh_CN.tar.gz

[root@VM_0_2_centos wordpress]#tar xf wordpress-5.3-zh_CN.tar.gz 
[root@VM_0_2_centos wordpress]#ll
total 12140
drwxr-xr-x 5 1006 1006     4096 Nov 14 09:00 wordpress
-rw-r--r-- 1 root root 12423575 Apr  7 23:53 wordpress-5.3-zh_CN.tar.gz

[root@VM_0_2_centos wordpress]#mv wordpress/* .

[root@VM_0_2_centos wordpress]#mv wordpress-5.3-zh_CN.tar.gz /opt/
[root@VM_0_2_centos wordpress]#mv wordpress/ /opt/
[root@VM_0_2_centos wordpress]#ll
total 208
-rw-r--r--  1 1006 1006   420 Dec  1  2017 index.php
-rw-r--r--  1 1006 1006 19935 Jan  2  2019 license.txt
-rw-r--r--  1 1006 1006  7005 Nov 14 09:00 readme.html
-rw-r--r--  1 1006 1006  6939 Sep  3  2019 wp-activate.php
drwxr-xr-x  9 1006 1006  4096 Nov 14 09:00 wp-admin
-rw-r--r--  1 1006 1006   369 Dec  1  2017 wp-blog-header.php
-rw-r--r--  1 1006 1006  2283 Jan 21  2019 wp-comments-post.php
-rw-r--r--  1 1006 1006  2776 Nov 14 09:00 wp-config-sample.php
drwxr-xr-x  5 1006 1006  4096 Nov 14 09:00 wp-content
-rw-r--r--  1 1006 1006  3955 Oct 11 06:52 wp-cron.php
drwxr-xr-x 20 1006 1006 12288 Nov 14 09:00 wp-includes
-rw-r--r--  1 1006 1006  2504 Sep  3  2019 wp-links-opml.php
-rw-r--r--  1 1006 1006  3326 Sep  3  2019 wp-load.php
-rw-r--r--  1 1006 1006 47007 Oct  1  2019 wp-login.php
-rw-r--r--  1 1006 1006  8483 Sep  3  2019 wp-mail.php
-rw-r--r--  1 1006 1006 19120 Oct 15 23:37 wp-settings.php
-rw-r--r--  1 1006 1006 31112 Sep  3  2019 wp-signup.php
-rw-r--r--  1 1006 1006  4764 Dec  1  2017 wp-trackback.php
-rw-r--r--  1 1006 1006  3150 Jul  1  2019 xmlrpc.php

# 填写配置文件,数据库信息
[root@VM_0_2_centos wordpress]#cp wp-config-sample.php wp-config.php
[root@VM_0_2_centos wordpress]#vim wp-config.php 
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );

/** MySQL数据库用户名 */
define( 'DB_USER', 'wordpress' );

/** MySQL数据库密码 */
define( 'DB_PASSWORD', '123456' );

/** MySQL主机 */
define( 'DB_HOST', '175.xx.xx.xx' );

[root@VM_0_2_centos wordpress]#chown  www.www /data/nginx/wordpress/ /apps/nginx/ -R

[root@VM_0_2_centos wordpress]#/apps/nginx/sbin/nginx  -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful

[root@VM_0_2_centos wordpress]#/apps/nginx/sbin/nginx  -s reload

4.2 初始化配置

访问http://www.likai.tech/index.php初始化

[root@VM_0_2_centos ~]#systemctl status mysql
[root@VM_0_2_centos ~]#systemctl start mysql
0f0c04dd4f532402e8609cc618034d3b.png

4.3 验证数据库

# 初始化wordpress生成的表
[root@VM_0_2_centos mysql]#/usr/local/mysql/bin/mysql -uwordpress -h175.xx.xx.xx -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.6.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-----------------------+
| Tables_in_wordpress    |
+-----------------------+
| wp_commentmeta         |
| wp_comments            |
| wp_links               |
| wp_options             |
| wp_postmeta            |
| wp_posts               |
| wp_term_relationships  |
| wp_term_taxonomy       |
| wp_termmeta            |
| wp_terms               |
| wp_usermeta                    |
| wp_users                        |
+-----------------------+
12 rows in set (0.00 sec)

mysql> 

4.4 验证自定义的 server 信息

在浏览器的调试窗口查看Server:xxx字段
为:Server: Kaivi/1.12

2878802bda0ecba020b58552fffaa9ad.png

4.5 隐藏 PHP 版本

[root@VM_0_2_centos mysql]#vim /apps/nginx/conf/nginx.conf
location ~ \.php$ {
           root          /data/nginx/wordpress;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_hide_header X-Powered-By;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }

# 重启nginx并验证是否隐藏PHP版本:
[root@VM_0_2_centos mysql]#/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@VM_0_2_centos mysql]#/apps/nginx/sbin/nginx -s reload
root@VM_0_2_centos wordpress]#chown www:www ./* -R #统一用户 不然上传下载存在问题

备份文件整理

efbfd4d69912fa0582fc51b1ac96f047.png

搭建博客首页

http://www.likai.tech/

891c2498ebb5ced6e5f82181a1bb75ba.png

9684822e29575d2b7e0474d5af75dd89.png

相关阅读推荐:

ShowDoc安装部署

K8S学习实验 kubernetes-1-组件简介

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值