系统环境:
阿里云centos7.0操作系统
安装步骤:
1.添加nginx官方源:
systemctl start mariadb
mysqladmin -u root password "密码"
4.创建php的session目录及设置权限:
mkdir /var/lib/php/session
1.配置nginx:
cd /etc/nginx/conf.d
cp default.conf default.conf.bak
vi default.conf
去掉文件中下方语句的#注释
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
修改下方语句,增加index.php
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
由于centos7默认使用的是firewalld防火墙,不再是iptables,许多人不习惯,把默认的卸载,重新安装了iptables,不建议这样做,firewalld功能更强大,使用也简单。防火墙中把http服务放行设置如下(配置文件:/etc/firewalld/zones/public.xml):
firewall-cmd --permanent --zone=public --add-service=http
systemctl start nginx
systemctl start php-fpm
systemctl enable nginx
systemctl enable php-fpm
域名指向:
cd /etc/nginx/conf.d
cp default.conf www.***.com.conf
vi www.***.com.conf
1.第三行 service_name 改成 www.***.com
2.第七行 root 改成 /usr/share/nginx/www.***.com;
此处由于是拷贝的default.con,所以默认首页index和 location ~ \.php$ 应该是配置好的。如没配置好请参考defualt.con配置过程
3.mkdir /usr/share/nginx/www.***.com
4.cd /usr/share/nginx/www.***.com
5.vi index.html
输入 hello world
6.systemctl reload nginx 重启nginx服务
7.到万网等域名服务商将域名A记录指向服务器ip
8.稍等十分钟或半小时(部分网络可能更久,如域名之前就指向当前服务器ip,立即刷新即可看到效果),浏览器输入域名即可访问
可能出现的错误:
无法访问.php后缀的文件
打开相关的conf文件。修改location ~ \.php$ 中的root 和 fastcgi_param
root /usr/share/nginx/www.***.com
fasfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
阿里云centos7.0操作系统
安装步骤:
1.添加nginx官方源:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx php-fpm php-gd php-mysql mariadb-server
3.设置mariadb的root密码:
systemctl start mariadb
mysqladmin -u root password "密码"
4.创建php的session目录及设置权限:
mkdir /var/lib/php/session
chmod 777 /var/lib/php/session -R
配置步骤:
1.配置nginx:
cd /etc/nginx/conf.d
cp default.conf default.conf.bak
vi default.conf
去掉文件中下方语句的#注释
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
修改下方语句,增加index.php
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
2.防火墙中打开http服务:
由于centos7默认使用的是firewalld防火墙,不再是iptables,许多人不习惯,把默认的卸载,重新安装了iptables,不建议这样做,firewalld功能更强大,使用也简单。防火墙中把http服务放行设置如下(配置文件:/etc/firewalld/zones/public.xml):
firewall-cmd --permanent --zone=public --add-service=http
systemctl reload firewalld
3.启动lnmp环境及设置开机启动:
systemctl start nginx
systemctl start php-fpm
systemctl enable nginx
systemctl enable php-fpm
systemctl enable mariadb
4.浏览器中输入你服务器的ip,可以显示正常的nginx欢迎页
域名指向:
cd /etc/nginx/conf.d
cp default.conf www.***.com.conf
vi www.***.com.conf
1.第三行 service_name 改成 www.***.com
2.第七行 root 改成 /usr/share/nginx/www.***.com;
此处由于是拷贝的default.con,所以默认首页index和 location ~ \.php$ 应该是配置好的。如没配置好请参考defualt.con配置过程
3.mkdir /usr/share/nginx/www.***.com
4.cd /usr/share/nginx/www.***.com
5.vi index.html
输入 hello world
6.systemctl reload nginx 重启nginx服务
7.到万网等域名服务商将域名A记录指向服务器ip
8.稍等十分钟或半小时(部分网络可能更久,如域名之前就指向当前服务器ip,立即刷新即可看到效果),浏览器输入域名即可访问
可能出现的错误:
无法访问.php后缀的文件
打开相关的conf文件。修改location ~ \.php$ 中的root 和 fastcgi_param
root /usr/share/nginx/www.***.com
fasfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;