Here's how to install the LNMP environment under Linux using Yum.
Tools/Materials
- Server One
- One PC for personal use
- Putty Software One
Installing Nginx
- 1 Check if the program is installed:
which Nginx #查看nginx是否存在
which PHP #查看php是否存在
which MySQL #查看mysql是否存在
- 2
Yum List Nginx #列出nginx
Yum Install Nginx #安装nginx
#看见 {complete! The installation was successful.
- 3
which Nginx #查看nginx是否存在
Service Nginx start #启动nginx进程方法 [1]
/etc/init.d/nginx start #启动nginx进程方法 [2]
Ps-ef | grep nginx #查看nginx进程
- 4
Ifconfig #查看网卡信息
Open Browser: http://182.92.73.109/
See {Welcome Interface} instructions for installation success!
END
Install PHP
- 1
Install PHP:
Yum list php php-fpm #列出php and PHP-FPM exist
Yum-y Install PHP php-fpm #安装php and PHP-FPM packages
#看见 {complete! The installation was successful.
------------------------------------
Start PHP-FPM:
/ETC/INIT.D/PHP-FPM Start #1
Service PHP-FPM Start #2
- 2
Modify the Nginx configuration file to forward the PHP request to the IP and port that PHP-FPM binds to:
Vi/etc/nginx/conf.d/default.conf #行 [37-43]
Remove # #:
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;
}
Code Explanation:
When the user's request URL is at the end of. PHP
The contents of this chunk are executed:
Root-specified directory
Pass forwarding port [E]
Index if the end of the specified directory is automatically added index.php
Param to execute the file name passed in the Documnetroot
Include home configuration file [E]
Note: (1): Wq #保存 (2) I #插入 (3): q! #不保存退出
- 3
Restart Nginx:
/etc/init.d/nginx Restart #1
Service Nginx Restart #2
--------------------------------------------------
Verify that the request PHP file is processed:
vi/usr/share/nginx/html/info.php
<?php
Phpinfo ();
---------------------------------------------------
Access IP URL:
http://182.92.73.109/info.php
END
Install MySQL
- 1
Yum list MySQL mysql-server #搜索mysql数据包
Yum-y install MySQL mysql-server #不需要提示安装
#看见 {complete! The installation was successful.
- 2
See if MySQL mysql-server exists:
which MySQL #查看mysql是否存在
which Mysqld_safe #查看mysqld_safe是否存在
-------------------------------------------------------
mysql_install_db #mysql初始化, set up a system table in MySQL
Mysqld_safe & #启动mysql
Ps-ef | grep mysqld #mysqld Presence
----------------------------------------------
Mysql-uroot #链接进入mysql数据库
Ctrl-c--exit! #退出终端
END
Installing PHP extensions for MySQL operations
Yum-y Install php-mysql #安装php-mysql Extensions
Service PHP-FPM Restart #重启php-fpm process
Check if MySQL database can be manipulated via PHP:
vi/usr/share/nginx/html/db.php
<?php
@mysqli_connect ("localhost", "root", "" "," MySQL ") or Die (" Connect MySQL failed\n ");
echo "Connect ok\n";
---------------------------------------------------------
php/usr/share/nginx/html/db.php #用命令行执行php
http://182.92.73.109/db.php #在浏览器执行
/etc/init.d/mysqld stop #停止mysql进程 [1]
Service mysqld Stop #停止mysql进程 [2]
--------------------------------------------------
php/usr/share/nginx/html/db.php #用命令行执行php
http://182.92.73.109/db.php #在浏览器执行
---------------------------------------------------
See the following effect is to show that the data link is not a problem
Installing the PHP module details will be published later, so much more.
Install LNMP environment under Linux