开发环境

(重定向自php/install

目标

在centos 6.6 上使用yum搭建一个简单的php的开发环境。简单调试代码可以使用 https://code.php.wiki

配置yum repos

添加 epelremi源, 并且重建缓存。

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum clean all
yum makecache

配置文件位置:/etc/yum.repos.d/

安装基础工具

yum install -y supervisor unzip tar git telnet curl

安装SSH

安装并启动ssh

yum install -y openssh-server openssh-clients
/etc/init.d/sshd restart

可以使用 passwd 更改密码

如果需要使用key登陆,参考 ssh-keygen

主要配置文件: /etc/ssh/sshd_config

安装Nginx

yum install -y nginx
/etc/init.d/nginx restart

配置文件路径: /etc/nginx/nginx.conf

参考配置文件:

# /etc/nginx/conf.d/test.conf
server {
        listen 80;
        server_name test.com www.test.com;
        root /www/test.com/public/api/;
        index index.php;
 
        access_log  /var/log/nginx/$host.access.log;
        error_log   /var/log/nginx/$host.error.log;
 
        error_page 404 403 /40x.html;
        error_page 500 501 502 503 504 /50x.html;
 
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php/$1 last;
        }
 
        location / {
            index index.html index.php;
        }
 
        location ~ .+\.php {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        }
}
 

安装PHP

yum install -y php-cli php-common php-fpm php-devel php-pdo php-mysql
yum install -y php-pecl-memcache php-pecl-memcached php-redis php-gd

扩展.ini 目录: /etc/php.d/

配置文件: /etc/php.ini

fpm配置文件: /etc/php-fpm.conf

参考配置文件:/etc/php/pool.d/www.conf

[www]
user = nginx
group = nginx
listen = 9200
pm = ondemand
pm.max_children = 512
pm.process_idle_timeout = 10s
pm.max_requests = 1000
pm.status_path = /status
ping.path = /ping
ping.response = pong
rlimit_files = 65535
rlimit_core = unlimited
request_slowlog_timeout = 3s
request_terminate_timeout = 60
slowlog = /www/log/php_slow.log
;access.log = /www/log/php_access.log
catch_workers_output = yes
security.limit_extensions = .php
php_flag[display_errors] = off
php_admin_value[error_log] = /www/log/php-www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 128M

安装MySQL

yum install -y mysql-server
/etc/init.d/mysqld start

配置文件: /etc/my.cnf

安装Redis

yum install -y redis
/etc/init.d/redis start

配置文件: /etc/redis.conf

安装 Memcache

yum install -y memcached
/etc/init.d/memcached start

参见

  1. http://tecadmin.net/top-5-yum-repositories-for-centos-rhel-systems/
  2. http://lamp.baidu.com/content/slides/how-to-optimize-php-program.pdf
  3. http://lamp.baidu.com/slides/
  4. 在线ide:https://www.tutorialspoint.com/unix_terminal_online.php