阿里云 CentOS LNMP 环境搭建

来源:互联网 发布:arm linux入门 编辑:程序博客网 时间:2024/05/17 10:57

CentOS 7.3    nginx 1.10.2   PHP 7.1.5   Mysql 5.7.18

 1. 安装nginx
 yum install nginx 
 nginx -v
     nginx version: nginx/1.10.2


 vi /etc/nginx/nginx.conf
     error_log /var/log/nginx/error.log;
     access_log  /var/log/nginx/access.log  main;
 
     server
root         /usr/share/nginx/html;


     ps -ef | grep nginx
root     15130     1  0 11:16 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx    15131 15130  0 11:16 ?        00:00:00 nginx: worker process


这时可以web访问网站了,但不支持php文件。

2. 手动编译安装PHP 

groupadd -r www && useradd -r -g www -s /bin/false -d /usr/local/php7 -M www
 
 yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
 wget http://cn2.php.net/get/php-7.1.5.tar.gz/from/this/mirror
 ./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--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-gd-native-ttf \
--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-redis \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm \
--disable-fileinfo
 make
 make test
 =====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #64267 (CURLOPT_INFILE doesn't allow reset) [ext/curl/tests/bug64267.phpt]
Bug #71523 (Copied handle with new option CURLOPT_HTTPHEADER crashes while curl_multi_exec) [ext/curl/tests/bug71523.phpt]
file_get_contents() test using offset parameter out of range [ext/standard/tests/file/file_get_contents_error001.phpt]
FPM: Startup and connect [sapi/fpm/tests/002.phpt]
FPM: Test Unix Domain Socket [sapi/fpm/tests/009.phpt]
FPM: Test IPv4 all addresses (bug #68420) [sapi/fpm/tests/011.phpt]
FPM: Test reload configuration (bug #68442) [sapi/fpm/tests/012.phpt]
FPM: Test for log_level in fpm_unix_init_main #68381 [sapi/fpm/tests/013.phpt]
FPM: Test for pm.start_servers default calculation message being a notice and not a warning #68458 [sapi/fpm/tests/014.phpt]
FPM: Test fastcgi_finish_request function [sapi/fpm/tests/017.phpt]
FPM: Test global prefixAz. [sapi/fpm/tests/019.phpt]
FPM: Test pool prefix [sapi/fpm/tests/020.phpt]
FPM: HTTP_PROXY - CVE-2016-5385 [sapi/fpm/tests/022-cve-2016-5385.phpt]
=====================================================================


 make install
 
 cd /usr/local
 cp php-7.1.5-src/php.ini-production php7/etc/php.ini
 cd /usr/local/php7
 cp php-fpm.conf.default php-fpm.conf

/usr/local/php7/sbin/php-fpm  启动php-fpm

ps -ef | grep php
root     15243     1  0 11:43 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
www      15244 15243  0 11:43 ?        00:00:00 php-fpm: pool www
www      15245 15243  0 11:43 ?        00:00:00 php-fpm: pool www


修改nginx.conf  增加:

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;
        }


这样就可以访问php文件了。


3. yum install mysql 

yum install mysql 
yum install mysql-community-server

mysql -V
mysql  Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using  EditLine wrapper

安装mysql 后 root还没有密码  

修改 /etc/my.cnf  最后加上 skip-grant-tables 
service mysqld restart  

然后/usr/bin/mysql_secure_installation 设置root密码,删掉test数据库,禁止remote访问


mysqld的日志文件:/var/log/mysqld.log


4. 配置PHP+Mysql

修改php.ini

extension_dir = ‘/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/’

extension=pdo_mysql.so


到此可以使用PDO的方式访问 mysql数据库了。 如下代码:

$pdo=new PDO('mysql:host=localhost;dbname=dc;port=3306','root','Enqiang123');
$pdo->exec('set names utf8');

$sql="insert test  values (5,'123456')";
$res=$pdo->exec($sql);
echo '影响行数:'.$res;


======================================

以下为开机启动设置:

php-fpm 要写开机启动脚本 放到/etc/init.d目录下  然后

chkconfig --add php-fpm

chkconfig php-fpm on

chkconfig nginx on

chkconfig mysqld on



5. 安装memcached

#1 服务端

yum install memcached

memcached -u root -d  以deamon形式启动memcached

#2 客户端

因为php_memcached 依赖 libmemcached

yum install libmemcached libmemcached-devel  // copy memcached.so 到对应的php.ini 设置的extension_dir目录

php.ini 中增加extension=memcached.so

重启(或只需重启web服务器)


原创粉丝点击