- 在 Centos 7 上架設 Nginx Web Server!
-
編寫最新的 Nginx 套件位置:
#vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
-
利用 yum 安裝
#yum -y install nginx
-
啟動防火牆:
#firewall-cmd --permanent --zone=public --add-service=http #firewall-cmd --permanent --zone=public --add-service=https #firewall-cmd --reload
-
啟動 Nginx:
#systemctl enable nginx.service #systemctl start nginx
讓 Nginx 加入 php 模組:
-
利用 yum 安裝
#yum -y install php-fpm
-
編寫 php-fpm 預設檔:
#vim /etc/php-fpm.d/www.conf user = nginx group = nginx
-
啟動 php-ftm 功能:
#systemctl enable php-fpm.service #systemctl start php-fpm
-
編寫 Nginx 預設檔:
#vim /etc/nginx/conf.d/default.conf (修改下列項目:) location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; }
-
重新啟動 Nginx:
#systemctl restart nginx
-
改成 Socket 的使用方式:
#vim /etc/sysconfig/memcached OPTIONS="-s /tmp/memcached.sock -a 666" #MEMCACHED_ARGS="-s /tmp/memcached.sock -a 666"
-
檢查一下成果:
#echo stats | nc -U /tmp/memcached.sock
-
修改 memcached.ini 設定檔內容:
#/etc/php/conf.d/memcached.ini extension=memcached.so session.save_handler="memcached" session.save_path="/tmp/memcached.sock"
-
編修 Nginx 預設檔:
#vim /etc/nginx/conf.d/default.conf server { : (加入以下內容:) location ^~ /cache/ { set $memcached_key $request_uri; #memcached_pass 127.0.0.1:11211; memcached_pass unix:/tmp/memcached.sock; } :
-
重新啟動 Nginx:
#systemctl restart nginx
參考文獻:
- https://www.howtoforge.com/tutorial/install-nginx-with-php-and-mysql-lemp-stack-on-centos/
- http://blog.itist.tw/2016/01/installing-lemp-stack-with-centos-7-nginx-mariadb-php-7.html
- http://www.phpini.com/linux/rhel-centos-7-install-nginx-mysql-php-lemp
- http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=1
- https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-centos-7