Heim  >  Artikel  >  Backend-Entwicklung  >  So stellen Sie PHP auf Centos6.8 bereit

So stellen Sie PHP auf Centos6.8 bereit

藏色散人
藏色散人Original
2021-11-25 09:59:542014Durchsuche

So stellen Sie PHP in Centos6.8 bereit: 1. Installieren Sie PHP. 3. Ändern Sie die php.ini-Konfigurationsdatei. 5. Konfigurieren Sie Apache.

So stellen Sie PHP auf Centos6.8 bereit

Die Betriebsumgebung dieses Artikels: Centos6.8-System, PHP7.0, Dell G3.

Wie stelle ich PHP auf Centos6.8 bereit?

centos6.8 Quellcode-Installation php7.0

Abhängigkeitspakete installieren

yum -y install gd gd-devel zlib-devel libjpeg-devel libiconv-devel. libxml2 libxml 2- devel <code>yum -y install gd gd-devel zlib-devel libjpeg-devel libiconv-devel libxml2 libxml2-devel <br> curl curl-devel mhash mcrypt libxslt-devel <br> libmcrypt-devel libjpeg-devel libpng-devel
安装时遇到 No package libmcrypt available的情况
解决方法:yum install epel-release //扩展包更新包

若libiconv安装失败,可以下载源码,使用源码安装
参考https://www.cnblogs.com/jkko123/p/6357670.html

下载php

下载地址:http://cn2.php.net/distributions/php-7.0.1.tar.gz
tar -zxvf php-7.0.1.tar.gz
cd php-7.0.1
./configure <br> --prefix=/usr/local/php7 <br> --exec-prefix=/usr/local/php7 <br> --bindir=/usr/local/php7/bin <br> --sbindir=/usr/local/php7/sbin <br> --includedir=/usr/local/php7/include <br> --libdir=/usr/local/php7/lib/php <br> --mandir=/usr/local/php7/php/man <br> --with-config-file-path=/usr/local/php7/etc <br> --with-mcrypt=/usr/include <br> --with-mhash <br> --with-openssl <br> --with-mysqli=shared,mysqlnd <br> --with-pdo-mysql=shared,mysqlnd <br> --with-gd <br> --with-iconv <br> --with-zlib <br> --enable-zip <br> --enable-inline-optimization <br> --disable-debug <br> --disable-rpath <br> --enable-shared <br> --enable-xml <br> --enable-bcmath <br> --enable-shmop <br> --enable-sysvsem <br> --enable-mbregex <br> --enable-mbstring <br> --enable-ftp <br> --enable-gd-native-ttf <br> --enable-pcntl <br> --enable-sockets <br> --with-xmlrpc <br> --enable-soap <br> --without-pear <br> --with-gettext <br> --enable-session <br> --with-curl <br> --with-jpeg-dir <br> --with-freetype-dir <br> --enable-opcache <br> --enable-fpm <br> --without-gdbm <br> --disable-fileinfo <br> --with-apxs2="/usr/local/apache2/bin/apxs

make
make install

配置文件

cp /root/php-7.0.15/php.ini-development /usr/local/php7/lib/php.ini

cp -R /root/php-7.0.15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
mkdir /usr/local/php7/tmp
chmod 766 /usr/local/php7/tmp

修改php.ini配置文件

extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20151012/" <br> session.save_path = "/usr/local/php7/tmp"

配置环境变量

echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH' >> /etc/profile
使生效source /etc/profile

自启动

chkconfig --add php-fpm <br> chkconfig php-fpm on

启动服务

chmod 755 /etc/init.d/php-fpm <br> service php-fpm start

配置apache

安装php后,需要配置apache使其能够支持php。
在apache的配置文件中加入下边的配置:
AddType application/x-httpd-php .php
这是能使apache调用php模块解析php文件

< IfModule dir_module>
DirectoryIndex index.html
< /IfModule>
中的index.html前加index.php

测试

在apache的htdocs下新建一个index.php文件
< ?php <br/> phpinfo(); <br/> ? > curl curl-devel mhash mcrypt libxslt-devel
libmcrypt-devel libjpeg-devel libpng-devel

Während der Installation ist kein Paket libmcrypt verfügbar

Lösung: Yum install epel-release //Extension package update Package

Wenn die libiconv-Installation fehlschlägt, können Sie den Quellcode herunterladen und zur Installation verwenden

Siehe https://www.cnblogs.com/jkko123/p/6357670.html🎜

PHP herunterladen🎜🎜Download-Adresse: http://cn2.php.net/distributions/php-7.0.1.tar.gz 🎜tar -zxvf php-7.0.1.tar.gz 🎜cd php-7.0 .1 🎜./configure 🎜 --prefix=/usr/local/php7 🎜 --exec-prefix=/usr/local/php7 🎜 --bindir=/usr /local/php7/bin 🎜 --sbindir=/usr/local/php7/sbin 🎜 --includedir=/usr/local/php7/include 🎜 --libdir=/usr/local/php7/lib/php 🎜 -- mandir=/usr/local /php7/php/man 🎜 --with-config-file-path=/usr/local/php7/etc 🎜 --with-mcrypt=/usr/include 🎜 --with-mhash 🎜 - -with-openssl 🎜 - -with-mysqli=shared,mysqlnd 🎜 --with-pdo-mysql=shared,mysqlnd 🎜 --with-gd 🎜 --with-iconv 🎜 --with-zlib 🎜 --enable-zip 🎜 --enable-inline -optimization 🎜 --disable-debug 🎜 --disable-rpath 🎜 --enable-shared 🎜 --enable-xml 🎜 --enable-bcmath 🎜 --enable-shmop 🎜 --enable-sysvsem 🎜 --enable-mbregex 🎜 --enable-mbstring 🎜 --enable-ftp 🎜 --enable-gd-native-ttf 🎜 --enable-pcntl 🎜 --enable-sockets 🎜 --with-xmlrpc 🎜 --enable -soap 🎜 --without -pear 🎜 --with-gettext 🎜 --enable-session 🎜 --with-curl 🎜 --with-jpeg-dir 🎜 --with-freetype-dir 🎜 --enable-opcache 🎜 - -enable-fpm 🎜 - -without-gdbm 🎜 --disable-fileinfo 🎜 --with-apxs2="/usr/local/apache2/bin/apxs🎜🎜make 🎜make install code>🎜

Configuration file🎜🎜cp /root/php-7.0.15/php.ini-development /usr/local/php7/lib /php.ini 🎜🎜cp -R /root/php-7.0.15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 🎜cp /usr/ local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf 🎜cp /usr/local/php7 /etc/php-fpm.d /www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf 🎜mkdir /usr/local/php7/tmp 🎜<code>chmod 766 /usr/local/php7/tmp🎜

Ändere die php.ini-Konfigurationsdatei

🎜extension_dir = " /usr/local/php7/lib /php/extensions/no-debug-zts-20151012/" 🎜 session.save_path = "/usr/local/php7/tmp"🎜

Umgebungsvariablen konfigurieren

🎜echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH' >> /etc/profile 🎜 Machen Sie es effektivsource /etc/profile🎜

self-start

🎜chkconfig --add php-fpm 🎜 chkconfig php- fpm on🎜

Start service

🎜chmod 755 /etc/init.d/php-fpm 🎜 service php-fpm start🎜Apache konfigurieren🎜 🎜Nach der Installation von PHP müssen Sie Apache für die Unterstützung von PHP konfigurieren. 🎜 Fügen Sie der Apache-Konfigurationsdatei die folgende Konfiguration hinzu: 🎜AddType application/x-httpd-php .php 🎜 Dadurch kann Apache das PHP-Modul aufrufen, um die PHP-Datei zu analysieren. 🎜 In 🎜 < IfModule dir_module> ; 🎜 DirectoryIndex index.html 🎜 < /IfModule> ?php 🎜 phpinfo(); 🎜 ? > 🎜 Testen Sie im Browser 🎜🎜Erweiterung hinzufügen 🎜🎜Verwenden Sie nach der Installation phpinfo(), um festzustellen, dass es keine Erweiterung für pdo_mysql gibt. 🎜

Laden Sie das komprimierte Paket der pdo_mysql-Erweiterung herunter
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar -xzvf PDO_MYSQL-1.0.2.tgz
cd /root/php-7.0.15/ext/pdo_mysql
/usr/local/php7/bin/phpize
./configure --with-php-config=/#usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
为mysql的头文件 做一个软链接,因为mysql安装时指定了安装目录,不做链接,找不到头文件
ln -s /usr/local/mysql/include/ /usr/local/include/
make
make install

修改php配置文件

在配置文件中添加:
extension_dir = /usr/local/php7/lib/php/extensions/no-debug-zts-20151012/ <br> extension=pdo_mysql.so

然后重启php-fpm 和apache
测试,发现仍然无效。
通过phpinfo()函数发现
Loaded Configuration File 为none

然后 cp /usr/local/php7/lib/php.ini /usr/local/php7/etc/tar -xzvf PDO_MYSQL-1.0.2.tgz

cd /root/php-7.0.15/ext/pdo_mysql

/usr/local/php7/bin/phpize

./configure -- with-php-config=/#usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

Erstellen Sie einen Softlink für die MySQL-Header-Datei, weil mysql Das Installationsverzeichnis wird während der Installation angegeben, es erfolgt keine Verknüpfung und die Header-Datei kann nicht gefunden werdenln -s /usr/local/mysql/include/ /usr/local/include/ make

make install

PHP-Konfigurationsdatei ändern

In der Konfigurationsdatei hinzufügen: 🎜extension_dir = /usr/local/php7 /lib/php/extensions/no-debug-zts-20151012/ 🎜 extension=pdo_mysql.so🎜🎜Dann starten Sie php-fpm und Apache 🎜 zum Testen neu und stellen fest, dass es immer noch funktioniert ungültig. 🎜 Durch die Funktion phpinfo() festgestellt, dass 🎜 die geladene Konfigurationsdatei keine ist 🎜🎜 Dann cp /usr/local/php7/lib/php.ini /usr/local/php7/etc/🎜🎜Erneut testen erfolgreich 🎜🎜Empfohlenes Lernen: „🎜PHP Video Tutorial🎜“🎜🎜🎜

Das obige ist der detaillierte Inhalt vonSo stellen Sie PHP auf Centos6.8 bereit. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn