欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Fedora 17 配置 Nginx + Mysql + php

程序员文章站 2024-01-07 18:24:16
...
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 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

方法一: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测试文件