導航:首頁 > 編程語言 > centos7yumphpfpm

centos7yumphpfpm

發布時間:2022-11-21 22:41:12

1. centos7 php7 安裝擴展phalcon 報錯

第一步:在網路中搜索Phalcon,一般第一個網站,進入網站,我們點擊網站首頁的download,目前該框架的最近版本是2.0

接著 我們找到我們的系統 這里我建議選用二進制的源碼編譯安裝!

然後 我們根據網站上的提示 下載該框架託管在github上面的二進制源碼,如圖所示,(使用git命令時需要安裝yum install git)

使用putty連接我們的linux系統 在linux系統/usr/local/src/下面輸入步驟三圖片上的命令 稍等片刻源碼就會下載下來

源碼下載完畢後會有一個cphalcon目錄 我們用命令行切換到/usr/local/src/cphalcon/build

用vi編輯器打開install文件 按照下圖配置 選擇php-config(php安裝位置各有不同)默認install 沒有選擇php-config的位置所有我們要自己動手

編輯完成 直接執行./install 動態編譯載入php擴展

編譯完成後打開php.ini文件添加phalcon的擴展 在php.ini中添加下圖的擴展即可

最後一步php探針驗證 !大工告成!

2. CentOS 7 用戶怎樣安裝 LNMP

安裝之前可以更新下ubuntu軟體源,要確保Linux處於聯網狀態
sudo vi /etc/apt/sources.list 輸入提供軟體的地址(裡面有默認的地址可以用,不可以的話網上到處都是這里就不貼出來了)保存退出
sudo apt-get update
可能會出現更新不了,這是看一下/etc/apt/apt.conf (這個貌似是設置HTTP代理的文件)。如果沒有設置代理,將裡面的東西刪除即可

開始安裝
1、安裝nginx,並啟動

sudo apt-get install nginx
sudo /etc/init.d/nginx start(或者 service nginx start)

2、安裝PHP和MySQL
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
更改資料庫用戶的許可權grant all on *.* to root@'%' identified by '123456';
刷新讓許可權生效flush privileges;
修改mysql的配置文件 sudo vi /etc/mysql/my.cnf
將bind-address = 127.0.0.1 注釋掉,就可以遠程連接資料庫了

3、安裝php5-fpm
sudo apt-get install php5-fpm

4、配置nginx並重啟服務
sudo vi /etc/nginx/sites-enabled,修改如下
server{
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
保存退出
5、啟動fastcgi php
sudo service php5-fpm start
6、重啟nginx服務
sudo service nginx restart

7、安裝PHP相關擴展
如 xdebug 、memcache、 oauth等

1)安裝curl:sudo apt-get install php5-curl
2)安裝gettext:sudo apt-get install php-gettext
3)安裝gd庫:sudo apt-get install php5-gd
4)安裝mcrypt:sudo apt-get install php5-mcrypt
5)安裝memcache
a)安裝伺服器 :
sudo apt-get install memcached
$ memcached -d -m 50 -p 11211 -u root
參數說明 -m 指定使用多少兆的緩存空間;-p 指定要監聽的埠; -u 指定以哪個用戶來運行
b)安裝php 模塊:

sudo apt-get install php5-memcache
6)安裝oauth:基於pecl的
a)sudo apt-get install php5-dev php-pear libpcre3-dev
sudo pecl install oauth (要確保有Linux系統里可以make)
b)修改配置文件
sudo vi /etc/php5/fpm/php.ini
在最後添加extension=oauth.so
7)安裝ssh2:sudo apt-get install libssh2-php
8)安裝xdebug:
sudo apt-get install php5-xdebug
修改php的配置文件 sudo vi /etc/php5/fpm/php.ini
將display_errors和html_errors都改為On
9)安裝完上述擴展後重啟PHP服務 :sudo service php5-fpm restart

至此整個環境就搭好了。

3. 用「yum」安裝「php-fpm」提示There are no enabled repos怎麼辦

Nginx 本身就不用介紹了,目前使用 FastCGI 是最流行的模式.現在不少網站使用.我來介紹一個簡單的安裝方法.
先要使用第三方的源,默認的源是不存在最新的 php 的,需要 php 5.3.3 以上才有 php-fpm,所以一定要安裝這些源..

配置最新 PHP 的源

如果是 CentOS 6 和 Red Hat (RHEL) 6 的 Remi 源

rpm-Uvhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
rpm-Uvhhttp://rpms.famillecollet.com/enterprise/remi-release-6.rpm

如果是 CentOS 5 和 Red Hat (RHEL) 5 的 Remi 源

rpm-Uvhhttp://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm-Uvhhttp://rpms.famillecollet.com/enterprise/remi-release-5.rpm

配置 Nginx 的源

我們需要建一個新的源文件,編輯 /etc/yum.repos.d/nginx.repo 就可以了.加入如下內容


[nginx]
name=nginxrepo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

安裝最新的 Nginx 和 PHP(php-fpm)

安裝最新的 Nginx 和 PHP .還有支持啟動 FastCGI 的 php-fpm 的功能.其它都是 PHP 的一些模塊了.

yum--enablerepo=remiinstallnginxphpphp-fpmphp-common
php-pearphp-pdophp-mysqlphp-pgsqlphp-pecl-memcachephp-gd
php-mbstringphp-mcryptphp-xml

安裝 MYSql 也需要使用這個的源才行


yum--enablerepo=remiinstallmysqlmysql-server

配置 Nginx 和 PHP-FPM

在 Nginx 加,給這些下面的注掉的內容打開,讓 php 的文件支持使用 fastcgi 來通信就行了.


location~.php${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/usr/share/nginx/html$fastcgi_script_name;
includefastcgi_params;
}

測試 Nginx 和 PHP-FPM

我們需要確認 fastcgi 是否能正常的使用,所以需要在,上面的 /usr/share/nginx/html 中加入 phpinfo.php 的測試文件.


<?php
phpinfo();
?>

這時只要打開 url 來測試這個 phpinfo.php 文件是否能正常的顯示就行了.

啟動和永久啟動 Nginx 和 PHP-FPM

我們一定不想下次 Nginx 和 PHP-FPM 在也啟動不了啦,所以我們需要加入啟動中去.讓系統啟動後就能自動啟動這些.

servicenginxstart
servicephp-fpmstart
chkconfig--addnginx
chkconfig--levels235nginxon
chkconfig--addphp-fpm
chkconfig--levels235php-fpmon

4. CentOS 7 用戶怎樣安裝 LNMP

1 先說一下
本文使用的主機名稱: server1.example.com 和IP地址: 192.168.1.105。這些可能與你的計算機有所不同,注意進行修改。
2 使用外部倉庫
Nginx不是從官方CentOS庫安裝,我們從 nginx 項目安裝庫安裝,修改源:
vi /etc/yum.repos.d/nginx.repo
修改為:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

3 安裝 MySQL
我們先安裝MariaDB。一個免費的MySQL 分支。運行此命令:
yum install mariadb mariadb-server net-tools
然後我們創建MySQL系統啟動鏈接(所以MySQL的自動啟動時,系統啟動)啟動MySQL伺服器:
systemctl enable mariadb.service
systemctl start mariadb.service
現在檢查網路啟用。運行
netstat -tap | grep mysql
它應該顯示出這樣的內容:
[root@example ~]# netstat -tap | grep mysql
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 10623/mysqld

運行
mysql_secure_installation
為用戶設置根口令(否則,任何人都可以訪問你的MySQL資料庫!):
[root@example ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we』ll need the current
password for the root user. If you』ve just installed MariaDB, and
you haven』t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] <– 回車
New password: <– 輸入ROOT密碼
Re-enter new password: <– 再輸入一次ROOT密碼
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
proction environment.
Remove anonymous users? [Y/n] <– 回車
… Success!
Normally, root should only be allowed to connect from 『localhost』. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <– 回車
… Success!
By default, MariaDB comes with a database named 『test』 that anyone can
access. This is also intended only for testing, and should be removed
before moving into a proction environment.
Remove test database and access to it? [Y/n] <– 回車
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 回車
… Success!
Cleaning up…
All done! If you』ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@example ~]#
[root@server1 ~]# mysql_secure_installation

4 安裝 Nginx
Nginx可以作為一個包從nginx.org安裝,運行:
yum install nginx
然後我們創建的系統啟動nginx的鏈接和啟動它:
systemctl enable nginx.service
systemctl start nginx.service
有時,你會得到一個錯誤,如80埠已在使用中,錯誤消息會是這樣的
[root@server1 ~]# service nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[FAILED]
[root@server1 ~]#
這就意味著有時在運行Apache服務。停止服務,進一步啟動服務nginx如下
systemctl stop httpd.service
yum remove httpd
systemctl disable httpd.service
systemctl enable nginx.service
systemctl start nginx.service
開放的HTTP和HTTPS防火牆中的埠
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload
輸出的shell結果將看起來像這樣:
[root@example ~]# firewall-cmd –permanent –zone=public –add-service=http
success
[root@example ~]# firewall-cmd –permanent –zone=public –add-service=https
success
[root@example ~]# firewall-cmd –reload
success
[root@example ~]#
在你的Web伺服器的IP地址或主機名稱輸入到瀏覽器(如HTTP:/ /192.168.1.105),你應該看到nginx的歡迎頁面。
5 安裝 PHP5
我們可以通過PHP-FPM使nginx的PHP5工作(PHP-FPM(FastCGI進程管理器)是一種替代PHP FastCGI執行一些額外的功能,支持任何規模大小,尤其是繁忙的站點很有用)。我們可以安裝php-fpmtogether用PHP-CLI和一些PHP5的模塊,如PHP,MySQL,你需要的,如果你想使用MySQL的PHP命令如下:
yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap
APC是一個自由和開放的PHP操作碼來緩存和優化PHP的中間代碼。它類似於其他PHP操作碼cachers,如eAccelerator和XCache。強烈建議有���些安裝,以加快您的PHP頁面。
我會從PHP PECL庫中安裝的APC。 PECL要求CentOS開發工具beinstalled編譯APC包。
yum install php-devel
yum groupinstall 『Development Tools』
安裝 APC
pecl install apc
[root@example ~]# pecl install apc
downloading APC-3.1.13.tgz …
Starting to download APC-3.1.13.tgz (171,591 bytes)
……………..done: 171,591 bytes
55 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Mole Api No: 20100525
Zend Extension Api No: 220100525
Enable internal debugging in APC [no] : <– 回車
Enable per request file info about files used from the APC cache [no] : <– 回車
Enable spin locks (EXPERIMENTAL) [no] : <– 回車
Enable memory protection (EXPERIMENTAL) [no] : <– 回車
Enable pthread mutexes (default) [no] : <–回車
Enable pthread read/write locks (EXPERIMENTAL) [yes] : <– 回車
building in /var/tmp/pear-build-rootVrjsuq/APC-3.1.13
……
然後打開 /etc/php.ini 並設置 cgi.fix_pathinfo=0:
vi /etc/php.ini
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

並添加行:
[...]
extension=apc.so

在 /etc/php.ini 文件後面。
除此之外,為了避免這樣的時區的錯誤:
[21-July-2014 10:07:08] PHP Warning: phpinfo(): It is not safe to rely on the system』s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 『Europe/Berlin』 for 『CEST/2.0/DST』 instead in /usr/share/nginx/html/info.php on line 2
… in /var/log/php-fpm/www-error.log 當你在瀏覽器中調用一個PHP腳本,你應該設置 date.timezone in /etc/php.ini:
[...]
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Europe/Berlin"
[...]

您可以通過運行正確的時區支持您的系統:
cat /etc/sysconfig/clock
[root@server1 nginx]# cat /etc/sysconfig/clock
ZONE=」Europe/Berlin」
[root@server1 nginx]#
接下來,創建系統啟動鏈接的PHP-FPM並啟動它:
systemctl enable php-fpm.service
systemctl start php-fpm.service
PHP-FPM是一個守護進程(使用init腳本/etc/init.d/php-fpm) 運行在埠9000的FastCGI伺服器。

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

首先更新系統軟體</str>
$ yum update
安裝nginx</str></str>
1.安裝nginx源
$ yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm2.安裝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 http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm2.安裝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 http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror2.解壓源碼包</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-proction /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/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf$ 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.查看訪問http://php7.thinkcmf.com

6. 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 http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

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

7. cent os7安裝PHP命令是什麼

phpize是屬於php-devel的內容,因此在centos中只要運行如下命令: yum install php-devel 然後就會安裝上phpize了。

8. CentOS 7 用戶怎樣安裝 LNMP

配置安裝
基於 YUM 特性,可以簡單快速的安裝 LNMP 環境。

配置 YUM 源
CentOS 7 的 默認 YUM 源里的軟體包版本可能不是最新的,如果要安裝最新的軟體包就得配置下 YUM 源。
配置 YUM 源可以通過直接安裝 RPM (Red Hat Package Manager) 包,或者修改 Repository,本文講解通過安裝 RPM 方式。
首先需要安裝 EPEL ( Extra Packages for Enterprise Linux ) YUM 源,用以解決部分依賴包不存在的問題:
yum install -y epel-release

接著是 MySQL YUM 源,MySQL 官網給出了配置教程,因為本文章講解的是 CentOS 7,我們只需要安裝對應的 RPM 包就行了。
安裝 RPM 包前需要導入 RPM-GPG-KEY 文件,不然安裝過程會出錯。
將 MySQL RPM-GPG-KEY 另存為 mysql_pubkey.asc 並導入 :
rpm --import mysql_pubkey.asc

導入後安裝 CentOS 7 的 MySQL RPM 包:
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

然後是 PHP YUM 源,PHP 最新的 RPM 包,可以使用 Remi's RPM repository。
導入 PHP RPM-GPG-KEY (remi):
rpm --import http://rpms.remirepo.net/RPM-GPG-KEY-remi

安裝 PHP RPM (remi) 包:
rpm -Uvh http://remi.mirrors.arminco.com/enterprise/remi-release-7.rpm

最後是 Nginx YUM 源,Nginx 官網也給出了配置教程。
導入 Nginx RPM-GPG-KEY:
rpm --import http://nginx.org/packages/keys/nginx_signing.key

安裝 Nginx RPM 包:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

到目前為止,YUM 源已經安裝好了 ,接著進行下一步的配置。
MySQL YUM 源默認是啟用的 MySQL-5.6,PHP YUM 源默認都沒有啟用,Nginx YUM 源默認是啟用的 Nginx-1.8。
定位到 /etc/yum.repos.d/,對 後綴為 .repo 的文件進行編輯,修改 enabled 為 1 以啟用。
啟用 PHP-7.0 :
1、修改 /etc/yum.repos.d/remi.repo,將 [remi] 和 [remi-test] 下面的 enabled=0 改為 enabled=1;
2、修改 /etc/yum.repos.d/remi-php70.repo,將 [remi-php70] 下面的 enabled=0 改為 enabled=1;
sed -i "/remi\/mirror/{n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi.repo
sed -i "/test\/mirror/{n;n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi.repo
sed -i "/php70\/mirror/{n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi-php70.repo

到這一步 YUM 配置就算完成了,清除並生成 YUM 緩存使之生效:
yum clean all
yum makecache

安裝 MySQL + PHP + Nginx + phpMyAdmin
YUM 源已經配置好了,現在直接安裝 MySQL + PHP + Nginx + phpMyAdmin:
yum install -y mysql-community-server nginx php php-bcmath php-fpm php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pdo_dblib php-pgsql php-recode php-snmp php-soap php-xml php-pecl-zip phpMyAdmin

註:上面安裝的 php-* 可以根據實際使用情況選擇安裝
安裝完成後,進行下一步的環境配置,MySQL 配置文件在 /etc/my.cnf.d/,PHP 配置文件在 /etc/php-fpm.d/,Nginx 配置文件在 /etc/nginx/ ,phpMyAdmin 的配置文件在 /etc/phpMyAdmin/。

配置 MySQL
MySQL 配置文件保持默認,運行一次安全配置即可。
啟動 MySQL:
systemctl start mysqld.service

安全配置 MySQL:
設置 root 密碼、刪除匿名用戶、禁止 root 遠程登錄、刪除 test 資料庫、重新載入許可權表,一路 Y 下去
mysql_secure_installation

配置 PHP
PHP 默認配置文件使用的是監聽 9000 埠進行通信,針對小型單一、沒有做負債均衡的伺服器,可以使用 unix sock 方式通信。
使用 unix sock 方式需要修改 PHP 配置文件:
#更換監聽方式
listen = /dev/shm/php-fpm-default.sock

#監聽隊列最大長度為不限
listen.backlog = -1
#指定監聽用戶和用戶組(需存在)
listen.owner = www
listen.group = www

啟動 PHP-FPM:
systemctl start php-fpm.service

配置 Nginx
讓伺服器默認訪問顯示為 400 提示頁。
#新建名為 nginx-default.conf 的配置文件
touch /etc/nginx/conf.d/nginx-default.conf
#編輯配置文件
vi /etc/nginx/conf.d/nginx-default.conf

將以下信息輸入到 nginx-default.conf
server
{
listen 80 default;
return 400;
}

按下 Esc,輸入 :x 保存並退出。
防火牆放行 HTTP 埠訪問:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload

啟動 Nginx:
systemctl start nginx.service

這時,在瀏覽器地址欄輸入當前伺服器 IP 就會看到一個 400 的提示頁面了。
進階!綁定域名+站點目錄+保存日誌+運行 PHP的配置文件:
server
{
listen 80; #監聽80埠
server_name default.com www.default.com; #綁定域名 default.com 和 www.default.com
index index.html index.htm index.php; #設置首頁文件,越前優先順序越高
charset utf-8; #設置網頁編碼

root /home/wwwroot/default; #設置站點根目錄

#運行 PHP
location ~ .*\.php$
{
fastcgi_pass 127.0.0.1:9000 #默認使用9000埠和PHP通信
#fastcgi_pass unix:/dev/shm/php-fpm-default.sock; #使用 unix sock 和PHP通信
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /home/wwwroot/default; #PHP 文檔根目錄
fastcgi_param SCRIPT_FILENAME /home/wwwroot/default$fastcgi_script_name; #PHP 腳本目錄
include fastcgi_params;
try_files $uri = 404;
}

#設置文件過期時間
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
{
expires 30d;
}

#設置文件過期時間
location ~ .*\.(js|css)$
{
expires 12h;
}

#設置文件訪問許可權
location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ {
allow 127.0.0.1;
deny all;
}

#設置文件訪問許可權
location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ {
deny all;
}

#保存日誌
access_log /var/log/nginx/default-access.log main;
error_log /var/log/nginx/default-error.log crit;
}

配置 phpMyAdmin
# 編輯配置文件
vi etc/phpMyAdmin/config.inc.php

修改以下內容:
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['UploadDir'] = '/tmp';
$cfg['SaveDir'] = '/tmp';

如果Nginx使用的是上面的進階代碼,那麼把 phpMyAdmin 的目錄 復制到 /home/wwwroot/default/phpMyAdmin/ 下面,就可通過 http://default.com/phpMyAdmin 訪問了:
#復制 phpMyAdmin 目錄
cp -a /usr/share/phpMyAdmin /home/wwwroot/default/

#替換連接形式為目錄
rm -rf /home/wwwroot/default/phpMyAdmin/doc/html
cp -a /usr/share/doc/phpMyAdmin-<span class="pl-k">*</span>/html /home/wwwroot/default/phpMyAdmin/doc/

一鍵腳本
上面已經講解了如何配置和安裝,但是不能每次都這么一步一步來吧?為了節省時間,麥蔥寫了一個一鍵安裝管理腳本,可選擇安裝 Nginx 1.8/1.9、 MySQL 5.5/5.6/5.7 和 PHP 5.5/5.6/7.0。
安裝
yum install -y unzip

wget https://github.com/maicong/LNMP/archive/master.zip

unzip master.zip

cd LNMP-master

bash lnmp.sh

# 輸出到指定文件
# bash lnmp.sh 2>&1 | tee lnmp.log

管理站點
service vhost (start,stop,list,add,edit,del,exit) <domain> <server_name> <index_name> <rewrite_file> <host_subdirectory>

start 啟動
stop 停止
list 列出
add 添加
edit 編輯
del 刪除
exit 什麼都不做
<domain>: 配置名稱,例如:domain
<server_name>: 域名列表,例如:domain.com,www.domain.com
<index_name>: 首頁文件,例如:index.html,index.htm,index.php
<rewrite_file>: 偽靜態規則文件,保存在 /etc/nginx/rewrite/ 例如:nomal.conf
<host_subdirectory>: 是否支持子目錄綁定,on 或者 off
示例:
#添加一個標識為 domain 的站點
service vhost add domain domain.com,www.domain.com index.html,index.htm,index.php nomal.conf on

#啟動標識為 domain 的站點
service vhost start domain

#停止標識為 domain 的站點
service vhost stop domain

#編輯標識為 domain 的站點
service vhost edit domain

#刪除標識為 domain 的站點
service vhost del domain

#列出所有站點
service vhost list

備份數據
service vbackup (start,list,del) <delete name.tar.gz>

start 添加
list 列出
del 刪除
示例:
#添加一個新的備份
service vbackup start

#列出備份文件
service vbackup list

#刪除一個備份
service vbackup del name.tar.gz

9. 怎麼安裝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';

六.測試環境

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

七.安裝nginx

yum install yum-priorities -y

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

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

yum install nginx

Nginx 版本號可變更http://nginx.org/packages/centos/7/noarch/RPMS/$版本

八.配置nginx

1.nginx啟動,停止,重啟

systemctl start nginx.service #啟動nginx

systemctl stop nginx.service #停止

systemctl restart nginx.service #重啟

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

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

訪問http://ip:81/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 http://site;

}

apache 默認目錄 /var/www/html

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

升級php版本

centos7 默認安裝php是5.4

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

yum provides php

開始升級PHP更新源:

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

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

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

https://blog.csdn.net/mao834099514/article/details/73470001

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 www.nine.com

DocumentRoot "/var/www/html/learnlaravel/public"

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

關閉防火牆

setenforce 0

10. pandorabox,在centos7 下編譯出錯,運行make V=s後有如下提示,應該怎麼解決

最近試了一下PHP7,在編譯和支持MySQL上都遇到一些問題,相信不少同學也同樣遇到,所以在這里聊一下這個過程。簡單來講編譯PHP7隻需要3步:

1、./buildconf --force
2、./configure
3、make && make install

1、3步,都沒啥好管的,configure是編譯的關鍵,涉及到PHP對一些庫的支持,這里我們使用最小的支持,包括MySQL:

curl
gd
fpm
mysqlnd

之所以把curl和gd拿來說,目的是要搞清楚,這些三方庫在編譯PHP之前得安裝好,可以直接使用yum安裝在默認位置,也可以編譯安裝到指定位置,yum安裝後,編譯時不用指定庫的安裝位置,關於安裝這些庫,可以搜索一下有很多。下面看看基本的configure

./configure --prefix=/apps/php/php7.0 --enable-mbstring --with-curl --with-gd --with-config-file-path=/apps/php/php7.0/etc/ --
enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd
PHP-FPM

關於fpm,相信不用多說,用它來支持PHP是一個比較好的選擇,PHP5.3.3開始就已經內置了php-fpm,所以PHP7里當然也有,只需要--enable-fpm一下就可以了

php-fpm參數:

--start 啟動
--stop 強制終止
--quit 平滑終止
--restart 重啟
--reload 重新平滑載入php的php.ini
--logrotate 重新啟用log文件

MySQL支持

重點講一下這個,因為在它上面花了一點時間,不知道從哪一版本開始,PHP不在希望使用mysql的庫來支持mysql的連接,啟用了mysqlnd來支持,聽說比libmysql要快很多,PHP5.x還可以使用libmysql,PHP7貌似已經取消了支持,編譯都沒有了--with-mysql參數,只支持--with-mysqli和--with-pdo-mysql,可以通過查看configure的參數來知道:

?

1

./configure -help | grep mysql

可以看到,PHP希望使用mysqlnd來支持MySQL,所以參數可以這樣寫:

--enable-mysqlnd
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd

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的位置:

?

1

--with-mysql-sock=/var/lib/mysql/mysql.sock

如果還不行,可以到/tmp目錄下建立一個mysql.sock的軟鏈接:

?

1

ln -s /var/lib/mysql/mysql.sock mysql.sock

再重啟一次php-fpm,相信已經正常運行了。如果需要PHP支持的庫更多,可以再次編譯,在configure時把需要的支持加上,就是--with-xxx這中,記得如果是三方的,要先安裝這些庫才行哦。

閱讀全文

與centos7yumphpfpm相關的資料

熱點內容
中國移動長沙dns伺服器地址 瀏覽:249
wifi密碼加密了怎麼破解嗎 瀏覽:596
linux命令cpu使用率 瀏覽:67
linux實用命令 瀏覽:238
傳奇引擎修改在線時間命令 瀏覽:109
php取域名中間 瀏覽:897
cad命令欄太小 瀏覽:830
php開發環境搭建eclipse 瀏覽:480
qt文件夾名稱大全 瀏覽:212
金山雲伺服器架構 瀏覽:230
安卓系統筆記本怎麼切換系統 瀏覽:618
u盤加密快2個小時還沒有搞完 瀏覽:93
小米有品商家版app叫什麼 瀏覽:94
行命令調用 瀏覽:436
菜鳥裹裹員用什麼app 瀏覽:273
窮查理寶典pdf下載 瀏覽:514
csgo您已被禁用此伺服器怎麼辦 瀏覽:398
打開加密軟體的方法 瀏覽:156
雲存儲伺服器可靠嗎 瀏覽:968
2核1g的雲伺服器能帶動游戲嘛 瀏覽:900