CentOS6 下 Yum 安装 LNMP PHP5.6及其扩展

先说下我的实践配置,centos6.9(64位),联网安装前准备:关闭防火墙 service iptables stop

安装MySQL(数据服务器)

打开终端,root用户

yum install mysql mysql-server

安装完毕,设置MySQL自启动

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start //或者service mysqld start

设置MySQL root账户的密码(我没有新建MySQL用户,就用root账户了),输入以下

mysql_secure_installation

出现以下提示时

Enter current paaword for root

因为我们root密码为空,所以直接回车

之后按照提示,输入新密码,确认,最后会有四个确认,直接回车就行

安装Apache(应用服务器)

yum install httpd

配置自启动

chkconfig --levels 235 httpd on
service httpd start

此时启动可能会出现以下错误

正在启动httpd:httpd:could not reliably determine the server’s fully qualif domain name,using 127.0.0.1 for servername

解决方法:

vim /etc/httpd/conf/httpd.conf

进入vi修改状态,找到#ServerName www.example.com:80

取消#,并修改为ServerName 域名:80(如果没有域名的话,就设为localhost)

wq!保存退出

service httpd restart

重启httpd,此时你就可以访问你的服务器了,输入localhost,出现一个Apache test page powered by centos的测试页面。

安装PHP(应用服务器)

同样输入命令

yum install php

直接一路安装,安装完成之后我们需要再次重启httpd服务

service httpd restart

重启之后我们进行测试PHP相关信息,我们新建一个PHP界面进行测试

vi /var/www/html/index.php

按  i   进行编辑,输入:

<?php

phpinfo();

?>

编辑完毕,保存退出

此时我们访问这个页面,输入localhost,就会出现一个现实PHP信息的网页,说明你的PHP安装成功了。

升级PHP到5.6

输入 php -v 显示 PHP 5.3.3,如需升级到5.6,方法如下:

yum update
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install yum-plugin-replace
yum replace php-common --replace-with=php56w-common

再次输入 php -v,显示 PHP 5.6.30,说明升级成功了。

安装PHP常用扩展

yum install php56w-devel php56w-fpm php56w-gd php56w-intl php56w-mbstring php56w-mcrypt php56w-mysql php56w-pdo php56w-pear php56w-pecl-imagick php56w-pecl-imagick-deve php56w-pecl-memcache php56w-pecl-memcached php56w-xml php56w-bcmath php56w-pecl-redis
service httpd restart

PHP.INI 配置中心

vi /etc/php.ini

  1. max_execution_time = 300:Maximum execution time of each script, in seconds
  2. max_input_time = 60:Maximum amount of time each script may spend parsing request data
  3. memory_limit = 1024M:Maximum amount of memory a script may consume
  4. error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT:This directive informs PHP of which errors, warnings and notices you would like it to take action for
  5. display_errors = Off:This directive controls whether or not and where PHP will output errors,notices and warnings too
  6. post_max_size = 60M:Maximum size of POST data that PHP will accept
  7. upload_max_filesize = 60M:Maximum allowed size for uploaded files
  8. max_file_uploads = 60:Maximum number of files that can be uploaded via a single request
  9. default_socket_timeout = 60:Default timeout for socket based streams (seconds)
  10. date.timezone = PRC:Defines the default timezone used by the date functions

service httpd restart

安装memcached

memcached -h
yum install memcached
memcached -d -p 11211 -u memcached -m 1024 -c 1024 -P /var/run/memcached/memcached.pid -l 10.141.104.150

安装Ngnix

ps -ef | grep nginx
yum install nginx
chkconfig nginx on

CentOS使用常见问题

linux下vim中文乱码的解决方法

编辑~/.vimrc文件,加上如下几行:

set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set tabstop=4

linux下增加快捷键方法

编辑~/.bash_profile文件,加上如下几行:

# 快捷键 alias ll=’ls -lh’ alias la=’ls -alh’

然后执行source ~/.bash_profile使其生效

即可搞定。

 

Ths:

1、http://www.cnblogs.com/IEBD/p/4563840.html

2、https://webtatic.com/packages/php56/