当我沿用这个标题的时候,内心在想“我能说我以前用的windows吗?",windows下xampp,wamp一键配置啊,有木有!我刚开始的时候就很傻很天真的在刚买的阿里云服务器安装了window Server 2008,着手部署xampp,两个小时把解析环境所有配置好了,内心各类吐槽什么服务器难搞定,在本大(diao)神(si)眼里全是渣!内心各类喜悦啊,开始乐呵乐呵的测试公司的网站(根本没问题啊),而后我就没多想了(果真仍是太年轻),以后的几天开始沉浸在项目开发中没法自拔,就没去折腾服务器了。php
因为项目接近尾声,开始试上线,我就把本地程序上传到了服务器(因为服务器是windows环境,桌面远程链接(我真是忍不住要吐槽)在mac实在是难用),因为没有配置好windows下远程FTP链接,而后就悲剧的共享磁盘驱动来更新程序(谁用谁知道),各类慢就不说了,还老是丢失。可是这些都没有让我产生放弃windows怀抱的想法。css
由于项目先后台都是我本身弄的,前端用的h5+js,免不了各类ajax调用数据接口,而后悲剧就此产生~ windows的apache 2会三五分钟就嗝屁,客户后台老是登不进去,基本就是一会一个电话,我内心想仍是换linux系统,就此开始了我3 * 24小时的CentOs+nginx+php+mysql+phpmyadmin+phalcon折腾之旅(听说nginx是7*24小时不重启的小金刚)。html
由于最开始我是部署的unbun12.04的系统,在开始以前仍是有思考过要用ubuntu仍是用centos呢?最后,我仍是选择了centos,缘由是由于我以为名字感受大气一点(任性一把)。前端
由于PHP-FPM 在 CentOS 的官方程序库中不存在,因此咱们首先得添加第三方扩展软件源,运行如下命令:mysql
rpm --import https://fedoraproject.org/static/0608B895.txt rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel- release-6-8.noarch.rpm rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi rpm -ivh http://rpms.famillecollet.com/enterprise/remi- release-6.rpm yum install yum-priorities
而后,编辑:vi /etc/yum.repos.d/epel.repo:linux
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch baseurl=http://mirrors.aliyun.com/epel/6/$basearch http://mirrors.aliyuncs.com/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 priority=10 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
接着:vi /etc/yum.repos.d/remi.repo:nginx
[remi] name=Les RPM de remi pour Enterprise Linux 6 - $basearch baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror enabled=1 priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
下面咱们就能够安装所须要的包文件了:git
yum install mysql mysql-server
-安装Nginxgithub
yum install nginx
yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy php-pecl-apc
启动MySQLweb
chkconfig --levels 235 mysqld on service mysqld start
启动Nginx
chkconfig --levels 235 nginx on service nginx start
启动PHP-FPM
chkconfig --levels 235 php-fpm on service php-fpm start
若 Nginx 启动失败,则有多是由于 Apache httpd 服务占用了该接口,这时,要么咱们修改 Nginx 的坚挺端口,要么修改Apache httpd的或者直接删除 Apache httpd。
apachectl stop yum remove httpd chkconfig --level 235 httpd off
运行 mysql_secure_installation 命令,由于咱们是首次安装因此直接回车,而后进入设置新密码
[...]
; 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 [...]
设置 upload_max_filesize 最大文件上传尺寸为 upload_max_filesize 为 16MB:
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 16M
设置 post_max_size 为 32MB:
; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 32M
打开:vi /etc/php-fpm.d/www.conf :
;listen = 127.0.0.1:9000 listen = /var/run/php-fpm.sock;
以及:
listen.owner = www listen.group = www listen.mode = 0660 ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache Choosed to be able to access some dir as httpd user = www ; RPM: Keep a group allowed to write in log dir. group = www
-因为以前就已经解析好了域名,因此我只须要配置一下nginx虚拟主机
静态解析
静态解析按照nginx提供的virtual.conf里面提供的例子解析便可
listen 80;
server_name somename alias another.alias;
location / {
root html;
index index.html index.htm;
}
}
动态解析,由于nginx自己不能解析php,因此它会把php转发到9000端口,提交给php-fpm去解析,这里我贴出个人配置文件
server { listen 80; server_name yourservername.com(须要解析的域名); index index.html index.htm index.php; set $root_path yourpath(项目入口文件位置); root $root_path; try_files $uri $uri/ @rewrite; location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index /index.php; include /etc/nginx/fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name; } location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { root $root_path; } location ~ /\.ht { deny all; } }
-这里有一个地方须要注意,若是你在重启nginx的时候,出现没法识别$document_root,你须要将你的 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;里面的$document_root换成你项目入口文件位置,我就在这个地方纠结了很久,弄半天才整出来,这个解析规则基本能知足大部分php项目解析。
进入phpmyadmin首页(http://www.phpmyadmin.net/home_page/index.php),打开download,下载最新的phpmyadmin(多国语言(all-languages))的版本,下载完成以后,打包用ftp工具上传到服务器,地址的话建议放home目录下新建phpmyadmin文件夹下。
配置一个虚拟主机解析到phpmyadmin根目录下,仍是沿用上方动态解析规则便可。
最后我根据session的配置文件,找到phpmyadmin/ libraries/session.inc.php ,修改一下代码:
if (! isset($_COOKIE[$session_name])) { // on first start of session we check for errors // f.e. session dir cannot be accessed - session file not created $orig_error_count = $GLOBALS['error_handler']->countErrors(); //session_save_path('./tmp'); session_save_path("/tmp"); $r = session_start(); if ($r !== true || $orig_error_count != $GLOBALS['error_handler']->countErrors() ) { setcookie($session_name, '', 1); /* * Session initialization is done before selecting language, so we * can not use translations here. */ PMA_fatalError('Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.'); } unset($orig_error_count); } else { session_save_path("/tmp"); session_start(); }
至此,打开虚拟主机域名就能够正常访问phpmyadmin了!
phalcon是一款由c语言直接编写的php框架,以灵活性(低耦合),可拓展性强,高性能闻名,也是以组建注册,工厂服务形式存在的php框架。
由于咱们的系统是Centos,因此根据官方给咱们的案例(http://phalconphp.com/zh/download,咱们须要本身手动编译phalcon模块
安装两个编译环境和工具:
yum install gcc libtool make git yum install php55w-devel (此处应该根据你本身的php版本去安装,具体版本信息能够输出phpinfo()查看)。
下载最新的phalcon文件
git clone git://github.com/phalcon/cphalcon.git cd cphalcon/build
而后执行
./install
编译好的.so文件目录地址:
/usr/lib64/php/moudels/phalcon.so
常见错误
咱们须要在/etc/php.d中新建一个 phalcon.ini文件,
vi phacon.ini
加入一下内容:
extension=phalcon.so
其次我被php-fpm重启也坑了半天,其重启命令是
services php-fpm restart
我在/etc/init.d/php-fpm restart半天也没反应,一直重启不起来,原来搞半天口令都错了。
至此,phalcon框架算是加载进来了,而后就是部署项目到服务器了
若是你仔细看我以前写的文档,你就会发现咱们在配置nginx环境修改php.ini的时候我写了一个此处有坑,咱们须要找到etc/php.ini:
cgi.fix_pathinfo=0改为 cgi.fix_pathinfo=1
开心~撒花。
centos经常使用命令:
php-fpm重启命令: services php-fpm restart nginx重启命令:services nginx restart 抑或在/etc/init.d/nginx -s reload
赋予权限:
chmod 777 -R ./ chrow www:www(用户组:用户名) -R ./
若是您对本文档有任何疑问或者建议,请您发送邮箱至zhoukai@dreamzk.cn,我会在第一时间给您答复,谢谢。 转载请代表出处,谢谢。