[腾讯云]简单在腾讯云 CenTOS7.0 安装Nginx,Mysql(MariaDB),Memcache,解析PHP!

1、安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。

  yum install epel-release

2、安装Nginx

  a) yum install nginx
  b) systemctl start nginx #启动nginx systemctl stop nginx
  c) systemctl enable nginx #设置开机启动

  /usr/share/nginx/html. 解析页面目录

  /etc/nginx/nginx.conf nginx配置文件

  ###现在已经可以解析.html文件啦!还想解析PHP文件需要安装PHP,然后修改nginx 配置文件

3 进入nginx 配置目录,复制nginx配置文件nginx.conf ,以留备份,防止改错!

  修改配置文件如下!

  server {

     listen       80;       
        server_name  server_domain_name_or_IP;
      location / {
             root   /usr/share/nginx/html;
             index  index.php index.html index.htm;       
      }          
      error_page  404              /404.html;          
      # redirect server error pages to the static page /50x.html       
      error_page   500 502 503 504  /50x.html;       
      location = /50x.html {           
          root   /usr/share/nginx/html;       
      }      
      # 更改上方面location /  直接把下方替换上方的就可以,或者直接加载server里也行!
      location ~ .php$ {           
            root           /usr/share/nginx/html;           
           try_files $uri =404;           
            fastcgi_pass   127.0.0.1:9000;           
           fastcgi_index  index.php;           
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;           
            include        fastcgi_params;       
      }

   }

   改完配置文件记得重启nginx!

1、安装PHP  

  yum install -y php php-devel php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring   php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel

  老规矩:直接复制!

2、开启php-fpm

  a) systemctl start php-fpm #开启php-fpm
  b) systemctl enable php-fpm #开机自动启动

这样Nginx基本实现可以解析PHP!

下面安装MYSQL

1、安装MYSQL(MariaDB)

  安装LNMP方式,CentOS7下MYSQL已经被Mariadb替代,这个无所谓,完全兼容的!

  (MariaDB 是一个采用Aria存储引擎的MySQL分支版本,是由原来 MySQL 的作者Michael Widenius创办的公司所开发的免费开源的数据库服务器)

   ( LAMP架构盛极一时,这离不开MySQL的免费与易用,但是在Oracle收购了Sun之后,很多公司开始担忧MySQL的开源前景,而最近Oracle进一步闭源的举措更是让人难以安  心,众多互联网公司纷纷开始寻求MySQL的替代方案。)

  a) yum install mariadb-server mariadb

  b) systemctl start mariadb #启动mariadb

  c) systemctl enable mariadb #设置开机启动

2、设置MariaDB密码

  mysql_secure_installation

   #会要求输入原密码,直接点击回车就行,剩下的就是输入新密码以及确认密码

  #其他配置(了解一下就好)

  Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车

  Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,

  Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车

  Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

3、测试是否成功

  mysql -u用户名 -p密码

  进入就OK啦!

  show databases;

linux 安装memcache

1、查找Memcached

  yum search memcached

2、安装memcache和PHP相关扩展

  yum -y install –enablerepo=rpmforge memcached php-pecl-memcache

3、验证安装 

  memcached -h #应该会输出一些帮助信息

4、设置开机启动

  chkconfig memcached on

5、启动memcached

  service memcached start

  或者找到目录的启动/bin/systemctl start memcached.service

6、测试服务端是否安装成功

  php -m|grep memcache

  #查看端口号  

  lsof -i tcp:11211 #如果提示lsof not found,使用yum install lsof即可

7、接下来加载php memcache扩展
  找到php配置文件,一般使用yum默认安装在etc/目录下,如果没找到可以建立一个文件输出phpinfo搜索Configuration File可以查看到php.ini文件位置

  开启memcache扩展

  extension=/usr/lib64/php/modules/memcache.so,

  重启php服务

  service php-fpm restart

8、检测php扩展是否安装ok

  在输出phpinfo页面搜索memache,可查看到memcache扩展

9、新建mem.php,输入如下代码:

  #去页面加载文件夹建一个新文件

  <?php
  $mem = new Memcache;
  $mem->connect("127.0.0.1", 11211);
  $mem->set('key', 'This is a test, Hello World!--Pc.Lee', 0, 0);
  $val = $mem->get('key');
  echo $val;
  ?>

10、在地址栏运行文件

  This is a test, Hello World!--Pc.Lee #页面显示这个输出内容就OK啦!

原文地址:https://www.cnblogs.com/lipcblog/p/6476258.html