Installing Nginx + MySQL + PHP5 (PHP-FPM mode) LNMP in Fedora 14

Source: Internet
Author: User
Tags gpg
Document directory
  • 1 Preface remarks
  • 2. Install mysql5
  • 3. Install nginx
Installing Nginx + MySQL + PHP5 (PHP-FPM mode) LNMP in Fedora 14

20:17:40 | category: Fedora | Tag: php nginx mysql root html | large font size, small/medium subscription

Nginx (pronounced "engine x") is a free, open-source, and high-performance HTTP server. Nginx is also known for its stability, rich functions, simple configuration, and low resource consumption. This tutorial will show you how to install Nginx + MySQL + PHP5 in a Fedora 14 (PHP-FPM Mode)

I have tested it correctly. This will ensure you can work!

1 Preface remarks

In this tutorial, the user name I use is www.unixbar.net and the IP address is 192.168.0.100. These settings may be different from yours, so you need to modify them in a proper place.

2. Install MySQL5

Run the following command to install MySQL:

yum install mysql mysql-server

Then we create a system startup connection for MySQL (in this case, MySQL will be automatically started when the system starts) and start the MySQL server:

chkconfig --levels235 mysqld on/etc/init.d/mysqld start

Check whether network access is supported and run:

netstat-tap|grep mysql

The following information should be displayed:

[root@server1 ~]# netstat -tap | grep mysql tcp        0      0 *:mysql                     *:*                         LISTEN      1717/mysqld [root@server1 ~]#

If it is not displayed, edit the/etc/my. cnf file and comment out the skip-networking parameter:

vi/etc/my.cnf
[...] #skip-networking [...]

And restart the MySQL server:

/etc/init.d/mysqld restart

Set a password for the root user (otherwise anyone can access your MySQL database ):

[root@server1 ~]# mysql_secure_installation
NOTE: running all parts of this script is recommended for all MySQLSERVERS in production use! Please read each step carefully! In order to log into MySQL to secure it, we'll need the currentpassword for the root user. if you 've just installed MySQL, andyou haven' t set the root password yet, the password will be blank, so you shoshould just press enter here. enter current password for root (enter for none): <-- press ENTER to OK, successfully used password, moving on... setting the root password ensures that nobody can log into the My SQLroot user without the proper authorisation. Set root password? [Y/n] <-- press ENTER key New password: <-- enter your password Re-ENTER new Password: <-- repeat your password updated successfully! Reloading privilege tables... Success! By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. this is intended only for testing, and to make the installationgo a bit smoother. you shoshould remove them before moving into aproduction environment. remove anonymous users? [Y/n] <-- press ENTER... Success! Normally, root shoshould only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] <-- press ENTER... Success! By default, MySQL comes with a database named 'test' that anyone canaccess. this is also intended only for testing, and shocould be removedbefore moving into a production environment. remove test database and access to it? [Y/n] <-- press ENTER-Dropping test database... Success! -Removing privileges on test database ...... Success! Reloading the privilege tables will ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [Y/n] <-- press ENTER... Success! Cleaning up... All done! If you 've completed all of the above steps, your MySQLinstallation shoshould now be secure. Thanks for using MySQL! [Root @ server1 ~] #
3. Install Nginx

Nginx is the default package of Fedora 14. You can run the following command to install it:

yum install nginx

Then we create a system startup link for nginx and start it:

chkconfig --levels235 nginx on /etc/init.d/nginx start

Enter your server IP address or host name (for example, http: // 192.168.0.100) in your browser. Then you can see the nginx welcome page:

4. Install PhP5
The official Fedora 14 source does not contain php-fpm, but we can use the Remi repository source. Use the following command to add a Remi repository Source

rpm -ivh http://rpms.famillecollet.com/remi-release-14.rpm

Open the tc/yum. repos. d/remi. repo file.

vi/etc/yum.repos.d/remi.repo

Change the enabled of the [remi] department to 1. Change Gpgcheck to 0. Do not modify other

[remi]name=Les RPM de remi pour Fedora $releasever - $basearch#baseurl=http://rpms.famillecollet.com/fedora/$releasever/remi/$basearch/mirrorlist=http://rpms.famillecollet.com/fedora/$releasever/remi/mirrorenabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remifailovermethod=priority [remi-test]name=Les RPM de remi en test pour Fedora $releasever - $basearch#baseurl=http://rpms.famillecollet.com/fedora/$releasever/test/$basearch/mirrorlist=http://rpms.famillecollet.com/fedora/$releasever/test/mirrorenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remifailovermethod=priority

Now we have installed php-cli and other PHP5 modules, such as php-mysql, which enables your PHP script to support MySQL:

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-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

Open the/etc/php. ini file and unregister cgi. fix_pathinfo = 1:

vi/etc/php.ini
[...]; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfocgi.fix_pathinfo=1[...]

Now we create a php-fpm system startup connection and start it:

chkconfig --levels235 php-fpm on/etc/init.d/php-fpm start

Php-fpm is a background process (the initialization script is/etc/init. d/php-fpm) and runs on a FastCGI server with port 9000.

5 configure nginx
Now open the nginx configuration file/etc/nginx. conf:

vi/etc/nginx/nginx.conf

Easy to understand configuration files
(You can learn more about the configuration methods http://wiki.codemongers.com/NginxFullExample and http://wiki.codemongers.com/NginxFullExample2 on the following websites)
First, you can increase the number of worker processes and set keepalive_timeout to a reasonable value:

[...]worker_processes  5;[...]keepalive_timeout  2;[...]

The VM is defined in the server {} container. Use the following command to modify the default VM:

[...]    server {        listen       80;        server_name  _;         #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           /usr/share/nginx/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;        }    }[...]

Server_name; you can confirm your domain name by modifying www.unixbar.net.
In the location/section, I added index. php to the index row. Root/usr/share/nginx/html indicates that the document path is/usr/share/nginx/html.
The most important part of PHP is location ~ \. Php $ {}. Uncomment it. Change the root line to the document path of the website. For example, root/usr/share/nginx/html. Make sure that the fastcgi-param line is changed to fastcgi_param SCRIPT_FILENAME/usr/share/nginx/html $ fastcgi_script_name; otherwise, the PHP parser will not find the PHP called in the browser.
Now we save the file and restart nginx:

/etc/init.d/nginx restart

Now, create the following PHP file in the document path root/usr/share/nginx/html:

vi/usr/share/nginx/html/info.php
<?phpphpinfo();?>

Now, we can access and ask through http: // 192.168.0.100/info. php in the browser.

As you can see in the Server API line, PHP5 is now running properly in FPM/FastCGI mode. If you continue to look down, you can see the modules supported by PHP5, including the MySQL module:

 

7. Original article address

Http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-on-fedora-14

Http://www.unixbar.net/linux/fedora/1106.html

Related Article

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.