目录
1. 安装nginx
- 准备好本次的安装包:nginx-1.22.0.tar.gz
1.1 安装依赖包
[root@localhost ~]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
1.2 创建运行用户、组
(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
[root@localhost ~]#useradd -M -s /sbin/nologin nginx
1.3 编译安装nginx
[root@localhost ~]#cd /opt
[root@localhost opt]#ls
rh
[root@localhost opt]#rz -E #将下载好的nginx直接拖进虚拟机
rz waiting to receive.
[root@localhost opt]#tar zxvf nginx-1.22.0.tar.gz -C /opt/ #解压
[root@localhost opt]#ls #查看解压好的文件
nginx-1.22.0 nginx-1.22.0.tar.gz rh
[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 nginx-1.22.0]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#建立软链接
[root@localhost nginx-1.22.0]#nginx -t #测试
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.22.0]#nginx -v #查看nginx版本号
nginx version: nginx/1.22.0
[root@localhost ~]#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 ~]#systemctl daemon-reload
[root@localhost ~]#systemctl start nginx
[root@localhost ~]#systemctl status nginx
2. 安装mysql
- 准备好本次的安装包 :mysql-boost-5.7.20.tar.gz
2.1 安装Mysql环境依赖包
[root@localhost ~]#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
2.2 创建运行用户
[root@localhost ~]#useradd -M -s /sbin/nologin mysql
2.3 编译安装
[root@localhost ~]#cd /opt #切换opt目录
[root@localhost opt]#rz -E
rz waiting to receive.
[root@localhost opt]#tar zxvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]#ls
mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.22.0 nginx-1.22.0.tar.gz rh
[root@localhost opt]#cd mysql-5.7.20/
[root@localhost mysql-5.7.20]#ls
[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
2.4 修改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可以删除所有
2.5 更改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
2.6 设置路径环境变量
[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]#source /etc/profile
2.7 初始化数据库
[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
2.8 添加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
2.9 修改mysql的登录密码
[root@localhost bin]#mysqladmin -u root -p password "abc123"
#给root账号设置密码为abc123,提示输入的是原始密码(为空)要求输入的是原密码直接回车即可
2.10 授权远程登录
[root@localhost bin]#mysql -u root -pabc123
[root@localhost bin]#ss -natp | grep 3306
LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=83561,fd=21))
3. 安装php
- 准备好本次的php软件包:php-7.1.10.tar.bz2
3.1 安装环境依赖包
[root@localhost ~]#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
3.2 编译安装
[root@localhost ~]#cd /opt
[root@localhost opt]#ls
[root@localhost opt]#tar jxvf php-7.1.10.tar.bz2
[root@localhost opt]#ls
mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.22.0 nginx-1.22.0.tar.gz php-7.1.10 php-7.1.10.tar.bz2 rh
[root@localhost opt]#cd php-7.1.10
[root@localhost php-7.1.10]#ls
[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
3.3 路径优化
[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/
3.4 调整PHP配置文件
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
- 调整主配置文件
[root@localhost php-7.1.10]#cp /opt/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
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai
[root@localhost php-7.1.10]#php -m #验证安装的模块
- 调整进程服务配置文件
[root@localhost php-7.1.10]#cd /usr/local/php/etc/
[root@localhost etc]#cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]#vim php-fpm.conf
--17行--去掉";"注释
pid = run/php-fpm.pid
- 调整扩展配置文件
[root@localhost etc]#cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]#cp www.conf.default www.conf
3.5 启动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]#netstat -anpt | grep 9000
[root@localhost php-fpm.d]#cd /opt/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
3.6 配置 Nginx 支持 PHP 解析
[root@localhost fpm]#vim /usr/local/nginx/conf/nginx.conf
--65行--取消注释,修改
location ~ \.php$ {
root html; $document_root
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
#将/scripts 修改为nginx的工作目录
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #$document_root 代表当前请求在root指令中指定的值
include fastcgi_params;
}
[root@localhost fpm]#systemctl restart nginx.service
[root@localhost fpm]#vim /usr/local/nginx/html/index.php
#验证PHP 测试页
<?php
phpinfo();
?>
#验证数据库工作是否正常
[root@localhost ~]#mysql -u root -pabc123
mysql> CREATE DATABASE bbs;
Query OK, 1 row affected (0.05 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| bbsuser | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
mysql> exit
Bye
[root@localhost ~]#vim /usr/local/nginx/html/index.php
#替换原来的测试页内容
<?php
$link=mysqli_connect('192.168.8.100','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
浏览器访问
192.168.8.100/index.php
4. 安装bbs论坛
- 准备好本次的安装包:Discuz_X3.4_SC_UTF8.zip
[root@localhost ~]#cd /opt
[root@localhost opt]#rz -E
rz waiting to receive.
[root@localhost opt]#unzip Discuz_X3.4_SC_UTF8.zip
[root@localhost opt]#ls
dir_SC_UTF8 mysql-5.7.20 nginx-1.22.0 php-7.1.10 rh
Discuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.22.0.tar.gz php-7.1.10.tar.bz2 说明.htm
[root@localhost opt]#cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]#ls
readme upload utility
[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.8.100/bbs/install/index.php
http://192.168.8.100/bbs/index.php
5. 安装wordpress
- 准备好本次的安装包:wordpress-6.3-zh_CN.zip
[root@localhost ~]#cd /opt
[root@localhost opt]#ls
dir_SC_UTF8 mysql-5.7.20 nginx-1.22.0 php-7.1.10 rh
Discuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.22.0.tar.gz php-7.1.10.tar.bz2 说明.htm
[root@localhost opt]#rz -E
rz waiting to receive.
[root@localhost opt]#unzip wordpress-6.3-zh_CN.zip
[root@localhost opt]#ls
dir_SC_UTF8 mysql-boost-5.7.20.tar.gz php-7.1.10 wordpress
Discuz_X3.4_SC_UTF8.zip nginx-1.22.0 php-7.1.10.tar.bz2 wordpress-6.3-zh_CN.zip
mysql-5.7.20 nginx-1.22.0.tar.gz rh 说明.htm
[root@localhost opt]#chmod 777 wordpress -R
[root@localhost opt]#ls
dir_SC_UTF8 mysql-boost-5.7.20.tar.gz php-7.1.10 wordpress
Discuz_X3.4_SC_UTF8.zip nginx-1.22.0 php-7.1.10.tar.bz2 wordpress-6.3-zh_CN.zip
mysql-5.7.20 nginx-1.22.0.tar.gz rh 说明.htm
[root@localhost opt]#cp -r wordpress /usr/local/nginx/html/
[root@localhost opt]#cp -r wordpress /usr/local/nginx/html/
[root@localhost opt]#ls
dir_SC_UTF8 mysql-boost-5.7.20.tar.gz php-7.1.10 wordpress
Discuz_X3.4_SC_UTF8.zip nginx-1.22.0 php-7.1.10.tar.bz2 wordpress-6.3-zh_CN.zip
mysql-5.7.20 nginx-1.22.0.tar.gz rh 说明.htm
[root@localhost opt]#cd /usr/local/nginx/html/
[root@localhost html]#ls
50x.html bbs index.html index.php wordpress
[root@localhost html]#chmod 777 wordpress/ -R
[root@localhost html]#mysql -u root -pabc123
mysql> CREATE DATABASE blog;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT all ON blog.* TO 'bloguser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
http://192.168.8.100/wordpress/wp-admin/install.php
http://192.168.8.100/wordpress/wp-admin/install.php/index.php
标签:LNMP,nginx,usr,mysql,php,root,localhost
From: https://www.cnblogs.com/LJ69/p/17665756.html