Dưới đây là memo các bước để thiết lập môi trường phát triển PHP trên Centos6.8. Danh sách middleware sẽ cài đặt: 1. Nginx 2. PostgreSQL 3. PHP5.6 (+php-fpm) Quá trình cài đặt dưới đây được thực hiện trên môi trường giả lập bằng vagrant, sử dụng box `bento/centos6.8`. ## Thực hiện: ~~~ $ sudo su - ~~~ **■ Cài đặt Nginx** ~~~ $ yum install http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm $ yum install nginx ~~~ **■ Cài đặt PHP** ~~~ $ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm $ rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm $ yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-devel.x86_64 php56w-fpm.x86_64 php56w-gd.x86_64 php56w-intl.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64 php56w-pgsql.x86_64 php56w-soap.x86_64 php56w-tidy.x86_64 php56w-xml.x86_64 php56w-xmlrpc.x86_64 php56w-process.x86_64 ~~~ **■ Cài đặt PostgreSQL** ~~~ $ cd ~ $ wget https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm $ rpm -ivh pgdg-centos95-9.5-3.noarch.rpm $ yum install postgresql95.x86_64 postgresql95-devel.x86_64 postgresql95-contrib.x86_64 postgresql95-libs.x86_64 postgresql95-server.x86_64 ~~~ **■ Tùy chỉnh Nginx** ~~~ $ vim /etc/nginx/nginx.conf # required when use vagrant # expires -1; sendfile off; ~~~ ~~~ $ vim /etc/nginx/conf.d/php-fpm.conf upstream php-fpm { server 127.0.0.1:9000; } ~~~ ~~~ $ vim /etc/nginx/conf.d/you-site.conf server { listen 80; server_name your-site.com; root /var/www/html/; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; client_max_body_size 20M; fastcgi_read_timeout 120; location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass php-fpm; } location ~ \.php/ { include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass php-fpm; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; } # redirect server error pages to the static page /40x.html # error_page 403 404 /404.html; location = /40x.html { root /usr/share//nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /(\.ht|\.user.ini|\.git|\.hg|\.bzr|\.svn) { deny all; } } ~~~ **■ Tùy chỉnh PostgreSQL** ~~~ $ service postgresql-9.5 initdb ~~~ ~~~ $ vim /var/lib/pgsql/9.5/data/postgresql.conf listen_addresses = '*' ~~~ ~~~ $ vim /var/lib/pgsql/9.5/data/pg_hba.conf local all all trust host all all all md5 host all all ::1/128 ident ~~~ ~~~ $ sudo service postgresql-9.5 start $ su - postgres $ psql CREATE USER username WITH PASSWORD 'password' CREATEDB CREATEROLE SUPERUSER; CREATE DATABASE "database_name" OWNER username LC_COLLATE 'ja_JP.utf8' TEMPLATE template0; ~~~