How to Install Linux, Nginx, MySQL, PHP (LEMP) stacks on CentOS 6

Source: Internet
Author: User
Tags fpm install php virtual private server

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, and the Linux part was taken care of. Here's how to install the rest.

Step One-install the Required repositories

We'll be installing all of the required software with Yum. However, because Nginx isn't available straight from CentOS, we'll need to install the Epel repository.

sudo yum install epel-release
Step Two-install MySQL

The next step is to begin installing the Server software on the virtual private server, starting with MySQL and Dependanci Es.

sudo yum install Mysql-server

Once The download is complete, restart MySQL:

Sudo/etc/init.d/mysqld restart

You can do some configuration of MySQL with this command:

Sudo/usr/bin/mysql_secure_installation

The prompt would ask you to your current root password.

Since you just installed MySQL, your most likely won ' t has one, so leave it blank by pressing ENTER.

Enter current password to root (enter for none): OK, successfully used password, moving on ...

Then the prompt would 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 the options. At the end, MySQL would reload and implement the changes.

By default, a MySQL installation had an anonymous user, allowing Anyoneto logs into MySQL without had to had a user ACC  Ount created Forthem.  This was intended only for testing, and the Installationgo a bit smoother. You should remove them before moving into aproduction environment. Remove anonymous users? [y/n] Y ... success!  Normally, Root should only is allowed to connect from ' localhost '. Thisensures that someone cannot guess at the root of password from the network. Disallow Root login remotely? [y/n] Y ... success!  By default, MySQL comes with a database named ' test ' that anyone canaccess. This was also intended only for testing, and should was removedbefore 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 would ensure that all changes made so farwill 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 mysqlinstallation should now is secure. Thanks for using mysql!
Step Three-install Nginx

As with MySQL, we'll install Nginx on our virtual private server using Yum:

sudo yum install Nginx

Nginx does not-start on its own. To get Nginx running, type:

Sudo/etc/init.d/nginx start

You can confirm this nginx have 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.

Ifconfig eth0 | grep inet | awk ' {print $} '
Step Four-install PHP

The PHP-FPM package was located within the REMI repository, which, at this point, is disabled. The first thing we need to does is enable the REMI repository and install PHP and PHP-FPM:

sudo yum install php-fpm php-mysql
Step five-configure PHP

We need to make one small change in the PHP configuration. Open up php.ini:

sudo vi/etc/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.

Cgi.fix_pathinfo=0

If This number is kept as a 1, the PHP interpreter would do it best to process the file, which is as near to the requested F Ile as possible. This is a possible security risk. If This number was set to 0, conversely, the interpreter would only process the exact file path-a much safer alternative. Save and Exit.

Step six-configure Nginx

Open up the default nginx config file:

sudo vi/etc/nginx/nginx.conf

Raise the number of the worker processes to 4 then save and exit the file.

Now we should configure the Nginx virtual hosts.

The default Nginx file more concise, the virtual host details is in a different location.

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):

# # The default server#server {    listen       ;    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   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/s hare/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 is 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, the We stored in the document root home.

Save and Exit

Open up the PHP-FPM configuration:

sudo vi/etc/php-fpm.d/www.conf

Replace the Apache in the user and group with Nginx:

[...]; 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 being able to access some dir as Httpduser = Nginx; Rpm:keep a group allowed to write in log Dir.group = nginx[...]

Finish by restarting PHP-FPM.

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 the this up, first create a new file:

sudo vi/usr/share/nginx/html/info.php

ADD in the following line:

<?phpphpinfo ();? >

Then Save and Exit.

Restart Nginx So, all of the changes take effect:

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.3 4.56.789/info.php

It should look similar.

Step Eight-set up Autostart

You is almost done. The last step was to set all of the newly installed programs to automatically begin when the VPS boots.

sudo chkconfig--levels 235 mysqld onsudo chkconfig--levels 235 nginx onsudo chkconfig--levels 235 php-fpm on

How to Install Linux, Nginx, MySQL, PHP (LEMP) stacks on CentOS 6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.