1、创建lnmp.py文件
$ vim lnmp.py
------------------------>
#!/usr/bin/env python
from fabric.colors import *
from fabric.api import *
env.user = ‘root‘
env.roledefs = {
‘localhost‘: [‘127.0.0.1‘]
}
env.password = ‘redhat‘
@roles(‘localhost‘)
def lnmptask():
print yellow("A key to install LNMP...")
with settings(warn_only=True):
run(‘yum groupinstall mariadb -y‘)
run(‘yum install nginx -y‘)
run(‘yum install php php-fpm php-mysql php-mbstring php-xml php-mcrypt php-gd -y‘)
run(‘systemctl start nginx‘)
run(‘systemctl enable nginx‘)
run(‘systemctl start mariadb‘)
run(‘systemctl enable mariadb‘)
run(‘systemctl start php-fpm‘)
run(‘systemctl enable php-fpm‘)
def deploy():
execute(lnmptask)
2、运行lnmp.py
$ fab -f lnmp.py deploy
3、修改nginx.conf文件,使其支持php。以下代码中只有中文标注部分是手动添加的!
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.php index.html index.htm;
}
#从下一行的location开始,往下6行都是添加的内容, 其它的都是默认的。
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
4、添加测试页面
$ sudo vim /usr/share/nginx/html/index.php
[/usr/share/nginx/html/index.php]
<?php
phpinfo()
?>
5、重启nginx服务并测试
#重启服务 $ sudo systemctl restart nginx #浏览器打开测试页面 http://10.0.0.20
原文:http://www.cnblogs.com/jefflee168/p/7425364.html