centos下配置laravel5.5运行环境随记

本机是新机什么东西都没有,所以记录下从无到有的所有过程。

1、安装unzip

yum install -y vim unzip  //-y自动全部选择y

2、下载php源码并解压

wget http://cn.php.net/distributions/php-7.2.7.tar.gz
tar -xzxvf php-7.2.7.tar.gz

3、进入php源码目录后编译

./configure --prefix=/usr/local/php72 --with-config-file-path=/usr/local/php72/etc --with-mhash --with-openssl --enable-mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-iconv-dir --with-zlib --with-zlib-dir --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --without-gdbm --disable-fileinfo --with-libxml-dir --enable-sysvmsg --enable-sysvshm  --with-bz2 --with-readline --with-libdir --enable-calendar --enable-exif --enable-intl  --with-png-dir  --enable-wddx --enable-dom --enable-filter --with-pear=DIR

中间会遇到很多错误,自己解决,一般都是某些应用未安装

make && make install

4、php安装完后开始修改一些配置项

cp php.ini-production /usr/local/php72/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php72-fpm
cd /usr/local/php73/etc
cd /usr/local/php72/etc
cp php-fpm.conf.default php-fpm.conf
chmod +x /etc/init.d/php72-fpm
chkconfig --add php72-fpm
chkconfig --level 35 php72-fpm on
vim php-fpm.conf
pid = run/php-fpm.pid
error_log = log/php-fpm_error.log
daemonize = yes
events.mechanism = epoll
cd php-fpm.d/
ll
cp www.conf.default www.conf
ll
vi www.conf
user = www
group = www
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = static
pm.max_children = 127
pm.max_requests = 10240
access.log = /data/logs/php-fpm_access.log
access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
slowlog = var/log/$pool.log.slow
request_slowlog_timeout = 5
rlimit_files = 65000
rlimit_core = 65000
catch_workers_output = yes

5、设置全局变量

PATH=$PATH:/usr/local/php72/bin
export PATH
source /etc/profile
php -v

至此PHP已经安装完毕

6、下载nginx

wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz

修改一下配置信息

vim src/core/nginx.h  //nginx版本信息
#define nginx_version      1014000
#define NGINX_VERSION      "66666"
#define NGINX_VER          "WTF/" NGINX_VERSION

vim src/http/ngx_http_header_filter_module.c \\修改HTTP头信息中的connection字段,防止回显具体版本号
 static u_char ngx_http_server_string[] = "Server: WTF" CRLF;

vim src/http/ngx_http_special_response.c \\ 有时候我们页面程序出现错误,Nginx会代我们返回相应的错误代码,回显的时候,会带上nginx和版本号,我们把他隐藏起来 
static u_char ngx_http_error_tail[] =
"<hr><center>WTF</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

编译安装

./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module  --with-http_addition_module --with-http_sub_module  --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module  --user=nginx  --group=nginx
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

运行一下Nginx

nginx
netstat -anput | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      15766/nginx: master 

nginx搞定

如果nginx报错应该会不存在nginx用户,可以新增上面编译时指定的nginx用户

useradd -s /sbin/nologin -M nginx

然后重新运行 就可以了。

7、安装composer

下载composer安装文件

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

运行composer安装文件

php composer-setup.php

删除composer安装文件

php -r "unlink('composer-setup.php');"

配置composer中国镜像

composer config -g repo.packagist composer https://packagist.phpcomposer.com

配置composer到全局环境变量

 
 
mv composer.phar /usr/bin/composer

其实这一步错了,因为centos7.4的bin目录/usr/bin目录,你可以在上一步的时候直接

mv composer.phar /usr/bin/compsoer

或者 也可以这样

ln -s /usr/local/bin/compsoer /usr/bin/compsoer

这样composer就可以全局访问了。

然后自己把laravel项目放置到想要放置的目录中并且配置好角色,继续开始配置nginx

配置nginx的时候在nginx.conf里最下方这样搞了

 include ./conf.d/*.conf;

对,也许你猜到了,我在nginx.conf当前目录下搞了一个conf.d的目录

里面放置了很多.conf文件,用来分别管理项目sever配置。

在www.xxx.com.conf配置里我是这样配置的

server{
    listen       80;
    server_name  www.xxx.com; 


    location / {
        root   /home/www/www.xxx.com/public;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;


        location ~ \.php$ {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
         }


    }

然后重启nginx,别忘了启动php。

nginx -s reload
service php-fpm start

这里可能会报一个错误让你去see systemctl status php72-fpm.service,看过后发现是没有www用户,那我们就先来添加www用户合用户组。

groupadd www //添加用户组
useradd -g www www //添加www用户

对了,不要忘记把项目目录给到www用户,这样你会省掉很多麻烦。

chown -R www.www ./www  

把你的域名解析好后,访问该域名你会发现,你的项目貌似已经配置好了..(这里我没有记录mysql的安装和配置,这里是由于我们项目中没有把数据库放置在项目服务器上)

但是实际上可能你的项目还没有那么完美的跑起来。

可能会动不动就报

could not find driver (SQL: select * from information_schema.tables bulabula....

在项目public目录下写一个info.php文件访问以下你会发现少了点儿东西..pdo没有加载进来。

是的,回到php安装过程中,我们找到php安装目录,编辑etc下的php.ini文件。

把扩展项的注释去掉,改为

extension_dir="/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718" 

这个地方值得注意的是,我安装的PHP在/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718目录下找到了相应的扩展,所以这个地方你要确定扩展的位置,这是在我们安装的过程中就已经搞好了的。

然后继续在下方的extension=pdo_mysql处取消注释,并修改为

extension=pdo_mysql.so
extension=mysqli.so

保存好后重启php,再次运行info.php,em.... 似乎发现了pdo和mysqli的扩展了,貌似问题到此是确实解决了。









猜你喜欢

转载自blog.csdn.net/u011743396/article/details/80775264