第一步:安装Nginx
Nginx依赖的包不多,除了常规的编译包,再安装上一下几个开发包就可以了。
sudo yum install pcre-devel zlib-devel openssl-devel
下载nginx源码包,解压后进入源码目录,然后执行make等安装就可以了。
make sudo make install
nginx默认安装到/usr/local/nginx路径。
第二步:安装PHP运行环境
sudo yum install php-devel php-fpm php-mysql php-pdo
运行PHP-FPM
sudo php-fpm -D
第三步:安装PHP的mcrypt扩展
CentOS 7运行Laravel的一个不方便的地方就是yum没有php的mcrypt扩展,需要手动编译安装一个。 首先需要编译安装libmcrypt。
tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make sudo make install
然后再编译mcrypt.so,编译完成之后放到/usr/lib64/modules目录下。 再到/etc/php.d路径下新建mcrypt.ini文件,内容如下
; Enable mcrypt extension module extension=mcrypt.so
重启php-fpm之后即可加载了。
第四步:配置Nginx
假设Laravel的网站根目录为/srv/www/default,修改/usr/local/nginx/conf/nginx.conf文件成如下内容
#user nobody; worker_processes 8; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; client_max_body_size 100m; gzip on; server { listen 80; server_name localhost; set $root_path '/srv/www/default/public'; root $root_path; index index.php index.html index.htm; 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 /usr/local/nginx/conf/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; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
由于PHP-FPM使用apache用户运行,所以修改网站根目录的权限给apache用户。
cd /srv/www chown -R apache default chgrp -R apache default
运行如下命令重启Nginx生效。
sudo /usr/local/nginx/sbin -s reload
至此,PHP和Laravel运行环境已经完成,Laravel已经可以运行在CentOS 7上了。
相关文章
本文链接:http://www.it892.com/content/system/centos/2015/article5968.html
推荐阅读
linux操作系统:Robolinux 7.6.2发布
Robolinux 7.6.2 发布,此版本包括 Robolinux Xfce 和 GNOME 7.6.2 ,包括了一些改进和工增强。... [详细]
热点排行