centos7重啟phpfpm,Centos7重啟防火牆

本文目錄一覽:

怎麼安裝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

linux centos7 怎麼重啟php-fpm

/etc/init.d/php-fpm start

/etc/init.d/php-fpm stop

/etc/init.d/php-fpm restart

/etc/init.d/php-fpm reload

apache

啟動

systemctl start httpd

停止

systemctl stop httpd

重啟

systemctl restart httpdmysql啟動

systemctl start mysqld停止

systemctl stop mysqld

重啟

systemctl restart mysqld

php-fpm

啟動

systemctl start php-fpm

停止

systemctl stop php-fpm

重啟

systemctl restart php-fpmnginx

啟動

systemctl start nginx

停止

systemctl stop nginx

重啟

systemctl restart nginx

阿里雲默認centos7上怎麼安裝php

首先更新系統軟體/str

$ yum update

安裝nginx/str/str

1.安裝nginx源

$ yum localinstall .安裝nginx

$ yum install nginx

3.啟動nginx

$ service nginx start

Redirecting to /bin/systemctl start nginx.service4.訪問http://你的ip/

如果成功安裝會出來nginx默認的歡迎界面

安裝MySQL5.7.*

/str

1.安裝mysql源/str

$ yum localinstall .安裝mysql

$ yum install mysql-community-server

確認一下mysql的版本,有時可能會提示mysql5.63.安裝mysql的開發包,以後會有用

$ yum install mysql-community-devel

4.啟動mysql

$ service mysqld start

Redirecting to /bin/systemctl start mysqld.service5.查看mysql啟動狀態

$ service mysqld status

出現pid

證明啟動成功

6.獲取mysql默認生成的密碼

$ grep ‘temporary password’ /var/log/mysqld.log2015-12-05T05:41:09.104758Z 1 [Note] A temporary password is generated for root@localhost: %G1Rgns!dD!v/str

加粗的就是生成的密碼

7.換成自己的密碼

$ mysql -uroot -p

Enter password:輸入上面的密碼

成功輸入後進入一下步,這裡你估計會輸入 好幾次才進去8. 更換密碼

mysql ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass4!’;這個密碼一定要足夠複雜,不然會不讓你改,提示密碼不合法;9.退出mysql;

mysql quit;

10.用新密碼再登錄,試一下新密碼

$ mysql -uroot -p

Enter password:輸入你的新密碼

11.確認密碼正確後,退出mysql;

mysql quit;

編譯安裝php7.0.0

/str

/str

1.下載php7源碼包/str

$ cd /root wget -O php7.tar.gz .解壓源碼包/str

$ tar -xvf php7.tar.gz

3./str

$ cd php-7.0.1

4.安裝php依賴包/str

/str

$ yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel5.編譯配置,這一步我們會遇到很多configure error,我們一一解決,基本都是相關軟體開發包沒有安裝導致/str

/str

$ ./configure \

–prefix=/usr/local/php \

–with-config-file-path=/etc \

–enable-fpm \

–with-fpm-user=nginx \

–with-fpm-group=nginx \

–enable-inline-optimization \

–disable-debug \

–disable-rpath \

–enable-shared \

–enable-soap \

–with-libxml-dir \

–with-xmlrpc \

–with-openssl \

–with-mcrypt \

–with-mhash \

–with-pcre-regex \

–with-sqlite3 \

–with-zlib \

–enable-bcmath \

–with-iconv \

–with-bz2 \

–enable-calendar \

–with-curl \

–with-cdb \

–enable-dom \

–enable-exif \

–enable-fileinfo \

–enable-filter \

–with-pcre-dir \

–enable-ftp \

–with-gd \

–with-openssl-dir \

–with-jpeg-dir \

–with-png-dir \

–with-zlib-dir \

–with-freetype-dir \

–enable-gd-native-ttf \

–enable-gd-jis-conv \

–with-gettext \

–with-gmp \

–with-mhash \

–enable-json \

–enable-mbstring \

–enable-mbregex \

–enable-mbregex-backtrack \

–with-libmbfl \

–with-onig \

–enable-pdo \

–with-mysqli=mysqlnd \

–with-pdo-mysql=mysqlnd \

–with-zlib-dir \

–with-pdo-sqlite \

–with-readline \

–enable-session \

–enable-shmop \

–enable-simplexml \

–enable-sockets \

–enable-sysvmsg \

–enable-sysvsem \

–enable-sysvshm \

–enable-wddx \

–with-libxml-dir \

–with-xsl \

–enable-zip \

–enable-mysqlnd-compression-support \

–with-pear \

–enable-opcache

configure error:

1.configure: error: xml2-config not found. Please check your libxml2 installation.

解決:

$ yum install libxml2 libxml2-devel

2.configure: error: Cannot find OpenSSL’s evp.h

解決:

$ yum install openssl openssl-devel

3.configure: error: Please reinstall the BZip2 distribution解決:

$ yum install bzip2 bzip2-devel

4.configure: error: Please reinstall the libcurl distribution – easy.h should be in curl-dir/include/curl/解決:

$ yum install libcurl libcurl-devel

5.If configure fails try –with-webp-dir=DIR configure: error: jpeglib.h not found.

解決:

$ yum install libjpeg libjpeg-devel

6.If configure fails try –with-webp-dir=DIR

checking for jpeg_read_header in -ljpeg… yesconfigure: error: png.h not found.

解決:

$ yum install libpng libpng-devel

7.If configure fails try –with-webp-dir=DIR

checking for jpeg_read_header in -ljpeg… yeschecking for png_write_image in -lpng… yesIf configure fails try –with-xpm-dir=DIR

configure: error: freetype-config not found.

解決:

$ yum install freetype freetype-devel

8.configure: error: Unable to locate gmp.h解決:

$ yum install gmp gmp-devel

9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解決:

$ yum install libmcrypt libmcrypt-devel

10.configure: error: Please reinstall readline – I cannot find readline.h解決:

$ yum install readline readline-devel

11.configure: error: xslt-config not found. Please reinstall the libxslt = 1.1.0 distribution解決:

$ yum install libxslt libxslt-devel

6.編譯與安裝

$ make make install

這裡要make好久,要耐心一下

7.添加 PHP 命令到環境變數

$ vim /etc/profile

在末尾加入

PATH=$PATH:/usr/local/php/bin

export PATH

要使改動立即生效執行

$ ./etc/profile

$ source /etc/profile

查看環境變數

$ echo $PATH

查看php版本

$ php -v

8.配置php-fpm

$ cp php.ini-production /etc/php.ini

$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf$ cp /usr/local/php/etc/php-fpm.d/ /usr/local/php/etc/php-fpm.d/ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm$ chmod +x /etc/init.d/php-fpm

9.啟動php-fpm

$ /etc/init.d/php-fpm start

配置nginx虛擬機,綁定域名/str

1.

/str

$ vim /etc/nginx/conf.d/php7.thinkcmf.com.conf這裡可以把php7.thinkcmf.com.conf改成自己的域名把下面的內容複製到php7.thinkcmf.com.conf里server{

listen 80;

server_name php7.thinkcmf.com;

root /var/www/html/php7.thinkcmf.com; # 該項要修改為你準備存放相關網頁的路徑location / {

index index.php index.html index.htm;

#如果請求既不是一個文件,也不是一個目錄,則執行一下重寫規則if (!-e $request_filename)

{

#地址作為將參數rewrite到index.php上。

rewrite ^/(.*)$ /index.php/$1;

#若是子目錄則使用下面這句,將subdir改成目錄名稱即可。

#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;}

}

#proxy the php scripts to php-fpm

location ~ \.php {

include fastcgi_params;

##pathinfo支持start

#定義變數 $path_info ,用於存放pathinfo信息set $path_info “”;

#定義變數 $real_script_name,用於存放真實地址set $real_script_name $fastcgi_script_name;#如果地址與引號內的正則表達式匹配

if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {#將文件地址賦值給變數 $real_script_name

set $real_script_name $1;

#將文件地址後的參數賦值給變數 $path_info

set $path_info $2;

}

#配置fastcgi的一些參數

fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;fastcgi_param SCRIPT_NAME $real_script_name;fastcgi_param PATH_INFO $path_info;

###pathinfo支持end

fastcgi_intercept_errors on;

fastcgi_pass 127.0.0.1:9000;

}

}

2.重啟nginx

$ service nginx reload

3.

$ vim /var/www/html/php7.thinkcmf.com/index.php/str

把下面的代碼複製到這個文件 里

?php

phpinfo();

4.查看訪問

centos7怎麼用service命令啟動服務?

service 服務名 start 不過,後面centos7 ,改成用systemctl了

在 centos7 版本中的 各項服務啟動命令:

服務管理命令

1、Apache 服務管理命令啟動:

systemctl start httpd關閉:

systemctl stop httpd重啟:

systemctl restart httpd狀態:

systemctl status httpd

2、PHP 服務管理命令啟動:

/usr/sbin/php-fpm關閉:

pkill php-fpm

3、MySQL 服務管理命令啟動:

systemctl start mysqld關閉:

systemctl stop mysqld重啟:

systemctl restart mysqld狀態:

systemctl status mysqld

4、FTP 服務管理命令啟動:

systemctl start vsftpd關閉:

systemctl stop vsftpd重啟:

systemctl restart vsftpd狀態:

systemctl status vsftpd

linux centos 7 下用yum 安裝iso鏡像里自帶的php5.4.16版本的但是沒有php-fqm文件不知道怎麼重啟php服務

systemctl restart php-fpm.service #這條命令是重啟php服務

下面是一個比較靠譜的php安裝步驟:

先刪除已有的php版本 ,執行下面的命令刪除php

yum remove php-common

然後像安裝那樣問你是否繼續的,輸入yes即可

添加 yum 源

CentOS 6.x 的源

# rpm -Uvh

# rpm -Uvh

安裝 PHP

# yum install –enablerepo=remi,remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common

註:安裝5.6版本為remi-php56,安裝5.5版本為remi-php55

為什麼centos7下nginx的php怎麼開啟報錯

首先要編輯php配置文件:

vi /etc/php.ini

error_reporting = E_ERROR

display_errors = On

因為我開啟了php-fpm。所以,還要編輯 php-fpm.conf文件,把php_flag[display_errors]設為on:

vi php-fpm.conf

php_flag[display_errors] = on

這樣在開發的時候就可以在瀏覽器中顯示php出現的錯誤了,非常方便。

原創文章,作者:BWDMK,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/330670.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
BWDMK的頭像BWDMK
上一篇 2025-01-16 15:46
下一篇 2025-01-16 15:46

相關推薦

  • Linux Redis 重啟

    一、概述 Redis 是一款高性能的 NoSQL 資料庫,常用於各種應用場景的數據緩存、消息隊列、實時數據分析等等。在使用 Redis 過程中,如果出現了某些問題,有時候只需要重啟…

    編程 2025-04-25
  • Linux防火牆配置詳解

    一、iptables基本介紹 iptables是一個重要的Linux內核中網路安全系統,通過設置iptables規則,可以對進入和離開Linux伺服器的數據進行過濾。 iptabl…

    編程 2025-04-25
  • 如何查看防火牆開放的埠

    一、使用命令行查看開放埠 在Windows系統中,我們可以使用命令行工具來查看防火牆開放的埠。 netstat -an | find /i 「listening」 運行以上命令…

    編程 2025-04-25
  • CentOS7重啟MySQL教程

    在Linux系統中,由於各種原因,需要重啟MySQL時是一個很常見的操作。本文將從多個方面對CentOS7重啟MySQL的方法進行詳細介紹,包括重啟網路服務、命令、系統、Nginx…

    編程 2025-04-24
  • Linux重啟Tomcat服務命令

    一、查看Tomcat狀態 在重啟Tomcat服務之前,我們需要先確認Tomcat的運行狀態。可以通過以下命令來查看: systemctl status tomcat 如果Tomca…

    編程 2025-04-24
  • 重啟nginx服務的命令詳解

    nginx是一個高性能的Web伺服器,可通過重新啟動nginx服務來更新配置文件和釋放資源。本文將從多個方面詳細闡述如何重啟nginx服務,包括命令的使用、參數的說明等。 一、ng…

    編程 2025-04-24
  • 重啟MySQL的方法及注意事項

    一、檢查MySQL狀態 在重啟MySQL之前,我們需要先檢查MySQL的狀態,確定MySQL是否正在運行。可以通過以下命令來檢查: systemctl status mysql.s…

    編程 2025-04-23
  • 從多個方面詳解Apache重啟

    一、Apache重啟命令 Apache作為一個Web伺服器,經常需要進行重啟,以確保伺服器的穩定性和性能優化。在Linux系統中,通過使用命令行可以輕鬆重啟Apache。以下是Ap…

    編程 2025-04-23
  • 華為防火牆配置詳解

    華為防火牆是一款功能強大的網路安全產品,除了基本的防火牆功能外,還提供了許多高級的安全策略配置。本文將從多個方面對華為防火牆配置進行詳細闡述,幫助讀者更好地掌握該產品。 一、基本配…

    編程 2025-04-22
  • Linux下查看防火牆規則

    一、iptables是什麼? 在Linux系統中,如果想要查看防火牆規則,則需要使用iptables命令,它是一個在Linux內核中提供的防火牆軟體,可用於配置和管理netfilt…

    編程 2025-04-22

發表回復

登錄後才能評論