[Linux] PHP Programmer to play Linux series-LNMP Environment building

Source: Internet
Author: User
Tags fpm

1.PHP programmer to play Linux series-How to install using CentOS

In the normal work, I as a PHP programmer often to build the environment, this environment is the Linux system installed Nginx,php,mysql three software, the software configuration, and then on the browser to open the normal running View project. There are several ways to install software in CentOS, and I often use the package installation method, because this very simple command can be installed successfully, which is the biggest difference with the software installed under Windows. Package installation Method A key word is yum.

Solve the problem of not finding the Nginx package

I first install the Web server Nginx, as well as this software, he can listen to 80 ports, bind domain name, provide Web services, you can access our project in the browser. I use the command yum install Nginx, at this time error no package nginx available, this is not this bag ah, this time need to install Enterprise Linux expansion pack Epel, using the command yum install Epel-release, Then try the new Nginx, this time can be installed, and solve the dependency problem. Using service Nginx start to open Nginx

Yum Install epel-releaseyuminstall  nginxservice nginx start

Troubleshoot problems with Web services that do not have IP access

At this point I opened the Windows browser, access to my previous settings address: http://192.168.2.100, inaccessible, in this case, I first use the PS command to see if the nginx process is open, Then use the netstat command to see if Port 80 is listening.

PS aux| grep  -altupn| grep  the

These two commands to see after the discovery is normal, it should be blocked by the firewall, I use the service iptables stop off the firewall, this time to visit the Ip,nginx test page appeared, it is really a firewall problem, I want to open the firewall port 80, Iptables Open Port profile is/etc/sysconfig/iptables, I copied its own 22 port rule, changed to 80, after saving, service iptables start, this time access is also normal.

Bind domain Name

I want to access this site through the domain name, such as I visit http://www.qingguow.cn, can see the server site directory, this time to configure Nginx to bind the domain name. Enter the directory/etc/nginx/conf.d, copy the configuration file from the virtual.conf, changed to www.qingguow.cn.conf, note that the suffix must be. conf, edit this configuration file, reboot the Nginx.

server {    listen       ;    server_name  www.qingguow.cn;     / {        root   /usr/local/web;        Index  index.html index.htm;    }}

I created a new index.html file in the/usr/local/web directory, which wrote a word, modify the Windows host file, point the domain name to my virtual machine IP

192.168.2.100 www.qingguow.cn

At this point I directly access the domain name can see just the index.html file, the browser will also prompt you this domain is redirected

At this point I can go to see the Nginx Access and error log, the default is/var/log/nginx/access.log, using tail-f This command, you can monitor the log file in real time

Tail-f/var/log/nginx/access.log, this can help me know, at this time Nginx really is running normally.

Installing and configuring PHP

I have created a new index.php file in the previous directory, direct access to this file, the browser will pop up the download box, the file is downloaded directly, this time will install PHP

Yum Install  -V

This version or PHP 5.3 is very old, and later I will write to upgrade PHP. PHP has been installed successfully at this time, but it has not been paired with nginx and needs to be installed PHP-FPM

Yum Install php-fpm# open php-fpmservice php-fpm start

At this point the PHP-FPM has been turned on, and the default listening 9000 port, configure Nginx to support PHP, edit www.qingguow.cn.conf, changed to the following configuration file. There are a few things to note in the configuration file:

1. Root command mentions outside the location directive to resolve file not found errors

2. Fastcgi_pass instruction, Nginx connection fastcgi

3. Fastcgi_param script_filename Specifies this parameter, also resolves file not found error

4. File not found error, Nginx error.log error log is fastcgi sent in stderr: "Primary script Unknown", search this can find a solution

5. When encountering an error, be sure to look at the error log and then go to the symptomatic search.

server {    listen       ;    server_name  www.qingguow.cn;    Root   /usr/local/web;     / {        index  index.html index.htm index.php;    }     ~ \.php {        fastcgi_pass   127.0.  0.1:9000, #指定FastCGI服务器监听端口与地址        fastcgi_param script_filename $document _root$fastcgi_ Script_name; #指定脚本的路径        include fastcgi_params; #加载一些参数, this file already exists    }}

Create a new index.php file, use the Phpinfo () function to print a look at the parameters of PHP, the browser access, is normal.

Installing the MySQL Database

Next i will install MySQL database, this I can use PHP to connect and use the MySQL database. I want to install MySQL and mysql-server One is the client, a server, the default installed MySQL database, the user name is root, the password is empty, this is not very safe, of course, now this database can only be our local to connect, not remote connection, there is no problem, The problem of adding users and fixing passwords will be dealt with later.

#安装客户端 Yum Install mysql# installation Service side Yum Install mysql--hlocalhost-uroot-p

This time, the LNMP environment is finished.

[Linux] PHP Programmer to play Linux series-LNMP Environment building

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.