Close Menu
    Facebook X (Twitter) Instagram
    • Download Cisco Packet Tracer
    Facebook X (Twitter) Instagram Pinterest Vimeo
    IT Beginner
    • Home
    • Server
    • WordPress
    IT Beginner
    Home»CentOS»How to install LEMP web server with Nginx, PHP-FPM 5.5, MySQL 5.5 on Centos Linux
    CentOS

    How to install LEMP web server with Nginx, PHP-FPM 5.5, MySQL 5.5 on Centos Linux

    26/07/2017No Comments5 Mins Read

    I have shown you How to install LEMP server with Linux, Nginx, PHP-FPM, and MySQL on Centos with standard packages from Centos repository, which comes with older version of PHP 5.3.x and MySQL 5.1.x. Since there are many new great features from PHP 5.5.x and MySQL 5.5.x which I mentioned in How to install LAMP server with Apache 2.2, MySQL 5.5.37, PHP 5.5.11 on Centos Linux. Why not install newer version of PHP 5.5.x and MySQL 5.5.x on nginx, HP-FPM, MySQL or LEMP server stack.

    We are going to use EPEL (Extra Packages for Enterprise Linux) and REMI (Les RPM de Remi) repositories for this article, since EPEL repository already has nginx package so we don’t need to add nginx repository to our server.

    Installing EPEL and REMI Repository for Centos 32 bit

    # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
    # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    Installing EPEL and REMI Repository for Centos 64 bit
    # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    Installing EPEL and REMI Repository for Fedora 17 / 18 / 19 / 20
    # rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
    # rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
    Installing Nginx repository for Red Hat/CentOS/Fedora
    nginx package does not come as default package for Centos or RHEL (Red Hat Enterprise Linux), both REMI and EPEL have nginx packages but not the newest. To install nginx, you have to add nginx yum repository or directly install rpm package.
    Create a file named nginx.repo in /etc/yum.repos.d/ directory
    # nano /etc/yum.repos.d/nginx.repo

    with the content

    For Centos 6.x

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/6/$basearch/
    gpgcheck=0
    enabled=1
    For Centos 5.x
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/5/$basearch/
    gpgcheck=0
    enabled=1
    For RHEL 6.x (Red Hat Enterprise Linux)
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/rhel/6/$basearch/
    gpgcheck=0
    enabled=1
    For RHEL 5.x (Red Hat Enterprise Linux)
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/rhel/5/$basearch/
    gpgcheck=0
    enabled=1
    Install nginx web-server

    After adding EPEL and REMI repositories, we now can install nginx

    # yum install nginx

    To start nginx

    # service nginx start

    To start nginx automatically when the system boot/reboot

    # chkconfig nginx on

    Your nginx web server should be running by now, if you can’t access your nginx web server, you may have not allowed http or port 80 access to your server on iptables rules. To allow http access to your server

    # iptables -F
    # iptables -P OUTPUT ACCEPT
    # iptables -P INPUT ACCEPT
    # iptables -P FORWARD ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
    # iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    # iptables-save
    When you install nginx from EPEL repository, the default nginx placeholder web page will look different from the nginx from nginx repository.
    Nginx from EPEL repository
    Nginx from nginx repository
    Install MySQL 5.5.x server

    We are going to install MySQL database server from remi repository instead of Centos default repository.

    Centos 5.10 / Centos 6.5

    # yum --enablerepo=remi,remi-php55 install mysql-server

    Fedora 20 Heisenbug / 19 Schrödinger’s Cat

    # yum --enablerepo=remi install mysql-server

    Fedora 18 Spherical Cow / 17 Beefy Miracle

    # yum --enablerepo=remi,remi-test install mysql-server

    To start MySQL database server

    # service mysqld start

    To start MySQL server at Startup

    # chkconfig mysqld on
    Secure MySQL server

    You should always run mysql_secure_installation after install mysql since default mysql server configuration isn’t safe enough. You will be asked to type in your new MySQL root password, and say Y for yes for the rest of the options

    • Remove root’s remote access
    • Remove anonymous users
    • Disallow root login remotely
    • Reload privilege tables
    # mysql_secure_installation
    Install PHP or PHP-FPM

    We are going to install PHP, PHP-FPM/FastCGI, from remi-php55 repository to get the latest php5 packages. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features.

    # yum --enablerepo=remi,remi-php55 install php-fpm php-common php-mysql php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml

    To start PHP-FPM

    # /etc/init.d/php-fpm start

    or

    # service php-fpm start

    To run PHP-FPM automatically when the system boot/reboot

    # chkconfig php-fpm on

    Configure nginx to work with PHP

     # nano /etc/nginx/conf.d/default.conf

    Modify / append as follows:

      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;
    }
    

    Search for

    location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    add index.php to index line
    location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm index.php;
        }

    Save and close the file. Restart nginx:

     # service nginx restart
    To confirm nginx and PHP are working

    Default nginx html/php files will be stored in /usr/share/nginx/html . You can change nginx default document root directory in /etc/nginx/conf.d/default.conf if you wish to. By the way we are creating php test file to check if nginx and php are working

    # nano /usr/share/nginx/html/info.php

    With the content

    <?php phpinfo(); ?>

    Save and exit, fire up your website and go to info.php file by going http://yourdomain/info.php

    You should see PHP version 5.5.x, and at “server API” line you should see FPM/FastCGI
    ——————————
    Note:
    To start/restart/stop nginx web server

    # service nginx start
    # service nginx restart
    # service nginx stop
    To start/restart/stop MySQL server
    # service mysqld start
    # service mysqld restart
    # service mysqld stop
    To start/restart/stop PHP-FPM server
    # service php-fpm start
    # service php-fpm restart
    # service php-fpm stop

    REMI repository is not enabled by default, every time you want to install/update packages via remi repository you will have to include enablerepo=remi option in yum command.

    Centos 5.10 / Centos 6.5

    # yum --enablerepo=remi,remi-php55 update

    Fedora 20 Heisenbug / 19 Schrödinger’s Cat

    # yum --enablerepo=remi update

    Fedora 18 Spherical Cow / 17 Beefy Miracle

    # yum --enablerepo=remi,remi-test update

     

    nginx web server
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow to install LAMP server with Apache 2.2, MySQL 5.5.37, PHP 5.5.11 on Centos Linux
    Next Article How to setup a LAMP server Linux, Apache, MySQL, PHP on Debian 7 wheezy Linux

    Related Posts

    CentOS

    How to install vsftpd on centos 6

    03/08/2017
    CentOS

    How To Install WordPress with nginx on Centos 6

    02/08/2017
    Security

    How to secure Nginx web server

    02/08/2017
    Subscribe
    Notify of
    guest

    guest

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    0 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    Tags
    apache centos Centos 6 cuda Desktop Environment dual boot environment featured gnome GUI hostname hosts intel kernel kill lamp server lemp server life MariaDB netflix nginx nvidia password php-fpm phpmyadmin pids processes s.m.a.r.t Security session solid state drive ssd ssh ssh server tag 1 tag 2 Ubuntu upgrade varnish VirtualBox VNC Server web server window manager wordpress xfce
    Facebook X (Twitter) Instagram Pinterest

    Type above and press Enter to search. Press Esc to cancel.

    wpDiscuz