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 #设置开机启动
更改nginx端口号(根据自己需求)
cd /etc/nginx/conf.d/
vim default.conf
把listen 80改成listen 81
3.访问http://ip:81即可看到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
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这中,记得如果是三方的,要先安装这些库才行哦。