Table of Contents
CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7
PHP-FPM
MySQL支持
几个问题
编译问题:cc: Internal error: Killed (program cc1)
PHP报找不到mysql服务
Home php教程 php手册 CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7

CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7

Jun 13, 2016 am 08:49 AM
centos mysql php7 Down and Install support of compile solve

CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7

最近试了一下PHP7,在编译和支持MySQL上都遇到一些问题,相信不少同学也同样遇到,所以在这里聊一下这个过程。简单来讲编译PHP7只需要3步:

<p>1、./buildconf --force</p>
<p>2、./configure</p>
<p>3、make && make install</p>
Copy after login

1、3步,都没啥好管的,configure是编译的关键,涉及到PHP对一些库的支持,这里我们使用最小的支持,包括MySQL:

<p>curl</p>
<p>gd</p>
<p>fpm</p>
<p>mysqlnd</p>
Copy after login

之所以把curl和gd拿来说,目的是要搞清楚,这些三方库在编译PHP之前得安装好,可以直接使用yum安装在默认位置,也可以编译安装到指定位置,yum安装后,编译时不用指定库的安装位置,关于安装这些库,可以搜索一下有很多。下面看看基本的configure

./configure --prefix=/apps/php/php7.<span>0</span> --enable-mbstring --with-curl --with-gd --with-config-<span>file</span>-path=/apps/php/php7.<span>0</span>/etc/ --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd
Copy after login

PHP-FPM

关于fpm,相信不用多说,用它来支持PHP是一个比较好的选择,PHP5.3.3开始就已经内置了php-fpm,所以PHP7里当然也有,只需要--enable-fpm一下就可以了

php-fpm参数:

<p>--start 启动</p>
<p>--stop 强制终止</p>
<p>--quit 平滑终止</p>
<p>--restart 重启</p>
<p>--reload 重新平滑加载php的php.ini</p>
<p>--logrotate 重新启用log文件</p>
Copy after login

MySQL支持

重点讲一下这个,因为在它上面花了一点时间,不知道从哪一版本开始,PHP不在希望使用mysql的库来支持mysql的连接,启用了mysqlnd来支持,听说比libmysql要快很多,PHP5.x还可以使用libmysql,PHP7貌似已经取消了支持,编译都没有了--with-mysql参数,只支持--with-mysqli和--with-pdo-mysql,可以通过查看configure的参数来知道:

./configure -help | <span>grep</span> mysql
Copy after login

可以看到,PHP希望使用mysqlnd来支持MySQL,所以参数可以这样写:

<p>--enable-mysqlnd</p>
<p>--with-mysqli=mysqlnd</p>
<p>--with-pdo-mysql=mysqlnd</p>
Copy after login

mysqlnd是不需要mysql支持的,所以不用先安装好mysql一样可以编译通过,启动php-fpm,查看一下phpinfo,能看到mysqlnd和pdo_mysql表示php已经可以支持mysql了(这里用的是pdo,mysqli同理)

几个问题

编译问题:cc: Internal error: Killed (program cc1)

这个问题是第一次遇到,原来是我的阿里云服务器关掉了swap,内存不够用,就报了这个错。 解决办法很简单,configure时加上--disable-fileinfo参数就可以了。

PHP报找不到mysql服务

正如它所说,确实没找到,看看phpinfo中pdo_mysql.default_socket项

mysql.sock在哪里,再看一下mysql.sock的真正位置,使用命令:ps -ef|grep mysql查看:

明显不在一个位置上,我的正确位置是:/var/lib/mysql/mysql.sock

所以,修改一下php.ini,找到pdo_mysql.default_socket,改为你的实际位置,重启一下php-fpm,很不幸,虽然php.ini有这个配置,修改后,竟然不行,最好是编译的时候,指定mysql.socket的位置:

<p>--with-mysql-sock=/var/lib/mysql/mysql.sock</p>
Copy after login

如果还不行,可以到/tmp目录下建立一个mysql.sock的软链接:

<span>ln</span> -s /var/lib/mysql/mysql.sock mysql.sock
Copy after login

再重启一次php-fpm,相信已经正常运行了。如果需要PHP支持的库更多,可以再次编译,在configure时把需要的支持加上,就是--with-xxx这中,记得如果是三方的,要先安装这些库才行哦。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

CentOS Interview Questions: Ace Your Linux System Administrator Interview CentOS Interview Questions: Ace Your Linux System Administrator Interview Apr 09, 2025 am 12:17 AM

Frequently asked questions and answers to CentOS interview include: 1. Use the yum or dnf command to install software packages, such as sudoyumininstallnginx. 2. Manage users and groups through useradd and groupadd commands, such as sudouseradd-m-s/bin/bashnewuser. 3. Use firewalld to configure the firewall, such as sudofirewall-cmd--permanent-add-service=http. 4. Set automatic updates to use yum-cron, such as sudoyumininstallyum-cron and configure apply_updates=yes.

How to create a new connection to mysql in navicat How to create a new connection to mysql in navicat Apr 09, 2025 am 07:21 AM

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

How to execute sql in navicat How to execute sql in navicat Apr 08, 2025 pm 11:42 PM

Steps to perform SQL in Navicat: Connect to the database. Create a SQL Editor window. Write SQL queries or scripts. Click the Run button to execute a query or script. View the results (if the query is executed).

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

See all articles