CentOS 7.2 To build a LNMP environment Tutorial _php Example

Source: Internet
Author: User
Tags fpm install php mcrypt php source code phpmyadmin

Native environment: Server is Aliyun ECS; the mirror used is: public mirror CENTOS 7.2

A. Nginx installation

1. Download the Nginx package (package) corresponding to the current system version

​ wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2. Establishment of the Nginx Yum warehouse (default yum is not nginx)

​ rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

3. Download and install Nginx

​ yum install nginx

4.nginx Boot (nginx installation directory-/usr/sbin/)

systemctl start nginx.service

PS: Some other Nginx related commands:

Nginx Related configuration file:

The default profile is under the/etc/nginx path, and the configuration can already be run correctly with Nginx;

If you need to customize, modify its nginx.conf and other documents can be;

Enter the IP of the machine that deploys the NGINX environment in the browser address bar, if all is OK, should be able to see the content of the following words.

Welcome to nginx!

If you have this page, the Nginx Web server is successfully installed andworking. Further configuration is required.

For online documentation and support to refer Tonginx.org.Commercial support is available atnginx.com.

Thank for using Nginx.

Step two: MySQL installation

1. First download the MySQL repo source; related commands:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. Install MYSQL-COMMUNITY-RELEASE-EL7-5.NOARCH.RPM Package

(After installing this package, you will get two MySQL yum repo sources:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/ Mysql-community-source.repo)

​ rpm -ivh mysql-community-release-el7-5.noarch.rpm

3. Install MySQL

​ sudo yum install mysql-server

4. Reset Password

To change user rights:

sudo chown -R root:root /var/lib/mysql

Restart Service:

systemctl restart mysql.service

Log in and modify the password:

Mysql-u root

mysql > use MySQL;

MySQL > Update user set Password=password (' 123456 ') where user= ' root ';

MySQL > exit;

Step Three: Install PHP

1. View the currently installed PHP version (Yum list installed | grep php)

If there is a PHP installation package first remove the previous version with Yum Remove the PHP-related package

2.rpm installation PHP7 corresponding Yum source

RPM-UVH https://mirror.webtatic.com/yum/el7/epel-release.rpm

RPM-UVH https://mirror.webtatic.com/yum/el7/ webtatic-release.rpm

3. Install php7.0

yum install php70w

4. Install PHP extensions

php70w-mysql.x8664 MySQL extensions (php70w-pdo.x8664 installed as dependencies)

php70w-gd.x86_64GD Library, is the PHP processing graphics extension Library, the GD library provides a series of APIs used to process pictures, using the GD library can process pictures, or generate pictures.

php70w-ldap.x86_64Lightweight Directory Access Protocol (Servers), a protocol for accessing directory servers;

php70w-mbstring.x86_64The mbstring extension library is used to handle multibyte strings, and PHP's built-in string-length function strlen not handle Chinese strings correctly, and it gets just the number of bytes in the string. For GB2312 Chinese encoding, strlen gets twice times the number of Chinese characters, and for UTF-8 encoded Chinese, it is 1~3 times the difference. Using the Mb_strlen function can solve this problem better.

php70w-mcrypt.x86_64The MCrypt extension library can be encrypted and decrypted, which can either encrypt plaintext or restore ciphertext.

5. Install PHP FPM

​ yum install php70w-fpm

About PHP-FPM

PHP-FPM is actually a patch of PHP source code, designed to integrate FASTCGI process management into the PHP package. It must be patch to your PHP source code and can be used only after compiling and installing PHP.

Now we can download the new PHP 5.3.2 source tree to directly integrate the PHP-FPM branch, it is said that the next version will be merged into the main branch of PHP. Relative SPAWN-FCGI,PHP-FPM in the CPU and memory control is better, and the former is very easy to crash, must be monitored with crontab, and PHP-FPM does not have this annoyance.

PHP5.3.3 has integrated PHP-FPM and is no longer a third party package. PHP-FPM provides a better way to manage PHP processes, can effectively control memory and process, can smooth overload PHP configuration, than spawn-fcgi has more advantages, so by the official PHP included. /configure with –ENABLE-FPM parameters to open the PHP-FPM.

Using PHP-FPM to control the fastcgi process of php-cgi

Fourth Step: Configure Nginx

Remember to backup before modifying configuration files

1.nginx Configuration file Location: (/etc/nginx/conf.d/default.conf)

Modify the Web root directory (you can use the default if there is no need to modify it):

root/wwwdata/html;

Configure PHP parsing, and modify the black bold section in the following code:

Location ~.php$ {

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.php;

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Include    Fastcgi_params;

}

2.PHP-FPM Configuration file Location: (/etc/php-fpm.d/www.conf)

Modify

User =nginx

Group=nginx

3. Start Nginx Service:

systemctl start nginx.service

To set the Power-on self use the following command:

sudo systemctl enable nginx.service

To view the startup status:

systemctl status nginx 

See the following words to say start success!

Active:active (running) since six 2016-11-19 13:40:04 CST; 50min ago

4. Start PHP-FPM:

systemctl start php-fpm.service

If you want to set up the Power-on self test the following command:

sudo systemctl enable php-fpm.service

To view the startup status:

systemctl status php-fpm.service

See the following words to say start success!

Active:active (running) since six 2016-11-19 14:14:33 CST; 18min ago

So far, Php+mysql+nginx environment to complete!

Finally, under the Web root directory under the next PHP file test;

For more convenient access to modify the database, you need to install the MySQL administration tool phpMyAdmin

Jump Web root: (jump to the root of your site based on previous settings)

cd/wwwdata/html/

To download the PMA installation package:

wget https://files.phpmyadmin.net/phpMyAdmin/4.4.12/phpMyAdmin-4.4.12-all-languages.zip

Unpack the installation package:

unzip phpMyAdmin-4.4.12-all-languages.zip

Here if the lack of unzip need to first install unzip;

yum install unzip zip

Renaming an installation folder

mv phpMyAdmin-4.4.12-all-languages phpmyadmin

Modify session Hosting Directory permissions:

chown -R nginx.nginx /var/lib/php/session

If you need to modify the location of the session root directory:

Modify Session.save_path in/etc/php.ini

Because the Session.save_path in the/etc/php-fpm.d/www.conf is higher than the php.ini priority, the Session.save_path in the presence of/etc/php-fpm.d/www.conf only needs to modify this A Can

Visit Http://youipaddress/phpmyadin, if you can access, then success!

I thought it would be okay, but there's a problem with the login! Landing not on!

Made a change:

1. Modify the/var/lib/php/session folder permissions more than 770

2. Modify the $cfg ' Servers ' [' user '] = ' root ' in the phpMyAdmin directory config.sample.inc.php, $cfg ' Servers ' [' password '] = ' 123456 '; User name password set for oneself;

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.