Home > Backend Development > PHP Tutorial > Fedora 17 配置 Nginx + Mysql + php

Fedora 17 配置 Nginx + Mysql + php

WBOY
Release: 2016-06-23 14:29:04
Original
822 people have browsed it

1. 安装Mysql5

yum install mysql mysql-serverchkconfig --levels 235 mysqld on
Copy after login

启动

/etc/init.d/mysqld start
Copy after login

查询是否启动

netstat -tap | grep mysql
Copy after login

无法启动mysql时

vi /etc/my.cnf
Copy after login

#skip networking

重启mysql

/etc/init.d/mysqld restart
Copy after login

设置mysql密码:

方法一:

mysqladmin -uroot password
Copy after login

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

mysql_secure_installation
Copy after login

系统自动启动mysql

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

systemctl enable mysqld.servicesystemctl start mysqld.service
Copy after login

方法二:

chkconfig --levels 235 mysqld on
Copy after login

2. 安装Nginx

yum install nginx
Copy after login

设置开机启动

方法一:

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

方法二:

systemctl enable nginx.servicesystemctl start nginx.service
Copy after login

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
Copy after login

方法二: 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
Copy after login

配置php

vi /etc/php.ini
Copy after login

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

查看本机时区

cat /etc/sysconfig/clock
Copy after login

修改配置

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
Copy after login
Copy after login

设置开机启动:

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
Copy after login
Copy after login

二:以php-fpm模式的启动

systemctl enable php-fpm.servicesystemctl start php-fpm.service
Copy after login

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

systemctl start php-fpm.serviceJob failed. See system journal and 'systemctl status' for details.
Copy after login

搜索了好久,都没有搜到,一开始以为没有把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
Copy after login

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;        }    }
Copy after login

重启nginx

systemctl reload nginx.service
Copy after login

5. 写一个php测试文件

<?phpphpinfo();?>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template