🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# php源码安装 > 解压PHP软件,进行编译安装,将程序安装到/application目录中,并且创建软链接 ## 安装依赖库 ```Bash yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel -y yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel ``` ## 安装其它相关程序---libmcrypt ```Bash #wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum -y install libmcrypt-devel mhash mcrypt rpm -qa libmcrypt-devel mhash mcrypt #php下载地址 http://php.net/releases/ ``` <!--more--> ## 下载并解压 ```Bash #下载安装包并解压 cd ~/tools/ wget http://cn2.php.net/distributions/php-5.6.36.tar.gz tar xf php-5.6.36.tar.gz cd php-5.6.36 #----正式编译前也可以把这个软件安装上(libxslt*) ``` ## 配置 ``` ./configure --prefix=/apps/php-5.6.36 \ --with-mysql=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --with-mcrypt \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --enable-short-tags \ --enable-static \ --with-xsl \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no ``` ``` ##提示 如下内容 即成功 Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands ``` ## 编译--安装 ```bash ln -s /apps/mysql/lib/libmysqlclient.so.18 /usr/lib64/ #可以不创建 touch ext/phar/phar.phar #这个文件一定要创建 make && make install ln -s /apps/php-5.6.36/ /apps/php ``` ``` Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc pharcommand.inc invertedregexiterator.inc directorygraphiterator.inc directorytreeiterator.inc phar.inc Build complete. ``` ```bash [root@web01 php-5.6.36]# make install Installing PHP CLI binary: /apps/php-5.6.36/bin/ Installing PHP CLI man page: /apps/php-5.6.36/php/man/man1/ Installing PHP FPM binary: /apps/php-5.6.36/sbin/ Installing PHP FPM config: /apps/php-5.6.36/etc/ Installing PHP FPM man page: /apps/php-5.6.36/php/man/man8/ Installing PHP FPM status page: /apps/php-5.6.36/php/php/fpm/ Installing PHP CGI binary: /apps/php-5.6.36/bin/ Installing PHP CGI man page: /apps/php-5.6.36/php/man/man1/ Installing build environment: /apps/php-5.6.36/lib/php/build/ Installing header files: /apps/php-5.6.36/include/php/ Installing helper programs: /apps/php-5.6.36/bin/ program: phpize program: php-config Installing man pages: /apps/php-5.6.36/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /apps/php-5.6.36/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /apps/php-5.6.36/etc/pear.conf You may want to add: /apps/php-5.6.36/lib/php to your php.ini include_path /root/tools/php-5.6.36/build/shtool install -c ext/phar/phar.phar /apps/php-5.6.36/bin ln -s -f phar.phar /apps/php-5.6.36/bin/phar Installing PDO headers: /apps/php-5.6.36/include/php/ext/pdo/ [root@web01 php-5.6.36]# echo $? 0 ``` ## 复制php.ini配置文件 ```bash [root@web01 php-5.6.36]# cp /root/tools/php-5.6.36/php.ini-production /apps/php-5.6.36/lib/php.ini ``` ## 复制php-fpm配置文件 ```bash [root@web01 php-5.6.36]# cd /apps/php-5.6.36/etc/ [root@web01 etc]# ls pear.conf php-fpm.conf.default [root@web01 etc]# cp php-fpm.conf.default php-fpm.conf [root@web01 etc]# ll total 52 -rw-r--r-- 1 root root 1332 Feb 27 22:53 pear.conf -rw-r--r-- 1 root root 22609 Feb 27 22:56 php-fpm.conf -rw-r--r-- 1 root root 22609 Feb 27 22:53 php-fpm.conf.default [root@web01 etc]# /apps/php-5.6.36/sbin/php-fpm -t [27-Feb-2018 22:56:53] NOTICE: configuration file /apps/php-5.6.36/etc/php-fpm.conf test is successful [root@web01 etc]# /apps/php-5.6.36/sbin/php-fpm [root@web01 etc]# ss -lntup |grep 9000 tcp LISTEN 0 16384 127.0.0.1:9000 *:* users:(("php-fpm",129733,7),("php-fpm",129734,0),("php-fpm",129735,0)) ``` ## LNMP搭建网站前的测试。 > 测试nginx与php配合是否成功 > php与MySQL配合是否成功 > 部署网站 ## 测试nginx与php配合是否成功 ```bash server { listen 80; server_name blog.etiantian.org; root html/blog; index index.php index.html index.htm; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } echo '<?php phpinfo();?>' >/apps/nginx/html/blog/test_info.php ``` ## php与MySQL配合是否成功 ```bash test_mysql.php <?php //$link_id=mysql_connect('主机名','用户','密码'); $link_id=mysql_connect('172.16.1.51','wordpress','123456') or mysql_error(); if($link_id){ echo "mysql successful by oldboy ! \n"; }else{ echo mysql_error(); } ?> ```