Centos7下编译安装PHP

阅读更多
# yum groupinstall "Development Tools"
# yum -y install libxml2 libxml2-devel bzip2-devel curl curl-devel libjpeg-devel libpng libpng-devel libXpm-devel gcc gcc-c++ freetype-devel glib2-devel cairo-devel postgresql-devel libxslt libxslt-devel mysql-devel
# cd /usr/local/src
# wget http://cn.php.net/distributions/php-5.6.38.tar.bz2
# tar –xjvf php-5.6.38.tar.bz2
# cd php-5.6.38
# ./configure --prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56/etc --with-apxs2=/usr/local/apache24/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libxml-dir --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-sockets --enable-sysvsem --enable-xml --enable-zip
*** libtool: warning: remember to run 'libtool --finish /usr/local/src/php-5.6.38/libs'
【 如果之前的yum groupinstall及yum install相关的准备工作已经完成,下面部分将不会有,如果没有做准备工作,可根据错误提示一次次排错
configure: error: xml2-config not found. Please check your libxml2 installation.
# yum install -y libxml2 libxml2-devel
configure: error: Please reinstall the BZip2 distribution
# yum -y install bzip2-devel
configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/
# yum -y install curl curl-devel
configure: error: jpeglib.h not found.
# yum -y install libjpeg-devel
configure: error: png.h not found.
# yum -y install libpng libpng-devel
configure: error: xpm.h not found.
# yum -y install libXpm-devel
configure: error: freetype-config not found.
# yum -y install gcc gcc-c++ freetype-devel glib2-devel cairo-devel
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
# ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
# yum groupinstall "Development Tools"
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
# yum -y install postgresql-devel
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
# yum -y install libxslt libxslt-devel
# make
In file included from /usr/local/src/php-5.6.38/ext/mysqli/mysqli.c:34:0:
/usr/local/src/php-5.6.38/ext/mysqli/php_mysqli_structs.h:82:21: 致命错误:my_list.h:没有那个文件或目录
#include
编译中断。
make: *** [ext/mysqli/mysqli.lo] 错误 1
# yum -y install mysql-devel

# make
# make install
# cp php.ini-production /usr/local/php/php5.6/etc/php.ini
配置httpd支持PHP
# vim /etc/httpd/httpd.conf
搜索ServerName,把#ServerName www.example.com:80前面的#号删除(此处未做,在安装Apache时在此处添加ServerName localhost:80)
段中的Require all denied改为Require all granted
在AddType application/x-gzip .gz .tgz下面添加一行AddType application/x-httpd-php .php
段中添加
    AddType application/x-httpd-php .php
在启动httpd之前检验配置文件是否正确
# /usr/local/apache24/bin/apachectl –t
启动apache
# /usr/local/apache24/bin/apachectl start
测试
# curl localhost
测试是否正确解析PHP
# vim /usr/local/apache24/htdocs/1.php
输入PHP代码,然后在浏览器中输入IP/1.php测试
====================================================
默认虚拟主机
# vim /etc/httpd/httpd.conf
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf ==去掉行首的#
# vim /etc/httpd/extra/httpd-vhosts.conf
默认内容
  #默认虚拟主机
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com  #网站域名,只能有一个
ServerAlias www.dummy-host.example.com #网站第二域名,可以有多个,中间用空格隔开
ErrorLog "logs/dummy-host.example.com-error_log" #错误日志
CustomLog "logs/dummy-host.example.com-access_log" common #访问日志



ServerAdmin [email protected]
DocumentRoot "/usr/local/apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common

修改后
 
ServerAdmin [email protected]
DocumentRoot "/data/wwwroot/aming.com"
ServerName aming.com 
ServerAlias www.aming.com 
ErrorLog "logs/aming.com-error_log"
CustomLog "logs/aming.com-access_log" common



DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com

测试:
# mkdir -p /data/wwwroot/aming.com /data/wwwroot/www.123.com
# echo "aming.com" > /data/wwwroot/aming.com/index.html
# echo "123.com" > /data/wwwroot/www.123.com/index.html
# /usr/local/apache24/bin/apachectl -t
# /usr/local/apache24/bin/apachectl graceful //这个操作是重新加载httpd服务
# curl -x127.0.0.1:80 aming.com
# curl -x127.0.0.1:80 www.abc.com
如果显示You don't have permission to access /index.html on this server. 则表示权限设置有误,修改httpd.conf将"Deny from all"这行给注释掉就可以了。

你可能感兴趣的:(centos,php)