安装LNMP-------(CENTOS8)
1.NGINX安装------编译安装
## 下载软件,选择自己需要的版本使用WGET下载
http://nginx.org/en/download.html
如:wget http://nginx.org/download/nginx-1.19.2.tar.gz
#安装依赖
yum -y install pcre pcre-devel openssl openssl-devel zlib zlib-devel
#安装nginx
cd /root/soft/
tar -zxvf nginx-1.19.2.tar.gz
cd nginx-1.19.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module #配置https安全型协议
make && make install # 编译&安装
2.安装php
# 下载、解压,进入PHP
wget https://www.php.net/distributions/php-7.4.2.tar.gz
tar -zxvf php-7.4.2.tar.gz
cd php-7.4.2/
# 配置
./configure --prefix=/usr/local/php7 --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/usr/local/php7/etc -with-bz2 --enable-inline-optimization --enable-sysvsem
#编译安装
make && make install
# 配置过程中遇到各种报错信息的处理
yum install libxml2-devel
yum install krb5-devel
yum install openssl-devel
yum install sqlite-devel
yum install libcurl-devel
yum install libxslt-devel
yum install libjpeg-devel
yum install libzip-devel
yum -y install bzip2-devel
yum install libpng-devel
yum install freetype-devel
# 下载 oniguruma
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4
# 编译安装
./autogen.sh && ./configure --prefix=/usr
make && make install
# 生成php配置文件
cp php.ini-production /usr/local/php7/etc/php.ini
#生成www配置文件
cd /usr/local/php7/etc/php-fpm.d/
cp www.conf.default www.conf
# 生成php-fpm配置文件
cd /usr/local/php7/etc
cp php-fpm.conf.default php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
#去除;分号
;pid = run/php-fpm.pid
# 启动php服务
/usr/local/php7/sbin/php-fpm
# 配置环境变量
vim /etc/profile
PATH=$PATH:/usr/local/php7/sbin:/usr/local/nginx/sbin:/usr/local/php7/bin/
# 配置时区
vi /usr/local/php7/etc/php.ini
date.timezone = PRC
# 重启php-fpm
killall php-fpm
php-fpm
# ****** 安装killall命令 **********
yum install psmisc -y
3.编译 php与nginx整合
server{
listen 80;
server_name localhost;
root php-file;
location /{
index index.html;
}
location ~ \.php?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
# 注意:可以在CONF/nginx.conf中写入
include extra/*.conf; #如果要用localhost:80需要注释掉nginx.conf中的server
4.systemctl管理 (nginx and php-fpm)
# NGINX使用SYSTEMCTL管理
[root@web69 ~]# cd /usr/lib/systemd/system
[root@web69 system]# vim nginx.service
### 注意:复制进去已后把注释都删掉,不然会报错
------------------------------------
[Unit]
# 描述服务
Description=nginx-The High-performance HTTP Server
# 前置服务
After=network.target remote-fs.target nss-lookup.target
[Service]
# 后台运行的形式
Type=forking
# PID文件的路径
PIDFile=/usr/local/nginx/logs/nginx.pid
# 启动准备
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
# 启动命令
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# 重启命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload
停止命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop
# 给服务分配临时空间
PrivateTmp=true
[Install]
# 服务用户的模式
WantedBy=multi-user.target
# 重新加载所有修改过的unit文件
#daemon-reload : 当我们手动修改/添加 unit文件后,需要执行daemon-reload
systemctl daemon-reload
# php-fpm
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
# PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 重新加载所有修改过的unit文件
#daemon-reload : 当我们手动修改/添加 unit文件后,需要执行daemon-reload
systemctl daemon-reload
5.rc.local
# 开机启动PHP-FPM
cd /etc/rc.d/
vim rc.local
# rc.local中添加
/usr/local/php7/sbin/php-fpm --fpm-config /usr/local/php7/etc/php-fpm.d/www.conf
#给rc.local执行权限
chmod +x rc.local
6.安装MARIADB
# 使用rpm -qa | grep mariadb搜索 MariaDB 现有的包:
rpm -qa | grep mariadb
yum remove mysql mysql-server mysql-libs compat-mysql51
# 开始新的安装, 创建MariaDB.repo文件
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2020-03-18 20:13 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# 运行安装命令安装MariaDB
sudo yum install -y MariaDB-server MariaDB-client
systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动
systemctl status mariadb #查看下状态
systemctl stop mariadb.service #停止MariaDB
# 进行MariaDB的相关简单配置
# 使用 mysql_secure_installation 命令进行配置
*************************************************************************************
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
# ******************************************************************************************
#配置MariaDB的字符集
查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件
1)使用vi server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
如果/etc/my.cnf.d 目录下无server.cnf文件,则直接在/etc/my.cnf文件的[mysqld]标签下添加以上内容。
2)文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
3)文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集
mysql> show variables like "%character%";show variables like "%collation%";
##****************************************************************************************
## 添加用户,设置权限
创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on *.* to username@localhost indentified by 'password';
修改密码
mysql>set password for root@localhost = password('abc.123');
授予外网登陆权限
mysql>grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
查看用户
MariaDB [mysql]> select host,user,password from user;
允许指定地址远程
GRANT ALL PRIVILEGES ON *.* TO 'root'@'193.112.125.229'WITH GRANT OPTION;
重启
FLUSH PRIVILEGES;
********************如果上面配置完还不可以访问再修改下面配置*******************************
修改SERVER.CONF配置文件
cd /etc/my.cnf.d/
vim server.cnf
设置成bind-address = 0.0.0.0
7.thinkphp 配置
server{
listen 80;
server_name localhost;
root tp6/public;
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
index index.php;
}
location ~ .+\.php($|/) {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php?IF_REWRITE=1;
include fastcgi.conf;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}
}