1, 安装软件包
#首先删除httpd
yum -y remove httpd
#安装仓库源
yum -y install epel-release
yum -y install nginx mysql mysql-server php php-fpm php-mysql #lnmp常用的包
yum -y install php-gd php-mbstring php-xml #php可选的扩展包
#查看php版本:默认是php5.3
[root@c6 www]# php -v
PHP 5.3.3 (cli) (built: Nov 1 2019 12:28:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
2,配置nginx使用fastcgi
a, php监听http端口
nginx配置fastcgi官方示例:http://nginx.org/en/docs/beginners_guide.html#fastcgi
#启动mysql
[root@c6 ~]# service mysqld start
[root@c6 ~]# mysqladmin -uroot password '123456';
#启动php-fpm: fastcgi 程序,默认端口9000
[root@c6 ~]# service php-fpm start
[root@c6 ~]# ss -nltp |grep 9000
LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",6119,7),("php-fpm",6120,0),("php-fpm",6121,0),("php-fpm",6122,0),("php-fpm",6123,0),("php-fpm",6124,0))
#查看nginx配置
[root@c6 ~]# ls /etc/nginx/
conf.d koi-utf scgi_params
default.d koi-win scgi_params.default
fastcgi.conf mime.types uwsgi_params
fastcgi.conf.default mime.types.default uwsgi_params.default
fastcgi_params nginx.conf win-utf
fastcgi_params.default nginx.conf.default
[root@c6 ~]# ls /etc/nginx/conf.d/
default.conf.bak proxy.conf.bak virtual.conf
myfashcgi.conf ssl.conf web.conf.bak
[root@c6 ~]# cat /etc/nginx/conf.d/myfashcgi.conf
server {
listen 80;
server_name c6;
location ~ \.php$ {
root /data/www;
#fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
include fastcgi_params;
}
}
b, php监听unix socket
[root@c6 ~]# grep listen /etc/php-fpm.d/www.conf
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; 'port' - to listen on a TCP socket to all addresses on a
; '/path/to/unix/socket' - to listen on a unix socket.
#listen = 127.0.0.1:9000
listen = /tmp/php-fpm.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
;listen.backlog = -1
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
listen.allowed_clients = 127.0.0.1
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666
3,测试lnmp
#测试lnmp环境
[root@c6 ~]# ls /data/www/
index.html index.php mysql.php
[root@c6 ~]# cat /data/www/index.php
<?php phpinfo() ?>
[root@c6 ~]# cat /data/www/mysql.php
<?php
$res=mysql_connect("localhost","root","123456");
if (!$res) echo "faild,mysql";
else echo "ok,mysql";
?>
[root@c6 ~]# curl localhost/index.php |head
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 51216 0 51216 0 0 31.8M 0 --:--:-- --:--:-- --:--:-- 48.8M
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
.center {text-align: center;}
[root@c6 ~]#
[root@c6 ~]#
[root@c6 ~]#
[root@c6 ~]# curl localhost/mysql.php
ok,mysql[root@c6 ~]#