CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7
CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决,centosphp7
最近试了一下PHP7,在编译和支持MySQL上都遇到一些问题,相信不少同学也同样遇到,所以在这里聊一下这个过程。简单来讲编译PHP7只需要3步:
<p>1、./buildconf --force</p> <p>2、./configure</p> <p>3、make && make install</p>
1、3步,都没啥好管的,configure是编译的关键,涉及到PHP对一些库的支持,这里我们使用最小的支持,包括MySQL:
<p>curl</p> <p>gd</p> <p>fpm</p> <p>mysqlnd</p>
之所以把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
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>
MySQL支持
重点讲一下这个,因为在它上面花了一点时间,不知道从哪一版本开始,PHP不在希望使用mysql的库来支持mysql的连接,启用了mysqlnd来支持,听说比libmysql要快很多,PHP5.x还可以使用libmysql,PHP7貌似已经取消了支持,编译都没有了--with-mysql参数,只支持--with-mysqli和--with-pdo-mysql,可以通过查看configure的参数来知道:
./configure -help | <span>grep</span> mysql
可以看到,PHP希望使用mysqlnd来支持MySQL,所以参数可以这样写:
<p>--enable-mysqlnd</p> <p>--with-mysqli=mysqlnd</p> <p>--with-pdo-mysql=mysqlnd</p>
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>
如果还不行,可以到/tmp目录下建立一个mysql.sock的软链接:
<span>ln</span> -s /var/lib/mysql/mysql.sock mysql.sock
再重启一次php-fpm,相信已经正常运行了。如果需要PHP支持的库更多,可以再次编译,在configure时把需要的支持加上,就是--with-xxx这中,记得如果是三方的,要先安装这些库才行哦。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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 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 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.

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.

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.

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).

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".
