首先更新系统软件 yum update
安装gcc编译器 yum install gcc && yum install gcc-c++
编译安装php7.1.8
1.下载php7源码包
1 | $ cd /root & wget -O php7.tar.gz http://am1.php.net/get/php-7.1.8.tar.gz/from/this/mirror |
2.解压源码包
1 | $ tar -xzvf php7.tar.gz |
3.进入PHP目录
1 | $ cd php-7.1.8 |
4.安装php依赖包
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,我们一一解决,基本都是相关软件开发包没有安装导致
1 | $ ./configure \ |
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
解决: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
解决:1
$ yum install libcurl libcurl-devel
5.If configure fails try –with-webp-dir=
解决:1
$ yum install libjpeg libjpeg-devel
6.If configure fails try –with-webp-dir=
checking for jpeg_read_header in -ljpeg… yes
configure: error: png.h not found.
解决:1
$ yum install libpng libpng-devel
7.If configure fails try –with-webp-dir=
checking for jpeg_read_header in -ljpeg… yes
checking for png_write_image in -lpng… yes
If configure fails try –with-xpm-dir=
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
如果显示无可用的包:1
2
3$ yum install epel-release //扩展包更新包
$ yum update //更新yum源
$ 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 |
在末尾加入
PATH=$PATH:/usr/local/php/bin
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 |
1 | $ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf |
1 | $ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm |
1 | $ chmod +x /etc/init.d/php-fpm |
9.启动php-fpm
1 | $ /etc/init.d/php-fpm start |
$ /etc/init.d/php-fpm start
安装Nginx
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 |
Redirecting to /bin/systemctl start nginx.service
4.访问http://你的ip/
1 | 如果成功安装会出来nginx默认的欢迎界面 |
安装MySQL5.7.*
1.安装mysql源
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 |
Redirecting to /bin/systemctl start mysqld.service
5.查看mysql启动状态
1 | $ service mysqld status |
出现pid
证明启动成功
6.获取mysql默认生成的密码
1 | $ grep 'temporary password' /var/log/mysqld.log |
7.换成自己的密码
1 | $ mysql -uroot -p |
8. 更换密码
1 | mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass666!'; |
注意:本地可以连接MySQL服务器,远程就不行.1
2
3
4
5
6
7mysql -uroot -p
use mysql;
Grant all on *.* to 'root'@'%' identified by 'root用户的密码' with grant option;
flush privileges;
然后用以下命令查看哪些用户和host可以访问,%代表任意ip地址
select user,host from user;
php和Nginx互通
修改文件
1 | $ vim /etc/nginx/conf.d/sui.conf |
配置文件
1 | server |
编译安装php扩展
1.查看自己服务器对象php版本
1 | php -v |
2.根据版本下载PHP源代码
1 | $ wget -O php7.tar.gz http://am1.php.net/get/php-7.1.8.tar.gz/from/this/mirror |
3、解压源码压缩包
1 | $ tar -zxvf php-7.1.8.tar.gz |
4、进入源码中的ext/pcntl目录
1 | cd pphp-7.1.8/ext/pcntl/ |
5、运行 phpize 命令
1 | phpize |
如果报错:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
注:如果报错,写绝对路径:sudo /usr/local/php/bin/phpize
1 | yum install m4 |
6、运行 configure命令
1 | ./configure |
7、makefile
1 | make && make install |
8.配置ini文件
1 | 通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=pcntl.so |
也可以使用pecl 安装
1 | pecl install memcached |