Domain, hosting, vps giá rẻ
Kết quả 1 đến 6 của 6

Chủ đề: [Linux CentOS] How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6

  1. #1
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762

    [Linux CentOS] How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6

    How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6


    About Lemp
    LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.

    Step One—Install the Required Repositories
    We will be installing all of the required software with Yum. However, because neither nginx nor php-fpm are available straight from CentOS, we need to download two extra repositories to our virtual private server first.
    Mã:
    sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
    sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    yum install wget zip unzip perl-libwww-perl -y
    yum update -y
    Step Two—Install MySQL
    The next step is to begin installing the server software on the virtual private server, starting with MySQL and dependancies.
    Mã:
    sudo yum install mysql mysql-server -y
    Once the download is complete, restart MySQL:
    Mã:
    sudo /etc/init.d/mysqld restart
    You can do some configuration of MySQL with this command:
    Mã:
    sudo /usr/bin/mysql_secure_installation
    The prompt will ask you for your current root password.

    Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
    Mã:
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

    CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.

    It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the changes.
    Mã:
    By default, a MySQL installation has an anonymous user, allowing anyone
    to log into MySQL 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.
    
    Setting the root password or using the unix_socket ensures that nobody
    can log into the MariaDB root user without the proper authorisation.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Switch to unix_socket authentication [Y/n] n
     ... skipping.
    
    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, MySQL 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 MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    
    
    SET GLOBAL max_connections=50000;
    show global variables like 'max_connections';
    SET GLOBAL max_allowed_packet=268435456;
    show global variables like 'max_allowed_packet';
    show global variables like 'thread_pool_max_threads';
    show status where `variable_name` = 'Max_used_connections';
    show status where `variable_name` = 'Threads_connected';
    Step Three—Install nginx
    As with MySQL, we will install nginx on our virtual private server using yum:
    Mã:
    sudo yum install nginx -y
    nginx does not start on its own. To get nginx running, type:
    Mã:
    sudo /etc/init.d/nginx start
    You can confirm that nginx has installed on your virtual private server by directing your browser to your IP address.

    You can run the following command to reveal your server’s IP address.
    Mã:
    ifconfig eth0 | grep inet | awk '{ print $2 }'
    Step Four—Install PHP
    The php-fpm package is located within the REMI repository, which, at this point, is disabled. The first thing we need to do is enable the REMI repository and install php and php-fpm:
    Mã:
    sudo yum --enablerepo=remi install memcached php-pecl-memcache php-pecl-memcached php-fpm php-mysql php-mbstring gd gd-devel php-gd php-common php-pecl-apcu php-cli php-pear php-pdo php-pgsql php-pecl-mongo php-pecl-sqlite php-mcrypt php-xml -y
    Step Five—Configure php
    We need to make one small change in the php configuration. Open up php.ini:
    Mã:
     sudo vi /etc/php.ini
    Find the line, ;cgi.fix_pathinfo=1, and change the 1 to 0.
    ;session.save_path = "/tmp", and change the "/tmp" to "/var/lib/php/session".
    memory_limit = 128M, and change to memory_limit = 512M
    Mã:
    cgi.fix_pathinfo=0
    session.save_path = "/var/lib/php/session"
    memory_limit = 512M
    short_open_tag = On
    max_execution_time = 60
    max_input_time = 60
    post_max_size = 9999M
    upload_max_filesize = 9999M
    If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path—a much safer alternative. Save and Exit.

    - Open file /etc/my.cnf, add value max_allowed_packet=256M under line [mysqld] :
    Mã:
    [mysqld]
    
    max_allowed_packet=256M
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    - Open file /etc/my.cnf.d/server.cnf, add value max_connections = 50000 under line [mysqld] :
    Mã:
    ...
    # this is only for the mysqld standalone daemon
    [mysqld]
    max_connections = 50000
    ...
    Step Six—Configure nginx
    Open up the default nginx config file:
    Mã:
    sudo vi /etc/nginx/nginx.conf
    Raise the number of worker processes to 4 then save and exit that file.

    Now we should configure the nginx virtual hosts.

    In order to make the default nginx file more concise, the virtual host details are in a different location.
    Mã:
    sudo vi /etc/nginx/conf.d/default.conf
    The configuration should include the changes below (the details of the changes are under the config information):
    Mã:
    #
    # The default server
    #
    server {
        listen       80;
        server_name example.com;
    
       
        location / {
            root   /usr/share/nginx/html;
            index index.php  index.html index.htm;
        }
    
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    Here are the details of the changes:
    - Add index.php within the index line.
    - Change the server_name to your domain name or IP address (replace the example.com in the configuration)
    - Change the root to /usr/share/nginx/html;
    - Uncomment the section beginning with "location ~ \.php$ {",
    - Change the root to access the actual document root, /usr/share/nginx/html;
    - Change the fastcgi_param line to help the PHP interpreter find the PHP script that we stored in the document root home.

    Save and Exit

    Open up the php-fpm configuration:
    Mã:
    sudo vi /etc/php-fpm.d/www.conf
    Replace the apache in the user and group with nginx:
    Mã:
    [...]
    ; 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 = nginx
    ; RPM: Keep a group allowed to write in log dir.
    group = nginx
    [...]
    Finish by restarting php-fpm.
    Mã:
    sudo service php-fpm restart
    Step Seven—RESULTS: Create a php info page
    Although LEMP is installed, we can still take a look and see the components online by creating a quick php info page

    To set this up, first create a new file:
    Mã:
    sudo vi /usr/share/nginx/html/info.php
    Add in the following line:
    Mã:
    <?php
    phpinfo();
    ?>
    Then Save and Exit.

    Restart nginx so that all of the changes take effect:
    Mã:
    sudo service nginx restart
    Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php

    It should look similar to this.

    Step Eight—Set Up Autostart
    You are almost done. The last step is to set all of the newly installed programs to automatically begin when the VPS boots.
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mysql on
    chkconfig nginx on
    chkconfig php-fpm on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable nginx
    systemctl enable php-fpm
    systemctl enable crond
    systemctl enable ntpd
    chown -R nginx:nginx /usr/share/nginx
    chown -R nginx:nginx /var/www/html
    chown -R nginx:nginx /home
    chown -R nginx:nginx /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    service mysql restart
    service nginx restart
    service php-fpm restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-nginx.log
    rm -rf php56-ovh.sh
    history -cw
    cd
    View more: https://www.digitalocean.com/communi...ck-on-centos-6
    Lần sửa cuối bởi nghiatichxanh1992, ngày 01/01/2021 lúc 19:48.
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

  2. #2
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762
    FOR APACHE CENTOS 6:
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mysqld on
    chkconfig httpd on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable httpd
    systemctl enable crond
    systemctl enable ntpd
    chown -R apache:apache /usr/share/nginx
    chown -R apache:apache /var/www/html
    chown -R apache:apache /home
    chown -R apache:apache /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
    /etc/init.d/iptables save
    /etc/init.d/iptables stop
    chkconfig iptables off
    service httpd restart
    service mysqld restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-apacheos6.log
    rm -rf apacheos6.sh apacheos6php7.sh
    history -cw
    reboot
    cd
    Lần sửa cuối bởi nghiatichxanh1992, ngày 13/02/2021 lúc 23:21.
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

  3. #3
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762
    FOR APACHE CENTOS 7:
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mariadb on
    chkconfig httpd on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable httpd
    systemctl enable crond
    systemctl enable ntpd
    chown -R apache:apache /usr/share/nginx
    chown -R apache:apache /var/www/html
    chown -R apache:apache /home
    chown -R apache:apache /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    sudo systemctl mask --now firewalld
    service httpd restart
    service mariadb restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-apacheos7.log
    rm -rf apacheos7.sh apacheos7php7.sh
    history -cw
    reboot
    cd
    Lần sửa cuối bởi nghiatichxanh1992, ngày 13/02/2021 lúc 23:21.
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

  4. #4
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762
    FOR LAMP CENTOS 8:
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mariadb on
    chkconfig httpd on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable httpd
    systemctl enable crond
    systemctl enable ntpd
    chown -R apache:apache /usr/share/nginx
    chown -R apache:apache /var/www/html
    chown -R apache:apache /home
    chown -R apache:apache /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    sudo systemctl mask --now firewalld
    service httpd restart
    service mariadb restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-apacheos8.log
    rm -rf apacheos8.sh apacheos8php7.sh
    history -cw
    reboot
    cd
    Lần sửa cuối bởi nghiatichxanh1992, ngày 01/01/2021 lúc 19:40.
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

  5. #5
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762
    FOR NGINX CENTOS 7:
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mariadb on
    chkconfig nginx on
    chkconfig php-fpm on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable nginx
    systemctl enable php-fpm
    systemctl enable crond
    systemctl enable ntpd
    chown -R nginx:nginx /var/www/html
    chown -R nginx:nginx /usr/share/nginx
    chown -R nginx:nginx /home
    chown -R nginx:nginx /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    sudo systemctl mask --now firewalld
    service nginx restart
    service php-fpm restart
    service mariadb restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-nginxcentos7.log
    rm -rf nginxcentos7.sh
    history -cw
    reboot
    cd
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

  6. #6
    nghiatichxanh1992's Avatar
    Bài viết
    5,037
    Cấp độ
    Bang hội
    Tiếu Ngạo
    Tu luyện
    Độ kiếp Hư Thần
    Giới tính
    Con trai
    Join Date
    Jun 2012
    Đến từ
    Hà Giang
    Tuổi
    31
    Danh vọng
    10
    Điện thoại
    0367790762
    FOR NGINX CENTOS 8:
    Mã:
    cd
    echo 0 > /selinux/enforce
    setenforce 0
    chkconfig mariadb on
    chkconfig nginx on
    chkconfig php-fpm on
    chkconfig crond on
    chkconfig ntpd on
    systemctl enable mariadb
    systemctl enable nginx
    systemctl enable php-fpm
    systemctl enable crond
    systemctl enable ntpd
    chown -R nginx:nginx /var/www/html
    chown -R nginx:nginx /usr/share/nginx
    chown -R nginx:nginx /home
    chown -R nginx:nginx /var/lib/php
    chmod 0777 -R /var/lib/php/session
    chmod 0777 -R /var/lib/php/wsdlcache
    ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    sudo systemctl mask --now firewalld
    service nginx restart
    service php-fpm restart
    service mariadb restart
    service crond restart
    service ntpd restart
    cd /root
    rm -rf install-nginxcentos8.log
    rm -rf nginxcentos8.sh
    history -cw
    reboot
    cd
    Diễn đàn chia sẻ kiến thức điện thoại: http://chiase123.com
    Click vào Hiện ra để xem chữ ký của mình

Thông tin về chủ đề này

Users Browsing this Thread

Có 1 người đang xem chủ đề. (0 thành viên và 1 khách)

Các Chủ đề tương tự

  1. [Linux Centos 7] Cài đặt Nginx, MySQL, PHP (LEMP)
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 0
    Bài viết cuối: 15/09/2014, 3:27
  2. [Linux] Hướng dẫn cài đặt Nginx - Php-fpm - MariaDB - APC opcode cache cho vps
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 1
    Bài viết cuối: 19/06/2014, 8:20
  3. [Linux] HZTUT Centos - Cài Remote Destop VPS Linux Centos với 1 lệnh duy nhất
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 0
    Bài viết cuối: 28/05/2014, 0:19
  4. [VPS Linux] Hướng dẫn cài đặt Apache, MySQL, PHP để chạy 1 trang web
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 0
    Bài viết cuối: 04/02/2014, 23:48
  5. hỏi về cấu hình VPS linux centos
    Bởi kemcoi trong diễn đàn VPS - Server
    Trả lời: 0
    Bài viết cuối: 01/10/2013, 21:41
  6. [Linux Centos] Tối ưu server : Anti DDos cho Linux Webserver
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 3
    Bài viết cuối: 17/02/2013, 11:23
  7. [VPS linux] Cài đặt Nginx trên virtualmin
    Bởi nghiatichxanh1992 trong diễn đàn VPS - Server
    Trả lời: 0
    Bài viết cuối: 30/01/2013, 21:04
  8. [VPS Linux] Hướng dẫn cài cPanel 11 & WHM trên VPS Linux
    Bởi nghiatichxanh1992 trong diễn đàn PHP & MySQL
    Trả lời: 0
    Bài viết cuối: 01/10/2012, 20:13
  9. [VPS linux] Hướng dẫn cài cpanel Kloxo trên VPS linux Centos
    Bởi nghiatichxanh1992 trong diễn đàn PHP & MySQL
    Trả lời: 0
    Bài viết cuối: 01/10/2012, 20:07
  10. [VPS linux] Hướng dẫn cài cpanel Direct Admin trên VPS linux Centos
    Bởi nghiatichxanh1992 trong diễn đàn PHP & MySQL
    Trả lời: 0
    Bài viết cuối: 01/10/2012, 20:04

Tag của Chủ đề này

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •