Fedora 17 配置 Nginx + Mysql + php

php中文网
发布: 2016-06-23 14:29:04
原创
907人浏览过

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

立即学习PHP免费学习笔记(深入)”;

重启mysql

/etc/init.d/mysqld restart
登录后复制

设置mysql密码:

方法一:

mysqladmin -uroot password
登录后复制

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

mysql_secure_installation
登录后复制

系统自动启动mysql

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

systemctl enable mysqld.servicesystemctl 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.servicesystemctl start nginx.service
登录后复制

3. 安装 PHP

琅琅配音
琅琅配音

全能AI配音神器

琅琅配音 208
查看详情 琅琅配音

方法一: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.servicesystemctl start php-fpm.service
登录后复制

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

systemctl start php-fpm.serviceJob 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测试文件

<?phpphpinfo();?>
登录后复制

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号