Fedora17 Configure Nginx + Mysql + php

Source: Internet
Author: User
Tags mcrypt tidy
Fedora17 Configure Nginx + Mysql + php 1. install Mysql5

yum install mysql mysql-serverchkconfig --levels 235 mysqld on

Start

/etc/init.d/mysqld start

Check whether startup is enabled

netstat -tap | grep mysql

When mysql cannot be started

vi /etc/my.cnf

# Skip networking

Restart mysql

/etc/init.d/mysqld restart

Set the mysql password:

Method 1:

mysqladmin -uroot password

Method 2 (set the root user password) (recommended ):

mysql_secure_installation

The system automatically starts mysql

Method 1 (recommended ):

systemctl enable mysqld.servicesystemctl start mysqld.service

Method 2:

chkconfig --levels 235 mysqld on

2. install Nginx

yum install nginx

Set startup

Method 1:

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

Method 2:

systemctl enable nginx.servicesystemctl start nginx.service

3. install PHP

Method 1: fastcgi mode

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

Method 2: php-fpm mode (recommended)

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

Configure php

vi /etc/php.ini

Cgi. fix_pathinfo = 0 (it is recommended to set it to 0. the default value is 1. if it is 1, a security vulnerability will occur)

View local time zone

cat /etc/sysconfig/clock

Modify configurations

Date. timezone = "Asia/Shanghai"

Start php
I. startup in spawn-fcgi mode
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

Set boot start:

Add 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

2. start in php-fpm mode

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

Note:

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

Search for a long time, have not found, at first thought did not change the php-rpm.conf.default to php-rpm.conf, and later found that in fact this file already exists.

Later the reason was finally found in the log through the systemctl status php-fpm.service:
The original is not configured with a php-rpm.conf and it contains the file/etc/php-fpm.d/www. conf
In this file
Default user = apache
Default to group = apache
Because nginx is installed, you can start php-fpm after changing all to nginx.

4. Configure nginx

vi /etc/nginx/nginx.conf

Worker_processes 5; keepalive_timeout 2; server {listen 80; server_name localhost; # it must be set here, otherwise php # charset KOI8-R cannot be supported; # access_log logs/host. access. log main; location/{root/usr/share/nginx/html; 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/50 x.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. htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\. Ht {deny all ;}}

Restart nginx

systemctl reload nginx.service

5. write a php test file

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.