电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1947 人浏览分享

阿里云里Centos 7 PHP7环境配置 LNMP

[复制链接]
1947 0
首先更新系统软件

  1. $ yum update
复制代码



安装nginx</str></str>

1.安装nginx源

  1. $ yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
复制代码


2.安装nginx


  1. $ yum install nginx
复制代码


3.启动nginx

  1. $ service nginx start
  2. Redirecting to /bin/systemctl start  nginx.service
复制代码


4.访问http://你的ip/

如果成功安装会出来nginx默认的欢迎界面

安装MySQL5.7.*
</str>

1.安装mysql源</str>

  1. $ yum localinstall  http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
复制代码


2.安装mysql

  1. $ yum install mysql-community-server
复制代码


确认一下mysql的版本,有时可能会提示mysql5.6

3.安装mysql的开发包,以后会有用

  1. $ yum install mysql-community-devel
复制代码


4.启动mysql

  1. $ service mysqld start
复制代码

  1. Redirecting to /bin/systemctl start  mysqld.service
复制代码



5.查看mysql启动状态

  1. $ service mysqld status
复制代码

出现pid

证明启动成功



6.获取mysql默认生成的密码

  1. $ grep 'temporary password' /var/log/mysqld.log
  2. 2015-12-05T05:41:09.104758Z 1 [Note] A temporary password is generated for root@localhost: %G1Rgns!dD!v</str>
复制代码


加粗的就是生成的密码

7.换成自己的密码

$
  1. mysql -uroot -p
  2. Enter password:
复制代码
输入上面的密码

成功输入后进入一下步,这里你估计会输入 好几次才进去



8. 更换密码

  1. mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
复制代码

这个密码一定要足够复杂,不然会不让你改,提示密码不合法;

9.退出mysql;

  1. mysql> quit;
复制代码


10.用新密码再登录,试一下新密码

$ mysql -uroot -p
Enter password:输入你的新密码

11.确认密码正确后,退出mysql;

  1. mysql> quit;
  2. 编译安装php7.0.0
  3. </str>

  4. </str>
复制代码

1.下载php7源码包</str>

  1. $ cd /root & wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
复制代码

2.解压源码包</str>

  1. $ tar -xvf php7.tar.gz
复制代码

3.</str>

  1. $ cd php-7.0.1
复制代码

4.安装php依赖包</str>

</str>

  1. $ yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
复制代码



5.编译配置,这一步我们会遇到很多configure error,我们一一解决,基本都是相关软件开发包没有安装导致</str>

</str>

$ ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx  \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir  \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
configure error:

1.configure: error: xml2-config not found. Please check your libxml2 installation.

解决:

  1. $ yum install libxml2 libxml2-devel
复制代码



2.configure: error: Cannot find OpenSSL's <evp.h>

解决:

  1. $ yum install openssl openssl-devel
复制代码



3.configure: error: Please reinstall the BZip2 distribution

解决:

  1. $ yum install bzip2 bzip2-devel
复制代码


4.configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/

解决:

  1. $ yum install libcurl libcurl-devel
复制代码



5.If configure fails try --with-webp-dir=<DIR> configure: error: jpeglib.h not found.



解决:

  1. $ yum install libjpeg libjpeg-devel
复制代码


6.If configure fails try --with-webp-dir=<DIR>

  1. checking for jpeg_read_header in -ljpeg... yes

  2. configure: error: png.h not found.
复制代码


解决:

  1. $ yum install libpng libpng-devel
复制代码



7.If configure fails try --with-webp-dir=<DIR>

  1. checking for jpeg_read_header in -ljpeg... yes

  2. checking for png_write_image in -lpng... yes

  3. If configure fails try --with-xpm-dir=<DIR>

  4. configure: error: freetype-config not found.
复制代码


解决:

  1. $ yum install freetype freetype-devel
复制代码


8.configure: error: Unable to locate gmp.h

解决:

  1. $ yum install gmp gmp-devel
复制代码


9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决:

  1. $ yum install libmcrypt libmcrypt-devel
复制代码


10.configure: error: Please reinstall readline - I cannot find readline.h

解决:

  1. $ yum install readline readline-devel
复制代码


11.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

解决:

  1. $ yum install libxslt libxslt-devel
复制代码



6.编译与安装

  1. $ make && make install
复制代码


这里要make好久,要耐心一下

7.添加 PHP 命令到环境变量

  1. $ vim /etc/profile
复制代码


在末尾加入

  1. PATH=$PATH:/usr/local/php/bin

  2. export PATH
复制代码


要使改动立即生效执行

  1. $ ./etc/profile
复制代码



  1. $ source /etc/profile
复制代码

查看环境变量

  1. $ echo $PATH
复制代码

查看php版本

  1. $ php -v
复制代码



8.配置php-fpm

  1. $ cp php.ini-production /etc/php.ini
  2. $ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

  3. $ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
  4. $ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  5. $ chmod +x /etc/init.d/php-fpm
复制代码


9.启动php-fpm

  1. $ /etc/init.d/php-fpm start
复制代码



配置nginx虚拟机,绑定域名</str>

1.
<
  1. /str>

  2. $ vim /etc/nginx/conf.d/php7.thinkcmf.com.conf
  3. 这里可以把php7.thinkcmf.com.conf改成自己的域名
复制代码


把下面的内容复制到php7.thinkcmf.com.conf里

  1. server{
  2.     listen 80;
  3.     server_name  php7.thinkcmf.com;
  4.     root /var/www/html/php7.thinkcmf.com; # 该项要修改为你准备存放相关网页的路径
  5.     location / {
  6.         index  index.php index.html index.htm;
  7.          #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
  8.          if (!-e $request_filename)
  9.          {
  10.             #地址作为将参数rewrite到index.php上。
  11.             rewrite ^/(.*)$ /index.php/$1;
  12.             #若是子目录则使用下面这句,将subdir改成目录名称即可。
  13.             #rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
  14.          }
  15.     }
  16.     #proxy the php scripts to php-fpm
  17.     location ~ \.php {
  18.             include fastcgi_params;
  19.             ##pathinfo支持start
  20.             #定义变量 $path_info ,用于存放pathinfo信息
  21.             set $path_info "";
  22.             #定义变量 $real_script_name,用于存放真实地址
  23.             set $real_script_name $fastcgi_script_name;
  24.             #如果地址与引号内的正则表达式匹配
  25.             if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)[        DISCUZ_CODE_42        ]quot;) {
  26.                     #将文件地址赋值给变量 $real_script_name
  27.                     set $real_script_name $1;
  28.                     #将文件地址后的参数赋值给变量 $path_info
  29.                     set $path_info $2;
  30.             }
  31.             #配置fastcgi的一些参数
  32.             fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  33.             fastcgi_param SCRIPT_NAME $real_script_name;
  34.             fastcgi_param PATH_INFO $path_info;
  35.             ###pathinfo支持end
  36.         fastcgi_intercept_errors on;
  37.         fastcgi_pass   127.0.0.1:9000;
  38.     }
  39. }
复制代码

2.重启nginx

  1. $ service nginx reload
复制代码


3.

  1. $ vim /var/www/html/php7.thinkcmf.com/index.php

  2. </str>
复制代码


把下面的代码复制到这个文件 里

  1. <?php

  2. phpinfo();
复制代码


4.查看访问http://php7.thinkcmf.com

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.