服务器环境配置nginx / php / php-fpm(一)
2017-04-12 11:15
741 查看
登陆,升级应用,查询和关闭selinux
添加非root用户
ssh配置
禁止密码与root登陆,先确定sudo权限,打开 /etc/ssh/sshd_config,修改 PasswordAuthentication 的值为 no,取消注释。修改PermitRootLogin同上。重启SSHD。
PHP、PHP-FPM 安装
PHP-FPM配置
在配置文件中有 include=/etc/php-fpm.d/*.conf , 表示池定义 pool definition 在php-fpm.d目录下
安装nginx
建立网站目录与日志目录
建立 /etc/nginx/conf.d/example.conf
重启
检查防火墙,检查端口,检查selinux /getenforce ,最后可以编辑一个phpinfo页面放在网站根目录,在主机设置好hosts映射到虚拟机,终于可以在主机浏览器中输入虚拟机地址,见到php页面了。
多虚拟机参考http://www.androiddev.net/webserver-apache-to-nginx/
配置参考 http://huoding.com/2013/10/23/290
yum update
getenforce setenforce 0 vi /etc/selinux
添加非root用户
adduser deploy passwd deploy usermod -a -G wheel deploy vi /etc/sudoers %wheel ALL=(ALL) ALL
ssh配置
ssh deploy@123.456.78.90 ssh-keygen mkdir ~/.ssh scp ~/.ssh/id_rsa.pub deploy@123.456.78.90: touch ~/.ssh/authorized_keys cat ~/id_rsa.pub >> ~/.ssh/authorized_keys chown -R deploy:deploy ~/.ssh chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
禁止密码与root登陆,先确定sudo权限,打开 /etc/ssh/sshd_config,修改 PasswordAuthentication 的值为 no,取消注释。修改PermitRootLogin同上。重启SSHD。
service sshd restart
PHP、PHP-FPM 安装
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm; //32位地址 http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm; sudo yum -y --enablerepo=epel,remi,remi-php56 install php-fpm php-cli php-gd php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-devel;
PHP-FPM配置
sudo vi /etc/php-fpm.conf //修改以下两处,1分钟内子进程失败达到10个就优雅重启 emergency_restart_threshold = 10 emergency_restart_interval = 1m
在配置文件中有 include=/etc/php-fpm.d/*.conf , 表示池定义 pool definition 在php-fpm.d目录下
vi /etc/php-fpm.d/www.conf //修改用户,尽量每个网站一个用户 user = deploy group = deploy //与nginx请求处理的端口 listen = 127.0.0.1:9000 //服务器内存除以进程占用内存 pm.max_children = 50 //开启服务时自动开启的准备进程数 pm.start_servers = 3 //每个池的最大进程数 pm.max_requests = 1000 //慢日志 slowlog = /path/to/slowlog.log request_slowlog_timeout = 5s //最后重启服务 sudo service php-fpm restart chkconfig php-fpm on
安装nginx
sudo yum install nginx; sudo systemctl enable nginx.service; sudo systemctl start nginx.service;
建立网站目录与日志目录
mkdir -p /home/deploy/apps/example.com/current/public mkdir -p /home/deploy/apps/logs chmod -R +rx /home/deploy
建立 /etc/nginx/conf.d/example.conf
server { listen 80; server_name example.com; index index.php; client_max_body_size 50M; error_log /home/deploy/apps/logs/example.error.log; access_log /home/deploy/apps/logs/example.access.log; root /home/deploy/apps/example.com/current/public; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php { try_files $uri=404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; } }
重启
sudo systemctl restart nginx.service sudo chkconfig nginx on //如果权限失败了, 以root权限启动 sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
检查防火墙,检查端口,检查selinux /getenforce ,最后可以编辑一个phpinfo页面放在网站根目录,在主机设置好hosts映射到虚拟机,终于可以在主机浏览器中输入虚拟机地址,见到php页面了。
多虚拟机参考http://www.androiddev.net/webserver-apache-to-nginx/
配置参考 http://huoding.com/2013/10/23/290
server { listen 80; server_name foo.com; root /path; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri =404; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; } }
fastcgi_pass unix:/dev/shm/php-fpm.sock;
相关文章推荐
- 服务器环境配置nginx / php / php-fpm(二)
- 服务器环境配置nginx / php / php-fpm(一)
- linux后台服务器开发环境部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))
- nginx php-fpm环境中chroot功能的配置使用方法
- 搭建LNMP(linux+nginx+mysql+php)服务器环境配置实例教程
- LNMP(linux+nginx+mysql+php)服务器环境配置
- LNMP(linux+nginx+mysql+php)服务器环境配置
- ubuntu nginx+mysql+php 服务器环境自动配置脚本
- LNMP(linux+nginx+mysql+php)服务器环境配置
- centos 配置nginx php-fpm mysql 环境步骤
- LNMP(linux+nginx+mysql+php)服务器环境配置
- Linux Debian 下LNMP服务器——nginx+mysql+php环境搭建及配置
- LNMP(linux+nginx+mysql+php)服务器环境配置
- LNMP(linux+nginx+mysql+php)服务器环境配置
- Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)
- LNMP(linux+nginx+mysql+php)服务器环境配置
- nginx 反向代理apache服务器 配置java与PHP共存环境
- LNMP(linux+nginx+mysql+php)服务器环境配置
- Linux下从零开始安装配置Nginx服务器+PHP开发环境
- LNMP(linux+nginx+mysql+php)服务器环境配置