立即注册 找回密码

QQ登录

只需一步,快速开始

查看: 6552|回复: 0

[Linux主机系统教程] CentOS7安装配置LEMP(Nginx/PHP-FPM 5.6/MySQL 5.5)网站环境过程

[复制链接]
发表于 2015-4-7 12:23:50 | 显示全部楼层 |阅读模式
道勤网-数据www.daoqin.net

亲注册登录道勤网-可以查看更多帖子内容哦!(包涵精彩图片、文字详情等)请您及时注册登录-www.daoqin.net

您需要 登录 才可以下载或查看,没有账号?立即注册

x

一般大型的网站建站环境都会采用Nginx系统环境架构,相对而言比Apache承受承载的线程和压力更大,不过对于一般的博客、网站来说,Apache环境也足够使用。在之前的相关文章中,无论是LNMP一键安装包、还是LEMP一键包、以及AMH等WEB面板,都是采用NGINX搭建的网站环境。

在这篇文章中,道勤小编整理一篇基于最新的CentOS7系统,搭建和应用Nginx/PHP-FPM 5.6/MySQL 5.5适用的网站环境,如果你也喜欢折腾,可以尝试下面的内容,文章是从海外翻译过来的,且进行过测试是完整的。

第一、安装EPEL和REMI库文件

  1. rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
  2. rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
复制代码

第二、安装Nginx

  1. yum install nginx -y
复制代码

启动和设置开机启动

  1. systemctl start nginx
  2. systemctl enable nginx
复制代码

设置防火墙开启80端口

  1. firewall-cmd --zone=public --add-port=80/tcp --permanent$ sudo firewall-cmd --reload
复制代码

这里我们已经安装完毕NGINX,我们可以打开IP地址浏览器中,可以看到成功的NGINX安装界面提示。

9999.jpg

第三、安装MariaDB 5.5

  1. yum --enablerepo=remi,remi-php56 install mariadb-server mariadb -y
复制代码

启动和设置开机启动

  1. systemctl start mariadb
  2. systemctl enable mariadb
复制代码

设置数据库的安全

/usr/bin/mysql_secure_installation

执行上面脚本,根据提示我们需要设置一遍数据库的安全,删除匿名用户等。

  1. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  2. SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
  3. In order to log into MariaDB to secure it, we'll need the current
  4. password for the root user.  If you've just installed MariaDB, and
  5. you haven't set the root password yet, the password will be blank,
  6. so you should just press enter here.
  7. Enter current password for root (enter for none):
  8. OK, successfully used password, moving on...
  9. Setting the root password ensures that nobody can log into the MariaDB
  10. root user without the proper authorisation.
  11. Set root password? [Y/n] y
  12. New password:
  13. Re-enter new password:
  14. Password updated successfully!
  15. Reloading privilege tables..
  16. ... Success!
  17. By default, a MariaDB installation has an anonymous user, allowing anyone
  18. to log into MariaDB without having to have a user account created for
  19. them.  This is intended only for testing, and to make the installation
  20. go a bit smoother.  You should remove them before moving into a
  21. production environment.
  22. Remove anonymous users? [Y/n] y
  23. ... Success!
  24. Normally, root should only be allowed to connect from 'localhost'.  This
  25. ensures that someone cannot guess at the root password from the network.
  26. Disallow root login remotely? [Y/n] y
  27. ... Success!
  28. By default, MariaDB comes with a database named 'test' that anyone can
  29. access.  This is also intended only for testing, and should be removed
  30. before moving into a production environment.
  31. Remove test database and access to it? [Y/n] y
  32. - Dropping test database...
  33. ... Success!
  34. - Removing privileges on test database...
  35. ... Success!
  36. Reloading the privilege tables will ensure that all changes made so far
  37. will take effect immediately.
  38. Reload privilege tables now? [Y/n] y
  39. ... Success!
  40. Cleaning up...
  41. All done!  If you've completed all of the above steps, your MariaDB
  42. installation should now be secure.
  43. Thanks for using MariaDB!
复制代码

第四、安装PHP-fpm 5.6

  1. yum --enablerepo=remi,remi-php56 install php-fpm php-common php-mysql php-opcache php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml -y
复制代码

启动和开机启动

  1. service php-fpm start
  2. chkconfig php-fpm on
复制代码

第五、配置Nginx

到这里我们已经安装完毕nginx, mariadb, 以及php-fpm,我们需要对Nginx进行配置

A - 配置/etc/nginx/nginx.conf文件

  1. user  nginx;
  2. worker_processes  1;
复制代码

worker_processes表示当前vps/服务器的CPU核心数,我们可以通过grep ^processor /proc/cpuinfo | wc -l检测和修改。

B - 检查启动sendfile, tcp_nopush, gzip,以及添加INDEX.PHP文件

  1. sendfile        on;
  2. tcp_nopush     on;
  3. #keepalive_timeout  0;
  4. keepalive_timeout  65;
  5. gzip  on;
  6. index   index.php index.html index.htm;
复制代码

第六、添加站点和设置文件

  1. vi /etc/nginx/conf.d/laozuo_org.conf
复制代码

添加站点的时候,我们最好以域名来定,这样好检查和记忆。

  1. server {
  2. listen your_public_ip_address:80;
  3. server_name  www.laozuo.org;
  4. root /var/www/www.laozuo.org;
  5. index index.php index.html index.htm;
  6. charset utf-8;
  7. location / {
  8. }
  9. location = /robots.txt { allow all; access_log off; log_not_found off; }
  10. location = /favicon.ico { allow all; access_log off; log_not_found off; }
  11. error_page 401 /401.html;
  12. error_page 403 /403.html;
  13. error_page 404 /404.html;
  14. error_page 500 502 503 504 /50x.html;
  15. location ~ \.php$ {
  16. root           /var/www/www.laozuo.org;
  17. fastcgi_pass   127.0.0.1:9000;
  18. fastcgi_index  index.php;
  19. fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  20. fastcgi_intercept_errors on;
  21. fastcgi_buffer_size 4K;
  22. fastcgi_buffers 128 4k;
  23. fastcgi_connect_timeout 50;
  24. fastcgi_send_timeout 40;
  25. fastcgi_read_timeout 40;
  26. try_files $uri =404;
  27. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  28. include        fastcgi_params;
  29. }
  30. # deny access to .htaccess files, if Apache's document root
  31. # concurs with nginx's one
  32. #
  33. # location ~ /\.ht {
  34. #     deny  all;
  35. # }
  36. }
复制代码

输入对应的配置文件。

如果没有/var/www/www.laozuo.org文件夹,我们需要给予设置添加和配置权限。

  1. mkdir /var/www/www.laozuo.org
  2. chmod 777 /var/www/www.laozuo.org
复制代码

最后,我们启动Nginx

  1. systemctl restart nginx
复制代码

如果无法启动,可以用"systemctl status nginx.service"检查到底是哪里的问题然后相应修改。

总结,这样我们可以在已经创建的文件夹中上传程序。如果需要有MYSQL等数据库的,我们单独再安装,




道勤主机提供365天*24小时全年全天无休、实时在线、零等待的售后技术支持。竭力为您免费处理您在使用道勤主机过程中所遇到的一切问题! 如果您是道勤主机用户,那么您可以通过QQ【792472177】、售后QQ【59133755】、旺旺【诠释意念】、微信:q792472177免费电话、后台提交工单这些方式联系道勤主机客服! 如果您不是我们的客户也没问题,点击页面最右边的企业QQ在线咨询图标联系我们并购买后,我们为您免费进行无缝搬家服务,让您享受网站零访问延迟的迁移到道勤主机的服务!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

道勤网- 推荐内容!上一条 /2 下一条

!jz_fbzt! !jz_sgzt! !jz_xgzt! 快速回复 !jz_fhlb! !jz_lxwm! !jz_gfqqq!

关于我们|手机版|小黑屋|地图|【道勤网】-www.daoqin.net 软件视频自学教程|免费教程|自学电脑|3D教程|平面教程|影视动画教程|办公教程|机械设计教程|网站设计教程【道勤网】 ( 皖ICP备15000319号-1 )

GMT+8, 2024-11-29 13:44

Powered by DaoQin! X3.4 © 2016-2063 Dao Qin & 道勤科技

快速回复 返回顶部 返回列表