编译安装nginx

安装依赖包

yum -y install gcc gcc-c++ autoconf automake make pcre-devel zlib-devel openssl-devel

创建nginx用户

useradd -s /sbin/nologin -M nginx

下载nginx源码包

wget http://nginx.org/download/nginx-1.18.0.tar.gz

解压nginx包

[root@localhost ~]# tar -zxvf nginx-1.18.0.tar.gz

编译安装nginx

[root@localhost ~]# cd nginx-1.18.0/

[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install

路径优化

[root@localhost nginx-1.18.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/

启动nginx

[root@localhost nginx-1.18.0]# nginx

检查nginx端口

[root@localhost nginx-1.18.0]# netstat -anpt | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13211/nginx: master 

安装mariadb数据库

[root@localhost ~]# yum install mariadb mariadb-server mariadb-devel -y

启动mariadb

[root@localhost ~]# systemctl start mariadb.service

修改数据库密码

[root@localhost ~]# mysqladmin -uroot -p password "123.com"
Enter password:

数据库授权

[root@localhost ~]# mysql -uroot -p123.com
给予权限
mysql> grant all on *.* to 'root'@'192.168.1.%' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
mysql> Bye

安装PHP

[root@localhost ~]# yum install php php-fpm php-devel php-mysql

启动php-fpm

[root@localhost ~]# systemctl start php-fpm.service

整合nginx与PHP

修改nginx配置文件

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root         html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

# 重启nginx
[root@localhost ~]# nginx -s reload

修改PHP配置文件

[root@localhost ~]# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx

测试网站能否正常访问

pi@raspberrypi:~ $ cd /usr/local/nginx/html/
pi@raspberrypi:/usr/local/nginx/html $ vim index.php
<?php
        phpinfo();
?>

# 浏览器打开
[root@localhost ~]# firefox 127.0.0.1
Last modification:July 23rd, 2020 at 10:11 pm
如果觉得我的文章对你有用,请随意赞赏