关于 Nginx (发音 “engine x”)这是一款免费、开源、高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗。本教程演示如何在CentOS 6.5服务器(适用于 CentOS 7)安装Nginx与PHP(通过php-fpm)和MySQL(MariaDB)。
--------------------------------------分割线 -------------------------------------- Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL http://www./Linux/2014-05/102351.htm Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www./Linux/2013-06/86250.htm CentOS 6.4 下的LNMP 生产环境搭建及安装脚本 http://www./Linux/2013-11/92428.htm 生产环境实用之LNMP架构的编译安装+SSL加密实现 http://www./Linux/2013-05/85099.htm LNMP 全功能编译安装 for CentOS 6.3笔记 http://www./Linux/2013-05/83788.htm CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6) http://www./Linux/2013-04/82069.htm 在部署LNMP的时候遇到Nginx启动失败的2个问题 http://www./Linux/2013-03/81120.htm Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建) http://www./Linux/2012-10/72458.htm --------------------------------------分割线 -------------------------------------- 1 先说一下本文使用的主机名称: server1.example.com 和IP地址: 192.168.1.105。这些可能与你的计算机有所不同,注意进行修改。 2 使用外部仓库Nginx不是从官方CentOS库安装,我们从 nginx 项目安装库安装,修改源: vi /etc/yum.repos.d/nginx.repo 修改为: [nginx] name=nginx repo baseurl=http:///packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 3 安装 MySQL我们先安装MariaDB。一个免费的MySQL 分支。运行此命令: yum install mariadb mariadb-server net-tools 然后我们创建MySQL系统启动链接(所以MySQL的自动启动时,系统启动)启动MySQL服务器: systemctl enable mariadb.service 现在检查网络启用。运行 netstat -tap | grep mysql 它应该显示出这样的内容: [root@example ~]# netstat -tap | grep mysql
运行 mysql_secure_installation 为用户设置根口令(否则,任何人都可以访问你的MySQL数据库!): [root@example ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB In order to log into MariaDB to secure it, we’ll need the current Enter current password for root (enter for none): Setting the root password ensures that nobody can log into the MariaDB Set root password? [Y/n] <– 回车 By default, a MariaDB installation has an anonymous user, allowing anyone Remove anonymous users? [Y/n] <– 回车 Normally, root should only be allowed to connect from ‘localhost’. This Disallow root login remotely? [Y/n] <– 回车 By default, MariaDB comes with a database named ‘test’ that anyone can Remove test database and access to it? [Y/n] <– 回车 Reloading the privilege tables will ensure that all changes made so far Reload privilege tables now? [Y/n] <– 回车 Cleaning up… All done! If you’ve completed all of the above steps, your MariaDB Thanks for using MariaDB! [root@server1 ~]# mysql_secure_installation 4 安装 NginxNginx可以作为一个包从安装,运行: yum install nginx 然后我们创建的系统启动nginx的链接和启动它: systemctl enable nginx.service 有时,你会得到一个错误,如80端口已在使用中,错误消息会是这样的 [root@server1 ~]# service nginx start 这就意味着有时在运行Apache服务。停止服务,进一步启动服务nginx如下 systemctl stop httpd.service systemctl enable nginx.service 开放的HTTP和HTTPS防火墙中的端口 firewall-cmd –permanent –zone=public –add-service=http 输出的shell结果将看起来像这样: [root@example ~]# firewall-cmd –permanent –zone=public –add-service=http 在你的Web服务器的IP地址或主机名称输入到浏览器(如HTTP:/ /192.168.1.105),你应该看到nginx的欢迎页面。 5 安装 PHP5我们可以通过PHP-FPM使nginx的PHP5工作(PHP-FPM(FastCGI进程管理器)是一种替代PHP FastCGI执行一些额外的功能,支持任何规模大小,尤其是繁忙的站点很有用)。我们可以安装php-fpmtogether用PHP-CLI和一些PHP5的模块,如PHP,MySQL,你需要的,如果你想使用MySQL的PHP命令如下: yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap APC是一个自由和开放的PHP操作码来缓存和优化PHP的中间代码。它类似于其他PHP操作码cachers,如eAccelerator和XCache。强烈建议有这些安装,以加快您的PHP页面。 我会从PHP PECL库中安装的APC。 PECL要求CentOS开发工具beinstalled编译APC包。 yum install php-devel 安装 APC pecl install apc [root@example ~]# pecl install apc 然后打开 /etc/php.ini 并设置 cgi.fix_pathinfo=0: vi /etc/php.ini [...] ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; http://www./manual/en/ini.core.php#ini.cgi.fix-pathinfo cgi.fix_pathinfo=0 [...] 并添加行: [...] extension=apc.so 在 /etc/php.ini 文件后面。 除此之外,为了避免这样的时区的错误: [21-July-2014 10:07:08] PHP Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Berlin’ for ‘CEST/2.0/DST’ instead in /usr/share/nginx/html/info.php on line 2 … in /var/log/php-fpm/www-error.log 当你在浏览器中调用一个PHP脚本,你应该设置 date.timezone in /etc/php.ini: [...] [Date] ; Defines the default timezone used by the date functions ; http://www./manual/en/datetime.configuration.php#ini.date.timezone date.timezone = "Europe/Berlin" [...] 您可以通过运行正确的时区支持您的系统: cat /etc/sysconfig/clock [root@server1 nginx]# cat /etc/sysconfig/clock 接下来,创建系统启动链接的PHP-FPM并启动它: systemctl enable php-fpm.service PHP-FPM是一个守护进程(使用init脚本/etc/init.d/php-fpm) 运行在端口9000的FastCGI服务器。 更多详情见请继续阅读下一页的精彩内容: http://www./Linux/2014-09/106192p2.htm
|
|
来自: Dead n Gone > 《CentOS》