您的位置:首页 > 运维架构 > Nginx

Linux 系统(ubuntu和CentOS)nginx服务器和php安装

2017-05-14 16:05 791 查看

linux 之CentOS

1:输入
yum
install nginx
命令进行nginx的安装,当需要确认时输入”y“确认。

2:输入
service
nginx start
启动nginx服务。
3:输入
wget http://127.0.0.1[/code]测试nginx服务。  
 


安装php及相应组件

1:输入
yum
install php php-fpm
命令进行PHP的安装,当需要确认时输入”y“确认。

2:输入
service
php-fpm start
启动php-fpm服务,并使用命令
cat
/etc/php-fpm.d/www.conf |grep -i 'listen ='
查看php-fpm配置。
3:使用命令
nginx
-t
查找nginx配置文件,并使用
vi
命令修改该配置文件:
4:

在配置文件中找到以下片段,修改红色部分。

server {
listen       80;
root   /usr/share/nginx/html;
server_name  localhost;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}

}


修改后保存,输入
service nginx restart
重启nginx服务。

在web目录下创建index.php:
vi /usr/share/nginx/html/index.php


写入如下内容:
<?php
echo "<title>Test Page</title>";
echo "hello world";
?>


在浏览器中,访问CentOS云服务器公网IP+php网页名称查看环境配置是否成功,如果页面可以显示“hello world”,说明配置成功。
若您无法访问此网页,请查看您的服务器是否配置了安全组导致端口无法被访问。


Linux 之Ubuntu 

1.安装Nginx

apt-get install nginx


2.启动Nginx

service nginx start

3.访问服务器IP

如果看到“Welcome to nginx!”说明安装好了。

4.安装PHP

apt-get install php5-fpm

5.配置Nginx

vi /etc/nginx/sites-available/default

找到下列代码,去掉相应注释

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}

重启服务

service nginx restart

6.默认的网站根目录在/var/www/html

vi /var/www/html/test.php

输入以下内容,并保存

<?php
echo phpinfo();
?>

访问网站IP/test.php,如果可以看到phpinfo的信息说明php安装成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐