在配置之前,首先要安装mysql和PHP
1、下载nginx-1.16.0和rtmp-module
http://nginx.org/en/download.html
https://github.com/sergey-dryabzhinsky/nginx-rtmp-module
到/usr/local/src目录
2、解压后,进入nginx目录准备进行编译
编译前首先搭建基础环境:
yum install -y gcc gcc-c++ autoconf wget
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel
gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
这下面三个基础的必须安装:
1、 安装openssl
yum install openssl openssl-devel
2、 安装pcre
yum install pcre pcre-devel
3、安装zlib
yum install zlib zlib-devel
4、之后编译:
./configure
--prefix=/usr/local/nginx --add-module=/usr/local/src/nginx-rtmp-module-master --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-stream --with-stream_ssl_module
然后
make && make install
注意,如果之前已经安装了NGINX,只是想升级,那就只make,然后把生成的objs文件夹中的二进制文件“nginx”,复制到之前的安装执行目录:/usr/local/nginx/sbin,之前的执行文件自行备份。
5、然后配置 “/usr/local/nginx/conf” 文件夹中 “nginx.conf”
如果要准备安装wordpress的话,可先查看php配置目录中的www.conf:
vim /etc/opt/remi/php73/php-fpm.d/www.conf
找到【www】选项,发现user和group是系统默认用户和组apache,于是把nginx.conf中的默认用户也改成apache。当然也可以将两者都修改成自己建的系统用户和组。
vim /etc/usr/nginx/conf/nginx.conf
修改:
user apache; #修改用户
worker_processes 1;
……
添加流服务器模块rtmp,注意rtmp和http同级:
rtmp {
server {
listen 1935;
application live {
live on;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
application vod {
play /usr/local/nginx/myvideo;
}
}
}
这样就设置了直播live、hls 和点播vod模块
http部分:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
server {
listen 8088;
server_name localhost;
root /usr/local/nginx/html; #指定根站点目录,不然可能遇到一些奇怪的问题
gzip on; #开启压缩
gzip_min_length 1024; #最小压缩文件为1K
gzip_buffers 4 16k; #压缩缓存空间大小
gzip_comp_level 2; #压缩级别
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; #指定压缩类型
gzip_vary on; #开启压缩表示
location /hls { #hls直播的http模块
types {
application/vnd.apple.mpegurl m3u8;
video/mp2ts ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/src/nginx-rtmp-module-master/;
}
location /control {
rtmp_control all;
}
location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
6、把NGINX加入到systemd作为服务:
在/usr/lib/systemd/system/目录新建一个nginx.service文件,并赋予可执行权限:
vim /usr/lib/systemd/system/nginx.service
添加内容:
[Unit]
Description=nginx-high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
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
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存,退出,赋予可执行权限:
chmon +x /usr/lib/systemd/system/nginx.service
然后启动服务:
systemctl enable nginx #开机启动
systemctl start nginx
这样nginx站点就配置好了。
7、测试PHP,可在html目录建立一个test.php文件,其中内容可为:
<?php
phpinfo();
?>
然后浏览器输入:http://localhost:8088/test.php进行查看,没有问题的话就进行下一步
8、安装wordpress
1、下载Wordpress源码包,并将其解压到/usr/local/nginx/html中,将html目录的拥有者和组改为apache:
chown -R apache:apache html
目录权限改为:
chmod -R 755 html
2、并再次检查nginx.conf中相应的配置:
server {
listen 8088;
server_name localhost;
root /usr/local/nginx/html;
location / {
root /usr/local/nginx/html;
index index.php
index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
3、 进入数据库,按照wordpress说明文档,添加相应的数据库用户和数据
mysql -uroot -p
输入密码
mysql> CREATE DATABASE blog;
#创建wordpress的数据库“databasename“名字可自己指定
mysql> GRANT ALL PRIVILEGES ON databasename.* TO “blog"@"localhost" IDENTIFIED BY "Blog,1234";
#创建访问数据库的用户和密码。
mysql> FLUSH PRIVILEGES;
mysql> EXIT
然后进入/usr/local/nginx/html,
将wp-config-sample.php重命名为wp-config.php
然后
vim wp-config.php
#找到
// ** MySQL settings - You can get this info from your web host ** //
#在其下输入刚才建立的数据库相关信息
define( 'DB_NAME', 'blog' );
/** MySQL database username */
define( 'DB_USER', 'blog' );
/** MySQL database password */
define( 'DB_PASSWORD', 'Blog,1234' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
#需要注意的是,安装时全都是英文的,如果想要中文,需要在下面再加一行:
define( 'WPLANG', 'zh_CN');
最后打开:http://localhost:8088,开始愉快的配置wordpress了.
配置完成后,发现还是英文,按照官网给出的方法,在Dashboard(仪表盘)栏目找到updata升级选项,让你填写上传网站的FTP配置,就是上传网站用到的ftp地址,用户,密码,配置好后就能升级。
我在这里还是遇到了问题,按要求配置好后,出现
ERROR: There was an error connecting to the server, Please verify the settings are correct.
最后考虑可能是SElinux的问题,将其暂时设为宽容模式,搞定!
setenforce 0