This article consists of Su Yi Lin Feng provide sponsorship, starting in Slime Line the world
Previously installed under the CentOS software are like source installation, but yesterday because of a thing need a centos under the LNMP environment. Instead of doing it, it was deliberately recorded today for future use.
First, install Nginx
Let's install Nginx first, as follows:
Yum-y Install Nginx
Through, we can see that there is no nginx software package in the current Yum source. We need to install a Yum source with Nginx, as follows:
RPM-IVH http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
View the RPM package just installed, as follows:
RPM-QL Nginx-release-centos-6-0.el6.ngx.noarch
Through, we can clearly see just installed RPM package, just add a new nginx yum source. View the Yum source as follows:
Cat/etc/yum.repos.d/nginx.repo
Now let's install Nginx via Yum, as follows:
Yum-y Install Nginx
Through, we can clearly see that Nginx has been installed.
Now look at the location of the Nginx installation and its files as follows:
RPM-QL Nginx
Through, we can obviously see Nginx installed to the/etc/nginx directory by default, and Nginx's default website is installed in the/usr/share/nginx/html directory.
Now let's start the Nginx and visit Nginx. As follows:
/etc/init.d/nginx start
Curl http://192.168.1.124
Look at the user who used the Nginx runtime as follows:
Ps-ef |grep Nginx
Through, we can clearly see that nginx is the root user to start, but Nginx is running with the Nginx user.
Second, install PHP and PHP-FPM
To install PHP and PHP-FPM, use the following command:
Yum-y Install PHP php-fpm
View the location of the PHP-FPM installation and its files as follows:
RPM-QL PHP-FPM
To start PHP-FPM, use the following command:
/ETC/INIT.D/PHP-FPM start
Ps-ef |grep PHP-FPM
NETSTAT-TUNLP |grep 1355
Through this, we can see that the PHP-FPM runtime uses Apache as the user, and php-fpm listens to the native port 9000.
If you want to modify the PHP-FPM runtime user and port, we can modify the PHP-FPM configuration file/etc/php-fpm.d/www.conf, as follows:
cat/etc/php-fpm.d/www.conf |grep-v ' ^; ' | Grep-v ^$
third, nginx and PHP integration
Nginx and PHP integration is achieved through fastcgi, and fastcgi we generally use is php-fpm. In chapter two, we have started php-fpm, and now we are going to modify the Nginx configuration file to support PHP.
Now we modify Nginx's default Web site configuration file default.conf, as follows:
Cat/etc/nginx/conf.d/default.conf
server {
Listen 80;
server_name localhost;
Location/{
root/usr/share/nginx/html;
Index index.php index.html index.htm;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root/usr/share/nginx/html;
}
Location ~ \.php$ {
root/usr/share/nginx/html;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
}
After the configuration is complete, we re-restart Nginx and PHP-FPM, as follows:
/etc/init.d/nginx restart
/ETC/INIT.D/PHP-FPM restart
The above is modified nginx default website, now we add an nginx virtual host, and make IT support PHP, as follows:
Vi/etc/nginx/conf.d/ilanni.conf
server {
Listen 80;
server_name test.ilanni.com;
Location/{
Root/ilanni;
Index index.php index.html index.htm;
}
Location ~ \.php$ {
Root/ilanni;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
}
After the Nginx virtual host configuration file is finished, now to create the virtual host Ilanni index.php, as follows:
Mkdir/ilanni
vi/ilanni/index.php
<?php phpinfo ();?>
Modify the owning user of the Ilanni directory as follows:
Chown Nginx:nginx-r/ilanni/
ll/ilanni/
As shown, we now change the Ilanni directory to the user Nginx used by Nginx runtime.
Now let's modify the user of the PHP-FPM runtime as follows:
Vi/etc/php-fpm.d/www.conf
We will restart Nginx and php-fpm as follows:
/etc/init.d/nginx restart
/ETC/INIT.D/PHP-FPM restart
Through, we can see Nginx virtual host has been able to correctly parse PHP.
iv. installation of MySQL
To install MySQL, use the following command:
Yum-y install MySQL mysql-server php-mysql
When the installation is complete, start MySQL. As follows:
/etc/init.d/mysqld start
Now we create a mysql.php file in the Nginx Default Web site to connect to the MySQL database. mysql.php content is as follows:
cat/usr/share/nginx/html/mysql.php
<?php
$host = ' localhost ';
$root = ' root ';
$pwd = ";
$con = mysql_connect ($host, $root, $pwd);
if ($con = = False) {
echo "Connect false";
} else{
echo "Connect true";
}
?>
Restart Nginx, PHP-FPM, MySQL, as follows:
/etc/init.d/nginx restart
/ETC/INIT.D/PHP-FPM restart
/etc/init.d/mysqld restart
Now by accessing the mysql.php file, as follows:
http://192.168.1.124/mysql.php
Through, we can clearly see that PHP has parsed the mysql.php file, and has successfully connected to the MySQL database.
Slime: Learn the Quick build LNMP environment of CentOS