在centos 6.4上安装Nginx宽php5和mysql支持

nginx (发音为engine-x)是一个免费的, 开源, 高性能 HTTP服务器反向代理,以及一个 IMAP/POP3 代理服务器. Igor Sysoev 于 2002 年开始开发 Nginx,并于 2004 年首次公开发布。Nginx 现在在所有域中托管近 12.18% (22.2M) 的活动站点。 Nginx 以其高性能、稳定性、丰富的功能集、简单的配置和低资源消耗而著称。

在本教程中,我使用主机名 srv1.lintut.com 和 IP 地址 10.0.0.80。 这些设置可能因您而异,因此您必须在适当的情况下替换它们。
首先启用EPEL和remi存储库。

安装 yum 优先级

# yum install yum-priorities

编辑 /etc/yum.repos.d/epel.repo 并将行 priority=10 添加到 [epel] 部分:

[epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=https://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [...]

编辑 /etc/yum.repos.d/remi.repo 并将启用更改为 1 并添加优先级 = 10:

nano /etc/yum.repos.d/remi.repo
[remi] name=Les RPM de remi pour Enterprise Linux $releasever - $basearch #baseurl=https://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/ mirrorlist=https://rpms.famillecollet.com/enterprise/$releasever/remi/mirror enabled=1 priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi failovermethod=priority  [remi-test] name=Les RPM de remi en test pour Enterprise Linux $releasever - $basearch #baseurl=https://rpms.famillecollet.com/enterprise/$releasever/test/$basearch/ mirrorlist=https://rpms.famillecollet.com/enterprise/$releasever/test/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

安装 Nginx

Nginx 可作为 CentOS 6.4(来自 EPEL)的软件包使用,我们可以按如下方式安装:

yum install nginx

启动 nginx 并使其在每次重新启动时自动启动。

/etc/init.d/nginx start chkconfig nginx on

在浏览器中输入 Web 服务器的 IP 地址或主机名,您应该会看到 nginx 欢迎页面:

安装MySql服务器

yum install mysql mysql-server -y

设置 MySQL 根密码

输入下一个命令并按照说明进行操作:

mysql_secure_installation

安装 PHP5

我们可以通过 PHP-FPM 使 PHP5 在 nginx 中工作(PHP-FPM(FastCGI 进程管理器)是另一种 PHP FastCGI 实现,具有一些附加功能,适用于任何规模的站点,尤其是繁忙的站点)。 我们可以将 php-fpm 与 php-cli 和一些 PHP5 模块(如 php-mysql)一起安装,如果您想从 PHP 脚本使用 MySQL,则需要这些模块,如下所示:

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

APC 是一个免费且开放的 PHP 操作码缓存器,用于缓存和优化 PHP 中间代码。 它类似于其他 PHP 操作码缓存器,例如 eAccelerator 和 Xcache。 强烈建议安装其中之一来加速您的 PHP 页面。
APC可以如下安装:

yum install php-pecl-apc

然后打开 /etc/php.ini 并设置 cgi.fix_pathinfo=0:

nano /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. ; https://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo cgi.fix_pathinfo=0 [...]

启动 php-fpm 服务并配置为在系统启动时自动启动:

 /etc/init.d/php-fpm start chkconfig php-fpm on

重启 ngnix 服务器

/etc/init.d/nginx reload

测试 PHP

创建测试 php 页面:

nano /usr/share/nginx/html/info.php

并粘贴以下代码:


现在我们在浏览器中调用该文件(例如 https://10.0.0.80/info.php)

参考:unixmen.com 和 howtoforge.com