<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Thu, 26 Nov 2020 01:33:49 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>PHP &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Centos8安装LNMP环境</title>
		<link>https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/</link>
					<comments>https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Wed, 09 Sep 2020 13:43:40 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=164</guid>

					<description><![CDATA[<p>最近在搭建网站，下面是我用的LNMP版本： Centos 8 PHP 7.4.10 Nginx 1.&#8230; <a href="https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Centos8安装LNMP环境</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/">Centos8安装LNMP环境</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-verse">最近在搭建网站，下面是我用的LNMP版本：
  Centos 8
  PHP 7.4.10
  Nginx 1.18.0
  Mysql 8.0.21</pre>



<h3>安装Nginx</h3>



<pre class="wp-block-code"><code>yum install yum-utils</code></pre>



<p>编写nginx.repo文件：</p>



<pre class="wp-block-code"><code>vi /etc/yum.repos.d/nginx.repo</code></pre>



<p>然后复制下面到nginx.repo里面：</p>



<pre class="wp-block-code"><code>&#91;nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

&#91;nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true</code></pre>



<p>这里我们一般都用stable（稳定版），如果要使用mainline（主线版），需要使用命令切换</p>



<pre class="wp-block-code"><code>yum-config-manager --enable nginx-mainline</code></pre>



<p>然后我们就可以直接用yum安装：</p>



<pre class="wp-block-code"><code> yum install nginx</code></pre>



<p>安装完成之后启动：</p>



<pre class="wp-block-code"><code>nginx</code></pre>



<h3>安装PHP</h3>



<p>先安装依赖包：</p>



<pre class="wp-block-code"><code>yum install gcc gcc-c++ make libxml2-devel openssl-devel curl-devel  libpng-devel sqlite-devel oniguruma libzip-devel bzip2-devel  readline-devel libxslt-devel</code></pre>



<p>除了上面的，我们还需要单独下载oniguruma-devel进行安装：</p>



<pre class="wp-block-code"><code>wget http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-1.el8.x86_64.rpm</code></pre>



<p>下载完成之后用rpm安装：</p>



<pre class="wp-block-code"><code>rpm -ivh oniguruma-devel-6.8.2-1.el8.x86_64.rpm</code></pre>



<p>接着我们可以下载php源码包了：</p>



<pre class="wp-block-code"><code>wget https://www.php.net/distributions/php-7.4.10.tar.gz</code></pre>



<p>下载完成之后解压：</p>



<pre class="wp-block-code"><code>tar -zxvf php-7.4.10.tar.gz</code></pre>



<p>解压完成之后，进入目录（<code>cd php-7.4.10</code>）执行configure，这里面的&#8211;with-fpm-user和&#8211;with-fpm-group最好使用新建的普通账号（可以使用命令<code>addusr</code>）：</p>



<pre class="wp-block-code"><code>./configure --enable-fpm   --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-opcache --enable-pcntl -with-xsl --enable-sockets  --enable-exif --with-gettext --with-readline --with-bz2  --enable-calendar --with-openssl --with-zlib --with-curl --enable-gd --enable-ftp  --enable-mbstring  --with-zip --enable-mysqlnd</code></pre>



<p>配置完成之后，会看到下面的内容，表示配置成功了：</p>



<pre class="wp-block-verse">+--------------------------------------------------------------------+
| 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.</pre>



<p>接下来我们就可以开始编译了，在编译的时候我们可以加上-j选项来加快编译速度，后面的数字就是CPU核心数（可以使用命令<code>cat /proc/cpuinfo</code>查看）：</p>



<pre class="wp-block-code"><code>make -j4</code></pre>



<p>编译时间比较久，等编译结束之后，可以看到下面的内容表示编译成功了：</p>



<pre class="wp-block-verse">Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
invertedregexiterator.inc
directorytreeiterator.inc
clicommand.inc
directorygraphiterator.inc
pharcommand.inc
phar.inc
Build complete.
Don't forget to run 'make test'.</pre>



<p>接下来直接安装就可以了：</p>



<pre class="wp-block-code"><code>make install</code></pre>



<p>安装结束之后，需要拷贝配置文件到对应的目录下面：</p>



<pre class="wp-block-code"><code>cp php.ini-production /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin</code></pre>



<p>php.ini-production是生产环境的配置文件，php.ini-development是开发环境的配置文件。</p>



<p>修改/usr/local/etc/php-fpm.conf文件，把NONE改成/usr/local：</p>



<pre class="wp-block-code"><code>include=/usr/local/etc/php-fpm.d/*.conf</code></pre>



<p>直接启动php-fpm：</p>



<pre class="wp-block-code"><code>php-fpm -c /usr/local/php/php.ini</code></pre>



<h3>安装php的扩展</h3>



<p>在ext文件下，可以看到很多的文件夹，这些文件夹里面就是对应扩展的源码：</p>



<pre class="wp-block-verse">bcmath curl exif ftp iconv libxml odbc pdo pdo_odbc posix shmop sockets sysvmsg xml zend_test
bz2 date ext_skel.php gd imap mbstring opcache pdo_dblib pdo_pgsql pspell simplexml sodium sysvsem xmlreader zip
calendar dba ffi gettext intl mysqli openssl pdo_firebird pdo_sqlite readline skeleton spl sysvshm xmlrpc zlib
com_dotnet dom fileinfo gmp json mysqlnd pcntl pdo_mysql pgsql reflection snmp sqlite3 tidy xmlwriter
ctype enchant filter hash ldap oci8 pcre pdo_oci phar session soap standard tokenizer xsl</pre>



<p>这里以安装mysqli为例，首先我们需要安装autoconf：</p>



<pre class="wp-block-code"><code>yum install autoconf</code></pre>



<p>进入fileinfo目录，执行phpize命令：</p>



<pre class="wp-block-code"><code>/usr/local/bin/phpize</code></pre>



<p>完成之后执行configure：</p>



<pre class="wp-block-code"><code>./configure -with-php-config=/usr/local/bin/php-config</code></pre>



<p>配置完成之后，执行make编译安装：</p>



<pre class="wp-block-code"><code>make -j2 &amp;&amp; make install</code></pre>



<p>成功之后，在输出信息中可以找到对应的so文件，默认所有扩展都会安装在/usr/local/lib/php/extensions/no-debug-non-zts-20190902/目录下面：</p>



<pre class="wp-block-verse">Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/</pre>



<h3>安装MySQL</h3>



<p>关于MySQL的安装，可以参考我的另一篇文章，里面有详细说明：</p>



<figure class="wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-wqh博客"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="faDs99lxFM"><a href="https://wangqianhong.com/2020/08/mysql/">在Centos8上安装MySQL8</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="《在Centos8上安装MySQL8》—wqh博客" src="https://wangqianhong.com/2020/08/mysql/embed/#?secret=faDs99lxFM" data-secret="faDs99lxFM" width="500" height="282" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>
<p><a rel="nofollow" href="https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/">Centos8安装LNMP环境</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2020/09/centos-8%e5%ae%89%e8%a3%85lnmp%e7%8e%af%e5%a2%83/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
