安装php
1.安装前准备
- 确保apache已经安装
- 确保mysql已经安装
- 安装libxml2
libxml2是解析xml会用到的,安装php的时候会去查找它的路径,如果不需要,编译php时加上--disable-libxml的参数
$ yum install libxml2-devel
2.准备安装
$ cd /usr/local/src $ wget -O php-7.1.10.tar.bz2 http://cn2.php.net/get/php-7.1.10.tar.bz2/from/this/mirror $ tar -zxvf php-7.1.10.tar.bz2 $ cd php-7.1.10 $ ./configure --help #查看编译参数 $ ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-mysqli --with-pdo-mysql $ /usr/local/src/php-7.1.11/libtool --finish /usr/local/src/php-7.1.11/libs $ cp /usr/local/src/php-7.1.11/php.ini-development /usr/local/php/lib/php.ini $ /usr/local/httpd/bin/apachectl stop #关闭apache $ vi /usr/local/httpd/conf/httpd.conf LoadModule php7_module modules/libphp7.so #检查是否有这一行,这样apache才能调用到php模块 #告知 Apache 将特定的扩展名解析成php <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
$ /usr/local/httpd/bin/apachectl start #启动apache $ firewall-cmd --zone=public --add-port=80/tcp --permanent #防火墙打开80端口,这样主机就可以访问到虚拟机的网站了
#添加环境变量 $ vi /etc/profile PATH=$PATH:/usr/local/httpd/bin:/usr/local/memcached/bin:/usr/local/php/bin export PATH $ source /etc/profile
3.运行
$ php -r 'echo "Hello World\n";' Hello World