fedora nginx 安装mysql_Fedora 17 配置 Nginx + Mysql + php

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 235nginx 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_timeout2;

server {

listen80;

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_page404 /404.html;

location= /404.html {

root/usr/share/nginx/html;

}

# redirect server error pages to the static page/50x.html

#

error_page500 502 503 504 /50x.html;

location= /50x.html {

root/usr/share/nginx/html;

}

# proxy the PHP scripts to Apache listening on127.0.0.1:80#

#location~\.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on127.0.0.1:9000#

location~\.php$ {

root html;

fastcgi_pass127.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测试文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值