1.下载所有待编译安装的包
wget http://nginx.org/download/nginx-1.9.9.tar.gz
wget http://cn2.php.net/distributions/php-7.2.8.tar.gz
php 装好后自带php-fpm
Nginx:
依赖插件安装:(centos用户自己谷歌下相应的组件)
sudo apt-get install openssl libssl-dev
sudo apt-get install libpcre3 libpcre3-dev
安装:
(方法一)
./configure --prefix=/usr/local/service --with-http_ssl_module
(方法二)
./configure --user=nginx\
--group=nginx\
--prefix=/usr/local/nginx\
--with-http_stub_status_module\
--with-http_ssl_module\
--with-http_gzip_static_module\
--with-ipv6
make
make install
异常抉择:
如出现:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
则需通过nginx –c ../conf/nginx.conf 命令指定nginx的配置
PHP:
#系统依赖
groupadd www-data
useradd -s /sbin/nologin -g www-data www-data
依赖插件安装:
sudo apt-get install libxml2-dev
sudo apt-get install libcurl3-openssl-dev
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libbz2-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libpng-dev
sudo apt-get install libxpm-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libt1-dev
sudo apt-get install libmcrypt-dev
sudo apt-get install libmysql++-dev
sudo apt-get install libxslt1-dev
(centos)
yum -y install gcc gcc-c++ make automake autoconf
yum -y install libxml2-devel openssl-devel pcre-devel sqlite-devel bzip2-deve l\
libcurl-devel freetype-devel gd-devel readline-devel libmcrypt-devel libicu-de vel
安装:(安装目录/usr/local/php7, mysql bin路径要指对(你要先安装好mysql))
./configure --help 看下 哪些 是有效的 参数(每个版本不一样,强行装也没事 ,但是会报warning,我这边是确保pdo-mysql一定要装上)
(方法1 )
./configure --disable-fileinfo --prefix=/usr/local/php7 --enable-fpm --with-mcrypt --enable-mbstring --enable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql=/usr/bin/mysql --with-mysqli --with-gd --with-jpeg-dir --with-openssl
(方法2 推荐)
./configure \
--prefix=/usr/local/php7 \
--disable-fileinfo \
--with-pdo-mysql=mysqlnd \
--with-mcrypt \
--with-bz2 \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir \
--with-readline \
--with-curl \
--with-pear \
--with-openssl \
--with-fpm-group=www-data \
--with-fpm-user=www-data \
--enable-fpm \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-zip
异常抉择:
如出现:configure: error: Cannot find OpenSSL's libraries
find / -name libssl.so
找到libssl.so后 软链接到/usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
当配置PHP时出现 make: * [ext/fileinfo/libmagic/apprentice.lo] Error 1 时
是因为服务器内存不足1G。
只需要在配置命令中添加 --disable-fileinfo即可
/root/install/php-7.2.8/ext/pdo_mysql/php_pdo_mysql_int.h:31:20: fatal error: mysql.h: No such file or directory
whereis mysql
找到include 的 c 头文件
sudo ln -s /usr/include/mysql/* /usr/local/include/ 把头文件软连接到 系统默认头文件 (这样make 就能找到这些头文件)
configure: error: Please reinstall libedit - I cannot find readline.h
apt-get install libedit2 libreadline6 libreadline6-dev
ERROR : sapi/cli/php
make clean
#软连接设置
#ln -s /usr/local/php-$PHP_VERSION/bin/php /usr/bin/php
#ln -s /usr/local/php-$PHP_VERSION/bin/phpize /usr/bin/phpize
#ln -s /usr/local/php-$PHP_VERSION/bin/pecl /usr/bin/pecl
#ln -s /usr/local/php-$PHP_VERSION/bin/php-config /usr/bin/php-config
#ln -s /usr/local/php-$PHP_VERSION/sbin/php-fpm /usr/bin/php-fpm
nginx demo 配置:(不要忘记chown www-data:www-data 网站目录 不然没权限)
server {
listen 80;
server_name {{ server_name }};
access_log /data/logs/nginx/{{ server_name }}/access.log;
error_log /data/logs/nginx/{{ server_name }}/error.log;
location / {
index index.php index.html index.htm;
root /data/www/wwwroot/{{ server_name }}/;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
}
}
php-fpm配置 (重命名两个文件 其他看实际情况配置(略。。。))
www.conf.default -> www.conf
php-fpm.conf.default -> php-fpm.conf
启动:
php-fpm -D
nginx -s reload
----
如果安装部署完毕(忘记了你要装的模块)想继续装扩展 怎么做?
1.找到你下载的php 扩展目录 (mysqli举例)
如 :
~/unzip/php-7.2.8/ext/mysqli
2.phpize
或
phpize --prefix=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/
3./configure --with-php-config=/usr/bin/php-config
4. make && make install
---------------------