Details on cloud host LNMP environment Construction (CentOS 6.9 64-bit System)

1. Log in to the cloud host

After you purchase a cloud host, you will get the following cloud host information
  • 1. Public IP address (assume 123.124.124.125)
  • 2. Password for logging in to the cloud host (assume 123456)
Note:
  • 1. Here is public IP can network access to the outside via a browser (such as: http://123.124.124.125:80), here at the back of the port number may be increased in a cloud host console configuration, configuration rear can use. The default is port 80;
  • 2. Use SSH to access cloud hosts in terminal(MAC command line tool), for example:
SSH [email protected] -p 22 (22 is the default port for accessing the cloud host) or SSH [email protected] (You can also log in to the cloud host)Copy the code
  • Then enter the cloud host password (the assumed password is used here: 123456)

  • After entering the correct password, you successfully log in to the cloud host. The following welcome document is displayed (this document is based on the ESC of the Ali Cloud host, and the following welcome document is the ESC cloud host) :

  • So far, login to the cloud host is successful!

Ii. Start installing LNMP environment (Conscience Summary)

Install nginx server

  • Install nginx with yum:
yum install nginx -y
Copy the code
  • Modify/etc/nginx/conf. D/default. The conf file content, listening to remove the IPv6 address, specific as follows:
pwd(View current path)cd/etc/nginx/conf.d (go to the nginx configuration directory) > default.conf (clear the original default.conf file) vim default.conf (vim edit the default.conf file)Copy the code
  • Copy the following into default.conf
server {
    listen       80 default_server;
    # listen [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
Copy the code
  • To start nginx, execute:
nginx
Copy the code
  • Set this parameter to automatic startup upon startup
chkconfig nginx on
Copy the code
Note: New version (centos 7) refer to the following tutorials:
Blog.csdn.net/gshzh00/art…
  • To view the nginx version, run the following command:
nginx -v
Copy the code

  • Nginx installed successfully!

Install the mysql database

  • Install the database using yum
Yum install mysql-server-y (default version 5.1, not recommended)Copy the code
  • Mysql > install mysql
# Update yum source
yum update 
# add mysql5.6 yum
# centos6
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# centos7
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
Copy the code
  • After the installation is complete, start the database and run the following command:
service mysqld restart
Copy the code
  • To set the database account password (assume that the account is set to root and the password is set to 123), run the following command:
/usr/bin/mysqladmin -u root password '123'
Copy the code
  • To set automatic startup, run the following command:
chkconfig mysqld on
Copy the code
  • To check the mysql version, execute (note: -v must be capitalized) :
mysql -V
Copy the code

  • Mysql installation complete!

Install the PHP environment

  • To check whether the PHP environment exists, run:
PHP -v (view the current PHP version information) or RPM - qa | grep PHP (view the current PHP related software versions and other related information)Copy the code
  • If the machine is not empty, uninstall the boss PHP first
  • You can uninstall any software using the following code yum Remove
  • Delete the PHP source again, refer to: Xz Compression not available solution
yum remove php* php-common
Copy the code
  • If the machine is empty, there should be no result above, indicating that there is no PHP environment.
  • # yum yum yum yum yum yum yum yum yum yum yum yum yum yum yum yum yum
  • Check out a good article on installing advanced versions of PHP
  • Here I want to install the php5.6 version, so it is slightly different from the php7.1 version in the article. I have also installed a PHP extension called php-GD. Increase according to demand) :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm - yum list are enablerepo = webtatic | grep PHP (this instruction is very important, to do the corresponding version of PHP extension after installation, Yum search php56w yum install php56w php56w-fpm php56w-mbstring php56w-mysqlnd php56w-pecl-redis php56w-mcrypt php56w-opcache -y yum install php56w-gdCopy the code
  • (not recommended) If you do not want to change the source to install the higher version of PHP, you do not need to implement all of the above, just the following, but the PHP version will be 5.3.x, ultra low, some plug-ins are no longer supported, command:
Yum install PHP PHP -fpm PHP -y yum install PHP -fpm PHP -yCopy the code
  • Note: The following problems may occur during installation:
Error: Package: php71w-common-7.1.14-1. W6.x86_64 (webtatic) Requires: libgmp.so.3()(64bit)Copy the code

Libgmp.so.3: libgmp.so.3: libgmp.so.3: libgmp.so.3: libgmp.so. Download the libgmp.so.3 library locally. (2). Upload the file to the cloud host using Filezlla; (3). Run the: yum install libgmp.so.3 command to install the libgmp.so. (4). Then continue the above steps to install PHP, problem solved.

  • After that, start phP-Fpm (process management tool, must start)
service php-fpm start
Copy the code
  • View FPM ports:
netstat -nlpt | grep php-fpm
Copy the code
  • Self-start upon startup
chkconfig php-fpm on
Copy the code
  • View the PHP version and other related information
PHP -v (view the current PHP version information) or RPM - qa | grep PHP (view the current PHP related software versions and other related information)Copy the code

  • At this point, the PHP environment is installed! LNMP has been installed successfully! Here is a simple example of an installed LNMP environment with browser intuitive verification.

Simple example

  • For example, the current external IP address of the cloud host is 123.124.124.125, and the default is port 80
  • Then we will do a simple example, finally realizes the browser type http://123.124.124.125:8000/info.php, shows the current cloud host PHP version information for an example of the page.

1. Add it in the background of the security group of the cloud host (I am using Ali Cloud ECS this time)8000Port number. Different cloud hosts have different configuration modes. You can select and add ports by yourself.

Second, the configurationnginxThe configuration file

  • Create a new file called php.conf in /etc/nginx/conf.d and configure the nginx port as follows:
pwd
cd /etc/nginx/conf.d
ls
touch php.conf
vim php.conf
Copy the code
  • Copy the following configuration information to the php.conf file and configure nginx to point to the project path. Note: the following configuration of root content can only end up pointing to a folder, not a specific file.
server {
    listen 8000;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {
        # root /usr/share/php;
        root           /data/topay; 
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; include fastcgi_params; }}Copy the code
  • Restart nginx(use either of the following methods)
Service nginx restart or nginx restart-sReload (re-read the nginx configuration file)Copy the code
  • Create a new /data/topay directory, as follows:
pwd
cd~ /.. / mkdir datacd data
mkdir topay
cd topay
pwd
ls
Copy the code
  • Create a new info.php file in the /data/topay directory with the following instructions:
cd /data/topay
touch info.php
vim info.php
Copy the code
  • Copy the following into the info.php file
<? php phpinfo(); ? > (Print current PHP version information)Copy the code
  • At this point, the browser type http://123.124.124.125:8000/info.php will appear the following page.

  • The example is complete!
  • See the next article for a tutorial on how to install common software on a Linux host
  • You can also go to Tencent Cloud developer laboratory to contact, there is one hour of free training opportunities on the computer, Tencent cloud – developer laboratory.