服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Fedora - Fedora 17 配置 Nginx + Mysql + php

Fedora 17 配置 Nginx + Mysql + php

2023-05-09 06:05未知服务器之家 Fedora

1. 安装Mysql5 yum install mysql mysql- serverchkconfig --levels 235 mysqld on 启动 /etc/init.d/mysqld start 查询是否启动 netstat -tap | grep mysql 无法启动mysql时 vi /etc/my.cnf #skip networking 重启mysql /etc/init.d/mysqld restart 设置mysql密码: 方法一: mysqladmin -uroot

1. 安装Mysql5

yum install mysql mysql-server
chkconfig --levels 235 mysqld on

启动

/etc/init.d/mysqld start

查询是否启动

netstat -tap | grep mysql

无法启动mysql时

vi /etc/my.cnf

#skip networking

重启mysql

/etc/init.d/mysqld restart

设置mysql密码:

方法一:

mysqladmin -uroot password

方法二(设置根用户密码)(推荐):

mysql_secure_installation

系统自动启动mysql

方法一(推荐,fedora新到管理服务的命令):

systemctl enable mysqld.service
systemctl start mysqld.service

方法二:

chkconfig --levels 235 mysqld on

2. 安装Nginx

yum install nginx

设置开机启动

方法一:

chkconfig --levels 235 nginx on
/etc/init.d/nginx start

方法二:

systemctl enable nginx.service
systemctl start nginx.service

3. 安装 PHP

方法一:fastcgi模式

yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

 方法二: php-fpm模式(推荐)

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

 配置php

vi /etc/php.ini

cgi.fix_pathinfo = 0 (推荐设置为0,默认为1,为1时会有安全漏洞)

查看本机时区

cat /etc/sysconfig/clock

修改配置

date.timezone="Asia/Shanghai"

启动php
一:以spawn-fcgi模式的启动
spawn-fcgi --help

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

 设置开机启动:

vi /etc/rc.local 加入

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

 二:以php-fpm模式的启动

systemctl enable php-fpm.service
systemctl start php-fpm.service

 注意这个地方会遇到这个错误 :

systemctl start php-fpm.service
Job failed. See system journal and 'systemctl status' for details.

搜索了好久,都没有搜到,一开始以为没有把php-rpm.conf.default改为php-rpm.conf, 后来发现其实这个文件已经存在了。

后来通过systemctl status php-fpm.service在日志中终于找到了原因:
原来是没有配置好php-rpm.conf 及它包含到文件/etc/php-fpm.d/www.conf
在此文件中
默认的 user = apache
默认到 group = apache
因为是安装nginx,所以全部改为nginx后,终于可以启动php-fpm了。

4. 配置nginx

vi /etc/nginx/nginx.conf
worker_processes  5;

keepalive_timeout  2;

server {
        listen       80;
        server_name  localhost; # 这里一定要设置,否则不能支持php
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
 
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

重启nginx

systemctl reload nginx.service

5. 写一个php测试文件

<?php
phpinfo();
?>

延伸 · 阅读

精彩推荐
  • FedoraHostwinds教程:如何在Fedora上安装Docker

    Hostwinds教程:如何在Fedora上安装Docker

    docker 是一个开源应用容器引擎,以类似于虚拟机但不虚拟化的方式在自包含的环境中创建相关应用程序和服务。您可以在多个平台上下载并安装Docker,比如...

    未知1232023-05-09
  • Fedorafedora phpMyAdmin 安装方法及介绍

    fedora phpMyAdmin 安装方法及介绍

    在安装fedora的时候,把基本该选择的组件都选上,其中就有Appache,mysql,和php,但是在我们管了数据库的时候,还是有个图形界面比较方便,所以我们自己...

    fedora教程网5742019-10-15
  • Fedora阿里云购买镜像服务器

    阿里云购买镜像服务器

    阿里云 作为国内的领先云计算服务提供商,为用户提供了各种可靠、高效的云计算产品,其中就包括镜像服务器。镜像服务器是一个非常优秀的解决方案,...

    未知1342023-06-02
  • Fedora阿里云服务器配置低选择什么系统比较好

    阿里云服务器配置低选择什么系统比较好

    在选择阿里 云服务器 时,除了考虑服务器的大小和价格,还需要考虑哪个操作系统最适合该服务器。操作系统是服务器的基础,因为它提供了一个框架,...

    未知1152023-05-10
  • Fedorafedora8 下mysql 安装的安装方法

    fedora8 下mysql 安装的安装方法

    fedora8 下mysql 安装的安装方法...

    fedora教程网6422019-10-14
  • FedoraFedora 33开始测试切换到Btrfs

    Fedora 33开始测试切换到Btrfs

    尽管距离 Fedora 的下一个稳定版本(Fedora 33)还有几个月的距离,但仍有一些值得关注的变化。在所有其他 Fedora 33 接受的系统范围的更改中,最有趣的提议...

    Linux中国3392020-07-27
  • Fedora【转载】fedora22和win10之间的文件共享互访

    【转载】fedora22和win10之间的文件共享互访

      钢铁侠与孔子  关注 2016.06.04 14:10*  字数 1327  阅读 2170 评论 0 喜欢 1  一,相关知识了解(本文执行环境为fedora22和win10) 在局域网内windows系统之间共享...

    未知872023-05-09
  • FedoraFedora 35 将搭载 LLVM 13 和 Go 1.17

    Fedora 35 将搭载 LLVM 13 和 Go 1.17

    Fedora工程和指导委员会 (FESCo) 批准了将于秋季发布的 Fedora 35 的一些额外变更。...

    开源中国6002021-08-19