在CentOS 6.5 上安装 Nginx、MySQL、PHP(PHP-FPM) (带Phalcon框架)运行环境
添加第三方软件源
PHP-FPM 在 CentOS 的官方程序库中不存在,所以我们首先得添加第三方扩展软件源。
rpm --import https://fedoraproject.org/static/0608B895.txt
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum install yum-priorities
然后编辑:vi /etc/yum.repos.d/epel.repo:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.aliyun.com/epel/6/$basearch
http://mirrors.aliyuncs.com/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
priority=10
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
接着:vi /etc/yum.repos.d/remi.repo:
[remi]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
安装 Nginx、MySQL以及PHP
#安装MySQL服务器
yum install mysql mysql-server
#安装Nginx
yum install nginx
#安装PHP及相关组件
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 php-pecl-apc
待所有安装结束后,使用以下命令启动服务:
#启动MySQL
chkconfig --levels 235 mysqld on
service mysqld start
#启动Nginx
chkconfig --levels 235 nginx on
service nginx start
#启动PHP-FPM
chkconfig --levels 235 php-fpm on
service php-fpm start
若 Nginx 启动失败,则有可能是因为 Apache httpd 服务占用了该接口,这时,要么我们修改 Nginx 的坚挺端口,要么修改Apache httpd的或者直接删除 Apache httpd。
apachectl stop
yum remove httpd
chkconfig --level 235 httpd off
配置Nginx、MySQL与PHP-FPM
运行 mysql_secure_installation 命令,提升 MySQL 服务器的安全性,要求您要输入数据库 root 帐户密码,若您是新安装,则直接回车即可,接着立马设置新密码。
配置 PHP
打开 PHP 配置文件:vi /etc/php.ini
设置 cgi.fix_pathinfo=0:
[...]
; 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.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]
设置 upload_max_filesize 最大文件上传尺寸为 upload_max_filesize 为 16MB:
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 16M
设置 post_max_size 为 32MB:
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 32M
打开:vi /etc/php-fpm.d/www.conf :
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock;
以及:
listen.owner = www
listen.group = www
listen.mode = 0660
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = www
; RPM: Keep a group allowed to write in log dir.
group = www