php7升级 阿里云服务器搭建lnmp(Cenons7.4+nginx+mysql5.7+php7)
php7出来也有一段时间了,一直没时间去看,今天就装机测试一下性能。
更新系统软件 yum update
安装编译工具:yum install gcc automake autoconf libtool gcc-c++
- 安装nginx
1. 安装nginx源 yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2. 安装nginx yum install nginx
3. 启动 nginxservice nginx start 成功显示:Redirecting to /bin/systemctl start nginx.service
4. 访问 http://你的ip/ 如果成功安装会出来nginx默认的欢迎界面
- 安装mysql5.7
# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
安装MySQL
shell> yum install mysql-community-server
启动MySQL服务
shell> systemctl start mysqld
查看MySQL的启动状态
shell> systemctl status mysqld
开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
下面就是修改密码 增加远程登录用户
更换密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass12!';
增加远程登录用户
grant all privileges on database.* to 'my'@'%' IDENTIFIED BY 'my123456.A';
- 编译安装php7.0.1
1.下载php7源码包cd /root & wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
2. 解压源码包源码包的位置可以使用 find / -name php7 查找 并进入所在文件夹tar -xvf php7.tar.gz
3. 打开解压好的包cd php-7.0.1
4. 安装php依赖包 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,我们一一解决,基本都是相关软件开发包没有安装导致)
./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.
解决:
$ yum install libxml2 libxml2-devel
2. configure: error: Cannot find OpenSSL's <evp.h>
解决:
$ yum install openssl openssl-devel
3. configure: error: Please reinstall the BZip2 distribution
解决:
$ yum install bzip2 bzip2-devel
4. configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
解决:
$ yum install libcurl libcurl-devel
5. If configure fails try --with-webp-dir=<DIR> configure: error: jpeglib.h not found.
解决:
$ yum install libjpeg libjpeg-devel
6. If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
解决:
$ yum install libpng libpng-devel
7. If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
解决:
$ yum install freetype freetype-devel
8. configure: error: Unable to locate gmp.h
解决:
$ yum install gmp gmp-devel
9. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决:
$ yum install libmcrypt libmcrypt-devel
10. configure: error: Please reinstall readline - I cannot find readline.h
解决:
$ yum install readline readline-devel
11. configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决:
$ yum install libxslt libxslt-devel
6. 编译与安装make && make install这里要make好久,要耐心一下
7. 添加 PHP 命令到环境变量vim /etc/profile在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改动立即生效执行 source /etc/profile
查看环境变量 echo $PATH
查看php版本php -v
8. 配置 php-fpm
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
9.启动php-fpm/etc/init.d/php-fpm start
配置nginx虚拟机,绑定域名
# vim /etc/nginx/nginx.conf
重启nginx
# service nginx reload
把下面的代码复制到这个index 里
<?php
phpinfo();
显示