如何用yum安裝php,yum軟件安裝

本文目錄一覽:

阿里雲上的centos 7.2怎麼yum安裝php 5.6

因之前通過網易的 centos 鏡像,將阿里雲的 centos 升級到最新版了,乘自己的項目尚未開始正式開發,遂將所有的相應環境都升級到最高。

查看 centos 版本:

[root@iZ23d ~]# cat /etc/centos-release

CentOS Linux release 7.2.1511 (Core)

1、刪除之前的 php 版本:

[root@iZ23d ~]# yum remove php* php-common

Loaded plugins: langpacks

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

No Match for argument: php-5.4.16

No Match for argument: php-5.4.16.tar.gz

No Match for argument: php-7.0.1RC1

No Match for argument: php-7.0.1RC1.tar.gz

No Match for argument: phpMyAdmin-4.4.0.tar.gz

No Match for argument: php-common

No Packages marked for removal

2、rpm 安裝 Php7 相應的 yum源:

[root@iZ23d ~]# rpm -Uvh

Retrieving

warning: /var/tmp/rpm-tmp.LhJKKR: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY

Preparing… ################################# [100%]

package webtatic-release-7-3.noarch is already installed

3、 直接yum安裝php7:

[root@iZ23d ~]# yum install php70w

Loaded plugins: langpacks

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

Resolving Dependencies

— Running transaction check

。。。 【省略】

Warning: RPMDB altered outside of yum.

Installing : php70w-common-7.0.0-1.w7.x86_64 1/3

Installing : php70w-cli-7.0.0-1.w7.x86_64 2/3

Installing : php70w-7.0.0-1.w7.x86_64 3/3

Verifying : php70w-7.0.0-1.w7.x86_64 1/3

Verifying : php70w-common-7.0.0-1.w7.x86_64 2/3

Verifying : php70w-cli-7.0.0-1.w7.x86_64 3/3

Installed:

php70w.x86_64 0:7.0.0-1.w7

Dependency Installed:

php70w-cli.x86_64 0:7.0.0-1.w7 php70w-common.x86_64 0:7.0.0-1.w7

Complete!

4、檢查 php 版本:

[root@iZ23d ~]# php -v

PHP 7.0.0 (cli) (built: Dec 2 2015 20:42:32) ( NTS )

Copyright (c) 1997-2015 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

[root@iZ23d2e6hoqZ ~]#

以上顯示安裝成功!

5、重啟 Apache,查看 phpinfo :

[root@iZ23d ~]# systemctl restart httpd.service

檢查phpinfo:

PHP Version 7.0.0

SystemLinux iZ23d 3.10.0-229.11.1.el7.x86_64 #1 SMP Thu Aug 6 01:06:18 UTC 2015 x86_64

Build DateDec 2 2015 20:43:38

Server APIApache 2.0 Handler

Virtual Directory Supportdisabled

Configuration File (php.ini) Path/etc

Loaded Configuration File/etc/php.ini

Scan this dir for additional .ini files/etc/php.d

Additional .ini files parsed/etc/php.d/bz2.ini, /etc/php.d/calendar.ini, /etc/php.d/ctype.ini, /etc/php.d/curl.ini, /etc/php.d/exif.ini, /etc/php.d/fileinfo.ini, /etc/php.d/, /etc/php.d/gettext.ini, /etc/php.d/gmp.ini, /etc/php.d/iconv.ini, /etc/php.d/json.ini, /etc/php.d/phar.ini, /etc/php.d/shmop.ini, /etc/php.d/simplexml.ini, /etc/php.d/sockets.ini, /etc/php.d/tokenizer.ini, /etc/php.d/xml.ini, /etc/php.d/zip.ini

PHP API20151012

PHP Extension20151012

Zend Extension320151012

Zend Extension BuildAPI320151012,NTS

PHP Extension BuildAPI20151012,NTS

Debug Buildno

Thread Safetydisabled

Zend Signal Handlingdisabled

Zend Memory Managerenabled

Zend Multibyte Supportdisabled

IPv6 Supportenabled

DTrace Supportenabled

Registered PHP Streamshttps, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip

Registered Stream Socket Transportstcp, udp, unix, udg, ssl, sslv3, sslv2, tls, tlsv1.0, tlsv1.1, tlsv1.2

Registered Stream Filterszlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, bzip2.*, convert.iconv.*

This program makes use of the Zend Scripting Language Engine:

Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Configuration

apache2handler

Apache VersionApache/2.4.6 (CentOS)

Apache API Version20120211

Server Administratorxxxxxx@xxxxxx.com

Hostname:Portxxxx.xxxxx.xxx:0

User/Groupapache(48)/48

Max RequestsPer Child: 0 – Keep Alive: on – Max Per Connection: 100

TimeoutsConnection: 60 – Keep-Alive: 15

Virtual ServerYes

Server Root/etc/httpd

Loaded Modulescore mod_so http_core mod_access_compat mod_actions mod_alias mod_allowmethods mod_auth_basic mod_auth_digest mod_authn_anon mod_authn_core mod_authn_dbd mod_authn_dbm mod_authn_file mod_authn_socache mod_authz_core mod_authz_dbd mod_authz_dbm mod_authz_groupfile mod_authz_host mod_authz_owner mod_authz_user mod_autoindex mod_cache mod_cache_disk mod_data mod_dbd mod_deflate mod_dir mod_dumpio mod_echo mod_env mod_expires mod_ext_filter mod_filter mod_headers mod_include mod_info mod_log_config mod_logio mod_mime_magic mod_mime mod_negotiation mod_remoteip mod_reqtimeout mod_rewrite mod_setenvif mod_slotmem_plain mod_slotmem_shm mod_socache_dbm mod_socache_memcache mod_socache_shmcb mod_status mod_substitute mod_suexec mod_unique_id mod_unixd mod_userdir mod_version mod_vhost_alias mod_dav mod_dav_fs mod_dav_lock mod_lua prefork mod_proxy mod_lbmethod_bybusyness mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_heartbeat mod_proxy_ajp mod_proxy_balancer mod_proxy_connect mod_proxy_express mod_proxy_fcgi mod_proxy_fdpass mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_proxy_wstunnel mod_ssl mod_systemd mod_cgi mod_perl mod_php7

以上顯示 php7 安裝成功!

怎麼安裝PHP環境?

LAMP/LNMP 環境搭建

一.檢查系統環境

1.確認centos版本

[root@localhost ~]# cat /etc/redhat-release

2.檢查是否安裝過apache

rpm -qa | grep httpd

或者:

apachectl -v

或者:

httpd -v

3.檢查是否安裝過Mysql

service mysqld start

如果未被識別則沒有安裝

如果系統安裝過,或者安裝失敗,清理一下系統

4.清理Mysql痕迹

yum remove mysql

rm -f /etc/my.cnf

5.卸載Apache包

rpm -qa|grep httpd

注意:如果是新的系統或者你從來沒有嘗試安裝過,則以上步驟省略

二.安裝Apache、PHP、Mysql

停止防火牆服務

[root@localhost ~]# systemctl stop firewalld.service

禁用防火牆開機啟動服務

[root@localhost ~]# systemctl disable firewalld.service

1.安裝apache

[root@localhost ~]# yum -y install httpd

2.安裝php

[root@localhost ~]# yum -y install php

3.安裝php-fpm

[root@localhost ~]# yum -y install php-fpm

4.安裝Mysql

[root@localhost ~]# yum -y install mysql

5.安裝 mysql-server

[root@localhost ~]# yum install mariadb-server

CentOS 7+ 版本將MySQL數據庫軟件從默認的程序列表中移除,用mariadb代替了,entos7配置教程上,大多都是安裝mariadb,因為centos7默認將mariadb視作mysql。

因為mysql被oracle收購後,原作者擔心mysql閉源,所以又寫了一個mariadb,這個數據庫可以理解為mysql的分支。如果需要安裝mariadb,只需通過yum就可。

6.安裝 php-mysql

[root@localhost ~]# yum -y install php-mysql

三.安裝基本常用擴展包

1.安裝Apache擴展包

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

2.安裝PHP擴展包

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel

3.安裝Mysql擴展包

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

四.配置Apache、mysql開機啟動

重啟Apache、mysql服務(注意這裡和centos6有區別,Cenots7+不能使用6的方式)

systemctl start httpd.service #啟動apache

systemctl stop httpd.service #停止apache

systemctl restart httpd.service #重啟apache

systemctl enable httpd.service #設置apache開機啟動

重啟數據庫

#啟動MariaDB

[root@localhost ~]# systemctl start mariadb.service

#停止MariaDB

[root@localhost ~]# systemctl stop mariadb.service

#重啟MariaDB

[root@localhost ~]# systemctl restart mariadb.service

#設置開機啟動

[root@localhost ~]# systemctl enable mariadb.service

五.配置Mysql

初次安裝mysql是沒有密碼的,我們要設置密碼,mysql的默認賬戶為root

方式1:設置 MySQL 數據 root 賬戶的密碼:

[root@localhost ~]# mysql_secure_installation

當出現如下提示時候直接按回車:

Enter current password for root

出現如下再次回車:

Set root password? [Y/n]

出現如下提示輸入你需要設置的密碼,這裡輸入了root,輸入密碼是不顯示的,回車後再輸入一次確認:

New password:

接下來還會有四個確認,分別是:

Remove anonymous users? [Y/n]

Disallow root login remotely? [Y/n]

Remove test database and access to it? [Y/n]

Reload privilege tables now? [Y/n]

直接回車即可。

方式2:進入mysql mysql -r

修改mysql密碼:set password for ‘root’@’localhost’=password(‘root’);

mysql授權遠程連接(navicat等): grant all on *.* to root identified by ‘root’;

六.測試環境

我們在瀏覽器地址欄輸入,正常顯示,說明我們的lamp 環境搭建成功

七.安裝nginx

yum install yum-priorities -y

wget

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

Nginx 版本號可變更版本

八.配置nginx

1.nginx啟動,停止,重啟

systemctl start nginx.service #啟動nginx

systemctl stop nginx.service #停止

systemctl restart nginx.service #重啟

systemctl enable nginx.service #設置開機啟動

更改nginx端口號(根據自己需求)

cd /etc/nginx/conf.d/

vim default.conf

把listen 80改成listen 81

3.訪問即可看到nginx首頁

安裝完成訪問時候需要啟動php-fpm,不重啟訪問會出現下載文件,重啟命令如下

systemctl start php-fpm.service #啟動php-fpm

systemctl enable php-fpm.service #設置開機啟動

4.更改nginx配置文件識別php

vi /etc/nginx/conf.d/default.conf,把之前的#給去掉就可以了,順手改一下

location ~ .php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;

include fastcgi_params;

}

方法二 安裝nginx

yum install nginx

啟動nginx,並設置為開機啟動

systemctl start nginx

systemctl enable nginx

vim /etc/nginx/conf.d/default.conf

5.在 /usr/share/nginx/html中新建一個test.php

訪問即可看到php頁面

修改完成配置記得啟動apache 和php-fpm 哦!

九.負載配置

upstream site{

server 172.16.170.138;

server 172.16.170.139;

}

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log /var/log/nginx/log/host.access.log main;

location / {

root /usr/share/nginx/html;

index index.html index.htm;

proxy_pass ;

}

apache 默認目錄 /var/www/html

nginx 默認目錄 /usr/share/nginx/html

升級php版本

centos7 默認安裝php是5.4

查看yum的可安裝的php版本列表

yum provides php

開始升級PHP更新源:

rpm -Uvh

rpm -Uvh

yum remove php-common -y #移除系統自帶的php-common

php72版本

yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring

php56版本

yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring #安裝依賴包

查看php版本

php -v

安裝php fpm:

yum install php72w-fpm

yum provides php-fpm #因為我是準備搭建lnmp,所以安裝php-fpm,這裡會提示多個安裝源,選擇5.6版本的安裝就可以了

yum install php56w-fpm-5.6.31-1.w7.x86_64 -y

systemctl start php-fpm.service 【啟動】

systemctl enable php-fpm.service【開機自啟動】

CentOS yum有時出現“Could not retrieve mirrorlist ”的解決辦法——resolv.conf的配置

原因:沒有配置resolv.conf

解決方法:

到/etc目錄下配置resolv.conf加入nameserver IP,如:

nameserver 8.8.8.8

nameserver 8.8.4.4

search localdomain

保存再次運行上面的命令就可以。

nginx目錄 : /usr/share/nginx/html

/etc/nginx/conf.d/default.conf nginx配置目錄

apache目錄 : /var/www/html

/etc/httpd/conf/httpd.conf apache配置文件

nginx 配置域名

cd /etc/nginx

cp default.conf imooc.conf

修改server_name imooc.test.com 以及項目目錄

配置虛擬域名 windows 訪問需要在host增加 linuxip

ServerName

DocumentRoot “/var/www/html/learnlaravel/public”

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

關閉防火牆

setenforce 0

服務器上怎麼安裝php程序

你好,如果你的服務器是Windows系統,那麼你需要遠程到你的服務器,進行啟動IIS(asp環境),如果你需要php環境,你可以從xp.cn(小皮)或者bt.cn(寶塔)安裝面板

如果你的服務器是Linux,建議使用寶塔

打開終端,不同Linux系統的輸入指令不同:

Centos安裝腳本

終端輸入:yum install -y wget wget -O install.sh sh install.sh

Ubuntu/Deepin安裝腳本

終端輸入:wget -O install.sh sudo bash install.sh

Debian安裝腳本

終端輸入:wget -O install.sh bash install.sh

Fedora安裝腳本

終端輸入wget -O install.sh bash install.sh

輸入後進行安裝就可以了

linux yum安裝php7.3

先安裝前面的教程,再安裝後面的

參考教程1:

參考教程2:

安裝PHP

1、安裝PHP73

1.1、卸載舊版本PHP

yum remove php*

1.2、安裝EPEL:

sudo yum install epel-release

1.3、安裝remi(選一個):

sudo rpm -Uvh

rpm -Uvh

1.4、查看目前有php的什麼版本(可忽略)

sudo yum list php*

1.5、列出所有的php相關的rpm包(可忽略)

rpm -qa|grep php

1.6、刪除php相關的rpm包(一次只能刪除一個)(可忽略)

rpm -e php72w-mysqlnd-7.2.17-1.w7.x86_64

1.7、列出remi倉庫下所有PHP7.3可用模塊。(可忽略)

yum –enablerepo=remi-php73 search php | grep php73

1.8、安裝PHP 7.3

yum –enablerepo=remi-php73 install php

1、安裝 PHP7.3:

(解決yum安裝apache關聯不了PHP的問題,用以下命令安裝)

yum –enablerepo=remi-php73 install php

安裝模塊

yum –enablerepo=remi-php73 install php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml

2、設置開機啟動、運行服務:

systemctl enable php73-php-fpm

systemctl start php73-php-fpm

3、查找php.ini位置:

find /etc/opt/remi/php73 -name php.ini

/etc/opt/remi/php73/php.ini

找到apache的配置文件:httpd.conf

sudo find / -name httpd.conf

位置如下:

/etc/httpd/conf/httpd.conf

5、PHP日常操作

systemctl restart php73-php-fpm #重啟

systemctl start php73-php-fpm #啟動

systemctl stop php73-php-fpm #關閉

systemctl status php73-php-fpm #檢查狀態

php -m #查看PHP已安裝拓展模塊

php -v #查看PHP版本

centos 下如何通過yum安裝最新的php

remi源,這裡的php版本較新,5.4,5.5,5.6都有,還有配套的各種擴展

rpms.famillecollet.com

 

Centos 6.默認下沒有安裝php組件,因此我們需要輸入命令:yum -y install php 回車如下圖。

不用管,程序會自動完成安裝及配置。

Zend組件,Centos 6.3 裡面是沒有的,需要手動下載,及安裝教程請點擊下面鏈接:

到此前期的準備工作已完成,下面就要對Apache進行配置

輸入命令 pd/conf/httpd.conf //打開Apache配置文件,

找到ServerTokens OS 將“OS”改為“Prod “ 。//顯示服務器運行錯誤信息。與下圖一樣,那麼Apache你就配置成功了,如果不一樣請仔細對比上面的教程是不是那個步驟少了#及字母拼寫錯了。

到此php運行環境便配置成功啦。

 

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/227754.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-09 16:31
下一篇 2024-12-09 16:31

相關推薦

  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • Python腳本控制其他軟件

    Python作為一種簡單易學、功能強大的腳本語言,具有廣泛的應用領域,在自動化測試、Web開發、數據挖掘等領域都得到了廣泛的應用。其中,Python腳本控制其他軟件也是Python…

    編程 2025-04-29
  • 如何用Python寫愛心

    本文將會從多個方面闡述如何用Python語言來畫一個美麗的愛心圖案。 一、準備工作 在開始編寫程序之前,需要先理解一些編程基礎知識。首先是繪圖庫。Python有很多繪圖庫,常見的有…

    編程 2025-04-29
  • 如何用Python統計列表中各數據的方差和標準差

    本文將從多個方面闡述如何使用Python統計列表中各數據的方差和標準差, 並給出詳細的代碼示例。 一、什麼是方差和標準差 方差是衡量數據變異程度的統計指標,它是每個數據值和該數據值…

    編程 2025-04-29
  • 量化交易軟件哪個好?

    量化交易軟件是為量化交易而設計的工具,能夠用程序化方法對市場數據進行分析和交易決策。那麼,哪個量化交易軟件最好呢?下面從幾個方面進行詳細闡述。 一、交易功能 交易功能是量化交易軟件…

    編程 2025-04-29
  • PHP怎麼接幣

    想要在自己的網站或應用中接受比特幣等加密貨幣的支付,就需要對該加密貨幣擁有一定的了解,並使用對應的API進行開發。本文將從多個方面詳細闡述如何使用PHP接受加密貨幣的支付。 一、環…

    編程 2025-04-29
  • Python計算機二級刷題軟件推薦

    Python作為編程語言的代表,已經在計算機學習和開發領域佔據了重要角色。Python計算機二級是國家信息技術應用能力證書的一種,是計算機應用能力的重要評估標準。對於想要獲取Pyt…

    編程 2025-04-29
  • 電腦如何下載ps軟件

    如果您想在電腦上使用Photoshop,那麼您需要下載安裝該軟件。下面是詳細的步驟說明: 一、選擇下載網站 目前市面上有很多下載網站都可以下載到Photoshop軟件,比如Adob…

    編程 2025-04-29
  • 如何用Python打印溫度轉換速查表

    本文將從多個方面闡述如何用Python打印溫度轉換速查表,以便於快速進行溫度轉換計算。 一、Python打印溫度轉換速查表的基本知識 在計算機編程領域中,溫度轉換是一個重要的計算。…

    編程 2025-04-29
  • 如何用Python對數據進行離散化操作

    數據離散化是指將連續的數據轉化為離散的數據,一般是用於數據挖掘和數據分析中,可以幫助我們更好的理解數據,從而更好地進行決策和分析。Python作為一種高效的編程語言,在數據處理和分…

    編程 2025-04-29

發表回復

登錄後才能評論