• CentOS7安裝配置LEMP(Nginx/PHP-FPM 5.6/MySQL 5.5)
  • 通常大型的網站建站環境都會采用Nginx系統環境架構,相對而言比Apache承受承載的線程和壓力更大,不過對于一般的博客、網站來說,Apache環境也足夠使用。
    在這里整理一篇基于最新的CentOS7系統,搭建和應用Nginx/PHP-FPM 5.6/MySQL 5.5適用的網站環境,如果你也喜歡折騰,可以嘗試下面的內容,文章是從海外翻譯過來的,且進行過測試是完整的。
    第一、安裝EPEL和REMI庫文件
    rpm -Uvh //dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
    第二、安裝Nginx
    yum install nginx -y
    啟動和設置開機啟動
    systemctl start nginx
    systemctl enable nginx
    設置防火墻開啟80端口
    firewall-cmd --zone=public --add-port=80/tcp --permanent$ sudo firewall-cmd --reload
    這里我們已經安裝完畢NGINX,我們可以打開IP地址瀏覽器中,可以看到成功的NGINX安裝界面提示。
    第三、安裝MariaDB 5.5
    yum --enablerepo=remi,remi-php56 install mariadb-server mariadb -y
    啟動和設置開機啟動
    systemctl start mariadb
    systemctl enable mariadb
    設置數據庫的安全
    /usr/bin/mysql_secure_installation
    執行上面腳本,根據提示我們需要設置一遍數據庫的安全,刪除匿名用戶等。
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
    SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user. If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Password updated successfully!
    Reloading privilege tables..
    ... Success!
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them. This is intended only for testing, and to make the installation
    go a bit smoother. You should remove them before moving into a
    production environment.
    Remove anonymous users? [Y/n] y
    ... Success!
    Normally, root should only be allowed to connect from 'localhost'. This
    ensures that someone cannot guess at the root password from the network.
    Disallow root login remotely? [Y/n] y
    ... Success!
    By default, MariaDB comes with a database named 'test' that anyone can
    access. This is also intended only for testing, and should be removed
    before moving into a production environment.
    Remove test database and access to it? [Y/n] y
    - Dropping test database...
    ... Success!
    - Removing privileges on test database...
    ... Success!
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    Reload privilege tables now? [Y/n] y
    ... Success!
    Cleaning up...
    All done! If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    Thanks for using MariaDB!
    第四、安裝PHP-fpm 5.6
    yum --enablerepo=remi,remi-php56 install php-fpm php-common php-mysql php-opcache php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml -y
    啟動和開機啟動
    service php-fpm start
    chkconfig php-fpm on
    第五、配置Nginx
    到這里我們已經安裝完畢nginx, mariadb, 以及php-fpm,我們需要對Nginx進行配置
    A - 配置/etc/nginx/nginx.conf文件
    user nginx;
    worker_processes 1;
    worker_processes表示當前VPS/服務器的CPU核心數,我們可以通過grep ^processor /proc/cpuinfo | wc -l檢測和修改。
    B - 檢查啟動sendfile, tcp_nopush, gzip,以及添加INDEX.PHP文件
    sendfile on;
    tcp_nopush on;
    #keepalive_timeout 0;
    keepalive_timeout 65;
    gzip on;
    index index.php index.html index.htm;
    第六、添加站點和設置文件
    vi /etc/nginx/conf.d/laozuo_org.conf
    添加站點的時候,我們最好以域名來定,這樣好檢查和記憶。
    server {
    listen your_public_ip_address:80;
    server_name www.myhack58.com;
    root /var/www/www.myhack58.com;
    index index.php index.html index.htm;
    charset utf-8;
    location / {
    }
    location = /robots.txt { allow all; access_log off; log_not_found off; }
    location = /favicon.ico { allow all; access_log off; log_not_found off; }
    error_page 401 /401.html;
    error_page 403 /403.html;
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location ~ \.php$ {
    root /var/www/www.myhack58.com;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_buffer_size 4K;
    fastcgi_buffers 128 4k;
    fastcgi_connect_timeout 50;
    fastcgi_send_timeout 40;
    fastcgi_read_timeout 40;
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    # location ~ /\.ht {
    # deny all;
    # }
    }
    輸入對應的配置文件。
    如果沒有/var/www/www.myhack58.com文件夾,我們需要給予設置添加和配置權限。
    mkdir /var/www/www.myhack58.com
    chmod 777 /var/www/www.myhack58.com
    最后,我們啟動Nginx
    systemctl restart nginx
    如果無法啟動,可以用"systemctl status nginx.service"檢查到底是哪里的問題然后相應修改。
    總結,這樣我們可以在已經創建的文件夾中上傳程序。
    如果需要有MYSQL等數據庫的,我們單獨再安裝


    上一篇Ubuntu v14 安裝及配置Redmine3.0

    下一篇Debian/Ubuntu系統中安裝和配置UFW防火墻

    2016 迅捷格言:事在人為 莫道萬般皆無奈;境由心造 后退一步萬事寬! 有事您說話,小捷很樂意幫助您!