目录
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0
#####关闭防火墙和关闭selinux
安装nginx
安装依赖环境
[root@localhost ~]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
创建nginx用户组
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
编译安装nginx
[root@localhost ~]#tar zxvf nginx-1.22.0.tar.gz -C /data
#####解压nginx1.22.0压缩包到data文件下
[root@localhost nginx-1.22.0]#./configure \
> --prefix=/usr/local/nginx \ #指定nginx的安装路径
> --user=nginx \ #指定用户名
> --group=nginx \ #指定组名
> --with-http_stub_status_module #启用 http_stub_status_module 模块以支持状态统计
#####配置执行
[root@localhost nginx-1.22.0]#make -j2 && make install
[root@localhost sbin]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#让系统识别nginx的操作命令可以自动补全 nginx $PATH
[root@localhost sbin]#nginx -t
#####检查nginx语法
[root@localhost sbin]#nginx -v
#####查看nginx版本
[root@localhost nginx-1.22.0]#vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -1 $MAINPID
ExecStop=/bin/kill -3 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost nginx-1.22.0]#systemctl daemon-reload
#####重新加载systemd文件
[root@localhost nginx-1.22.0]#systemctl start nginx
#####启动nginx文件
[root@localhost nginx-1.22.0]#systemctl status nginx
#####查看nginx文件状态
安装mysql
安装mysql环境依赖包
[root@localhost nginx-1.22.0]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
创建mysql用户组
[root@localhost nginx-1.22.0]#useradd -M -s /sbin/nologin mysql
编译安装mysql
[root@localhost data]#tar zxvf mysql-boost-5.7.20.tar.gz
#####解压mysql5.7.20压缩包在data文件下
[root@localhost mysql-5.7.20]#cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]#make -j2 && make install
此处需要耐心等待下载安装
修改mysql配置文件
[root@localhost mysql-5.7.20]#vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
#####可以使用ggdG删除vim里面全部内容
更改mysql安装目录和配置文件的属主属组
[root@localhost mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.20]#chown mysql:mysql /etc/my.cnf
设置路径环境变量
[root@localhost mysql-5.7.20]#echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]#. /etc/profile
初始化数据库
[root@localhost mysql-5.7.20]#cd /usr/local/mysql/bin/
[root@localhost bin]#./mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
添加mysqld系统服务
[root@localhost bin]#cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost bin]#systemctl daemon-reload
[root@localhost bin]#systemctl start mysqld.service
[root@localhost bin]#systemctl status mysqld.service
修改mysql 的登录密码
[root@localhost bin]#mysqladmin -u root -p password "abc123"
#####给root账号设置密码为abc123,提示输入的是原始密码(为空)要求输入的是原密码直接回车即可
授权远程登录
[root@localhost bin]#mysql -u root -pabc123
安装php
安装环境依赖
[root@localhost bin]#yum -y install gd \
> libjpeg libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
编译安装
[root@localhost data]#tar xf php-7.1.10.tar.bz2
[root@localhost php-7.1.10]#./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]#make -j2 && make install
此处需要耐心等待下载安装
路径优化
[root@localhost php-7.1.10]#ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost php-7.1.10]#ln -s /usr/local/php/sbin/* /usr/local/sbin/
调整PHP配置文件
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
- 调整主配置文件
[root@localhost php-7.1.10]#cp /data/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]#vim /usr/local/php/lib/php.ini
939 date.timezone = Asia/Shanghai
#####939G
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
#####1170G
- 调整进程服务配置文件
[root@localhost php-7.1.10]#cd /usr/local/php/etc/
[root@localhost etc]#cp -a php-fpm.conf.default php-fpm.conf
[root@localhost etc]#vim php-fpm.conf
- 调整扩展配置文件
[root@localhost etc]#cd php-fpm.d/
[root@localhost php-fpm.d]#cp www.conf.default www.conf
启动php-fpm
[root@localhost php-fpm.d]#/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost php-fpm.d]#ss -natp |grep 9000
[root@localhost php-fpm.d]#cd /data/php-7.1.10/sapi/fpm
[root@localhost fpm]#cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
[root@localhost fpm]#systemctl restart php-fpm.service
[root@localhost fpm]#systemctl status php-fpm.service
配置 Nginx 支持 PHP 解析
[root@localhost fpm]#vim /usr/local/nginx/conf/nginx.conf
[root@localhost fpm]#nginx -s reload
[root@localhost fpm]#systemctl restart nginx.service
[root@localhost html]#mysql -u root -pabc123
mysql> create database bbs;
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
mysql> flush privileges;
mysql> show databases;
mysql> select user,host from mysql.user;
[root@localhost fpm]#cd /usr/local/nginx/html/
[root@localhost html]#vim index.php
<?php
$link=mysqli_connect('192.168.174.103.','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
安装bbs论坛
[root@localhost html]#cd /data
[root@localhost data]#unzip Discuz_X3.4_SC_UTF8.zip
[root@localhost data]#cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]#cp -r upload/ /usr/local/nginx/html/bbs/
[root@localhost dir_SC_UTF8]#cd /usr/local/nginx/html/
[root@localhost html]#chmod -R 777 bbs/
[root@localhost html]#chown nginx.nginx -R bbs/
http://192.168.174.103/bbs/install/index.php
http://192.168.174.103/bbs/index.php
安装wordpress
[root@localhost data]#unzip wordpress-6.3-zh_CN.zip
[root@localhost data]#cp -a wordpress /usr/local/nginx/html/
[root@localhost data]#cd /usr/local/nginx/html/
[root@localhost html]#chmod 777 wordpress/ -R
[root@localhost html]#mysql -u root -pabc123
mysql> CREATE DATABASE blog;
mysql> GRANT all ON blog.* TO 'mtwm'@'%' IDENTIFIED BY 'admin123';
mysql> flush privileges;
mysql> show databases;
mysql> select user,host from mysql.user;
http://192.168.174.103/wordpress/wp-admin/install.php
http://192.168.174.103/wordpress/wp-admin/index.php
标签:LNMP,nginx,usr,mysql,php,root,localhost
From: https://www.cnblogs.com/mtwm/p/17665783.html