阿里云 ECS Linux 云服务器编译安装 PHP 开发环境
本文介绍如何使用一台普通配置的云服务器 ECS
实例搭建 LNMP
平台的web环境,这也是本人的一些踩坑总结。
适用对象
适用于熟悉Linux操作系统,刚开始使用阿里云进行建站的个人用户。
基本流程
使用云服务器 ECS
搭建 LNMP
平台的操作步骤如下:
1.准备编译环境
2.安装 nginx
3.安装 mysql
4.安装 php-fpm
5.测试访问
步骤一:准备编译环境
本文主要说明手动安装 LNMP
平台的操作步骤,您也可以在云市场购买 LNMP
镜像直接启动 ECS
,以便快速建站。
打开一个终端,登录 ECS
云服务器:
ssh user@IP
回车,输入正确的密码后再回车即可登录。
1、系统版本说明
[root@example ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@example ~]#
注:这是本文档实施时参考的系统版本。您的实际使用版本可能与此不同,下文中的 nginx
,mysql
,及 php
版本,您也可以根据实际情况选择相应版本。
2、关闭SELINUX
修改配置文件,重启服务后永久生效。
[root@example ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
命令行设置立即生效。
[root@example ~]# setenforce 0
3、安全组设置
在 ECS
安全组放行需访问的端口和访问白名单,下面的示例表示允许所有 IP
访问服务器的 80 端口。您可以根据实际情况放行允许访问的客户端 IP
。
步骤二:安装 Nginx
Nginx
是一个小巧而高效的 Linux
下的 Web
服务器软件,是由 Igor Sysoev
为俄罗斯访问量第二的 Rambler.ru
站点开发的,已经在一些俄罗斯的大型网站上运行多年,目前很多国内外的门户网站、行业网站也都在是使用 Nginx
,相当稳定。
Nginx下载页面地址:
1、添加运行nginx服务进程的用户
[root@example ~]# groupadd -r nginx
[root@example ~]# useradd -r -g nginx nginx
2、下载源码包解压编译。
将鼠标放到你想下载的对应版本的文件上方,【右键】->【复制链接地址】, 然后:
进入要存放源码文件的目录:
[root@example ~]# cd /usr/local/src
下载对应版本的压缩包:
[root@example ~]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
解压缩:
[root@example ~]# tar xvf nginx-1.10.2.tar.gz
安装依赖包:
[root@example ~]# yum groupinstall "Development tools"
[root@example ~]# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
进入解压后的源码目录:
[root@example ~]# cd /usr/local/src/nginx-1.10.2
配置编译参数:
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-threads \
--with-stream \
--with-stream_ssl_module
如果没有配置出错,然后进行编译安装:
[root@example ~]# make && make install
创建 nginx 相关的目录:
[root@example ~]# mkdir -pv /var/tmp/nginx/client
3、添加SysV启动脚本。
[root@example ~]# vim /etc/init.d/nginx
复制以下内容到脚本中:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
4、赋予脚本执行权限。
[root@example ~]# chmod +x /etc/init.d/nginx
5、添加至服务管理列表,设置开机自启。
[root@example ~]# chkconfig --add nginx
[root@example ~]# chkconfig nginx on
6、启动服务。
[root@example ~]# service nginx start
7、浏览器访问可看到默认欢迎页面。
步骤三:安装 MySQL
MySQL下载页面地址:
1、准备编译环境。
[root@example ~]# yum groupinstall "Server Platform Development" "Development tools" -y
[root@example ~]# yum install cmake -y
2、准备 MySQL 数据存放目录。
[root@example ~]# mkdir /mnt/data
[root@example ~]# groupadd -r mysql
[root@example ~]# useradd -r -g mysql -s /sbin/nologin mysql
[root@example ~]# id mysql
uid=497(mysql) gid=498(mysql) groups=498(mysql)
3、更改数据目录属主属组:
[root@example ~]# chown -R mysql:mysql /mnt/data
4、解压编译在 MySQL
官网下载的稳定版源码包
进入MySQL
的下载页面:
点击你想要的版本, 因为是编译安装,所以选择 Source Code
版本:
然后将本页面拉到下面,选择下载最下方的一个版本,点击Download
:
跳转页面之后,对红框中的链接进行:【右键】->【复制链接地址】
打开终端,切换目录:
[root@example ~]# cd /usr/local/src
下载压缩包:
[root@example ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
解压缩:
[root@example ~]# tar xvf mysql-5.6.40.tar.gz
进入解压缩后的目录:
[root@example ~]# cd /usr/local/src/mysql-5.6.40
配置编译参数:
[root@example ~]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
若出现如下错误:
CMake Error at cmake/ssl.cmake:247 (MESSAGE):
Cannot find appropriate system libraries for SSL. Make sure you've
specified a supported SSL version. Consult the documentation for WITH_SSL
alternatives
Call Stack (most recent call first):
CMakeLists.txt:446 (MYSQL_CHECK_SSL)
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:128 (FIND_CURSES)
cmake/readline.cmake:218 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:448 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-5.6.38/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-5.6.38/CMakeFiles/CMakeError.log".
执行此操作:
[root@example ~]# rm CMakeCache.txt
[root@example ~]# yum install ncurses-devel
接着:
[root@example ~]# make && make install
5、修改安装目录的属组为mysql。
[root@example ~]# chown -R mysql:mysql /usr/local/mysql/
6、初始化数据库。
[root@example ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mnt/data/
注:在当前版本的操作系统的最小安装完成后,在 /etc 目录下会存在一个 my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的 MySQL 的正确配置,造成无法启动。
[root@example ~]# mv /etc/my.cnf /etc/my.cnf.bak
7、拷贝配置文件和启动脚本。
[root@example ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@example ~]# chmod +x /etc/init.d/mysqld
[root@example ~]# cp support-files/my-default.cnf /etc/my.cnf
8、设置开机自动启动。
[root@example ~]# chkconfig mysqld on
[root@example ~]# chkconfig --add mysqld
9、修改配置文件中的安装路径及数据目录存放路径。
[root@example ~]# echo -e "basedir = /usr/local/mysql\ndatadir = /mnt/data\n" >> /etc/my.cnf
10、设置PATH环境变量。
[root@example ~]# echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
[root@example ~]# source /etc/profile.d/mysql.sh
11、启动服务。
[root@example ~]# service mysqld start
若出现如下错误:
Starting MySQL.Logging to '/mnt/data/localhost.localdomain.err'.
The server quit without updating PID file (/mnt/data/localh[FAILED]ldomain.pid).
[root@localhost mysql]# service mysqld start
Starting MySQL.The server quit without updating PID file (/mnt/data/localhost.localdomain.pid). [FAILED]
重新初始化:
进入当前目录下的 scripts 目录:
[root@localhost mysql]# cd scripts/
[root@localhost scripts]# ./mysql_install_db --user=mysql --datadir=/mnt/data/
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
接着执行:
[root@localhost scripts]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/data &
看到如下信息之后回车:
[1] 16068
[root@localhost scripts]# Installing MySQL system tables...2017-12-01 01:23:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-01 01:23:46 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-12-01 01:23:46 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.38) starting as process 16077 ...
2017-12-01 01:23:46 16077 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-12-01 01:23:46 16077 [Note] InnoDB: The InnoDB memory heap is disabled
2017-12-01 01:23:46 16077 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-12-01 01:23:46 16077 [Note] InnoDB: Memory barrier is not used
2017-12-01 01:23:46 16077 [Note] InnoDB: Compressed tables use zlib 1.2.7
2017-12-01 01:23:46 16077 [Note] InnoDB: Using CPU crc32 instructions
2017-12-01 01:23:46 16077 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-12-01 01:23:46 16077 [Note] InnoDB: Completed initialization of buffer pool
2017-12-01 01:23:46 16077 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-12-01 01:23:46 16077 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-12-01 01:23:46 16077 [Note] InnoDB: Database physically writes the file full: wait...
2017-12-01 01:23:46 16077 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-12-01 01:23:46 16077 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-12-01 01:23:46 16077 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-12-01 01:23:46 16077 [Warning] InnoDB: New log files created, LSN=45781
2017-12-01 01:23:46 16077 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-12-01 01:23:46 16077 [Note] InnoDB: Doublewrite buffer created
2017-12-01 01:23:46 16077 [Note] InnoDB: 128 rollback segment(s) are active.
2017-12-01 01:23:46 16077 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-12-01 01:23:46 16077 [Note] InnoDB: Foreign key constraint system tables created
2017-12-01 01:23:46 16077 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-12-01 01:23:46 16077 [Note] InnoDB: Tablespace and datafile system tables created.
2017-12-01 01:23:46 16077 [Note] InnoDB: Waiting for purge to start
2017-12-01 01:23:46 16077 [Note] InnoDB: 5.6.38 started; log sequence number 0
2017-12-01 01:23:46 16077 [Note] RSA private key file not found: /mnt/data//private_key.pem. Some authentication plugins will not work.
2017-12-01 01:23:46 16077 [Note] RSA public key file not found: /mnt/data//public_key.pem. Some authentication plugins will not work.
2017-12-01 01:23:47 16077 [Note] Binlog end
2017-12-01 01:23:47 16077 [Note] InnoDB: FTS optimize thread exiting.
2017-12-01 01:23:47 16077 [Note] InnoDB: Starting shutdown...
2017-12-01 01:23:48 16077 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2017-12-01 01:23:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-01 01:23:48 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-12-01 01:23:48 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.38) starting as process 16099 ...
2017-12-01 01:23:48 16099 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-12-01 01:23:48 16099 [Note] InnoDB: The InnoDB memory heap is disabled
2017-12-01 01:23:48 16099 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-12-01 01:23:48 16099 [Note] InnoDB: Memory barrier is not used
2017-12-01 01:23:48 16099 [Note] InnoDB: Compressed tables use zlib 1.2.7
2017-12-01 01:23:48 16099 [Note] InnoDB: Using CPU crc32 instructions
2017-12-01 01:23:48 16099 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-12-01 01:23:48 16099 [Note] InnoDB: Completed initialization of buffer pool
2017-12-01 01:23:48 16099 [Note] InnoDB: Highest supported file format is Barracuda.
2017-12-01 01:23:48 16099 [Note] InnoDB: 128 rollback segment(s) are active.
2017-12-01 01:23:48 16099 [Note] InnoDB: Waiting for purge to start
2017-12-01 01:23:48 16099 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2017-12-01 01:23:48 16099 [Note] RSA private key file not found: /mnt/data//private_key.pem. Some authentication plugins will not work.
2017-12-01 01:23:48 16099 [Note] RSA public key file not found: /mnt/data//public_key.pem. Some authentication plugins will not work.
2017-12-01 01:23:48 16099 [Note] Binlog end
2017-12-01 01:23:48 16099 [Note] InnoDB: FTS optimize thread exiting.
2017-12-01 01:23:48 16099 [Note] InnoDB: Starting shutdown...
2017-12-01 01:23:49 16099 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[1]+ 完成 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/data
查看一下 MySQL
的状态:
[root@localhost scripts]# service mysqld status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]
启动与重启的检查:
[root@localhost scripts]# service mysqld start
Starting MySQL.Logging to '/mnt/data/localhost.localdomain.err'.
[ OK ]
[root@localhost scripts]# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
登录连接数据库:
[root@example ~]# mysql -h 127.0.0.1
步骤四:安装php-fpm
Nginx
本身不能处理 PHP
,作为 Web
服务器,当它接收到请求后,不支持对外部程序的直接调用或者解析,必须通过 FastCGI
进行调用。如果是 PHP
请求,则交给 PHP
解释器处理,并把结果返回给客户端。PHP-FPM
是支持解析 PHP
的一个 FastCGI
进程管理器。提供了更好管理 PHP
进程的方式,可以有效控制内存和进程、可以平滑重载 PHP
配置。
1、安装依赖包。
[root@example ~]# yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel
2、从官网下载的源码包,解压缩并编译安装。
PHP ( 7.0.26 ) 下载页面:
选择一个镜像源,【右键】->【复制链接地址】:
切换到存放源码的目录:
[root@example ~]# cd /usr/local/src/
下载压缩包:
[root@example ~]# wget http://cn2.php.net/get/php-7.0.26.tar.gz/from/this/mirror
下载好以后,这个压缩包的文件名是 mirror
, 但是它其实是一个 .tar.gz
的压缩包,所以将它解压缩:
tar -zxvf php-7.0.26.tar.gz
进入解压缩后的目录:
[root@example ~]# cd php-7.0.26/
配置编译参数:
[root@example ~]# ./configure --prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--with-mysqli=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-openssl \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-bz2 \
--with-curl=/usr/local/curl
如果没有 curl
,请看这:Linux 编译安装 CURL
如果没有配置出错,执行编译安装:
[root@example ~]# make && make install
如果你使用的是配置比较低,内存比较小的服务器,可能到编译这一步就会卡掉,因为在前面已经启动了 MySQL ,MySQL的内存占用很高,我的服务器内存是 1 个 G ,MySQL的内存占用是 45.6% ,如果出现编译停止,报 fileinfo 扩展的错误,请先停止MySQL服务,等 PHP 安装完后再将其启动。
3、添加php和php-fpm配置文件。
[root@example ~]# cp /usr/local/src/php-7.0.26/php.ini-production /etc/php.ini
[root@example ~]# cd /usr/local/php/etc/
[root@example ~]# cp php-fpm.conf.default php-fpm.conf
[root@example ~]# sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf
4、添加php-fpm启动脚本,并赋予脚本执行权限:
[root@example ~]# cp /usr/local/src/php-7.0.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@example ~]# chmod +x /etc/init.d/php-fpm
5、添加php-fpm至服务列表并设置开机自启。
[root@example ~]# chkconfig --add php-fpm
[root@example ~]# chkconfig --list php-fpm
[root@example ~]# chkconfig php-fpm on
6、启动服务。
[root@example ~]# service php-fpm start
若出现如下情况:
Starting php-fpm [01-Dec-2017 02:31:24] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 125.
[01-Dec-2017 02:31:24] ERROR: No pool defined. at least one pool section must be specified in config file
[01-Dec-2017 02:31:24] ERROR: failed to post process the configuration
[01-Dec-2017 02:31:24] ERROR: FPM initialization failed
failed
执行此操作:
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm done
[root@localhost php-fpm.d]#
7、添加 nginx
对 fastcgi
的支持,首先备份默认的配置文件。
[root@localhost php-fpm.d]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
[root@localhost php-fpm.d]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
编辑 /etc/nginx/nginx.conf ,在所支持的主页面格式中添加 php 格式的主页,类似如下:
[root@localhost php-fpm.d]# vim /etc/nginx/nginx.conf
location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
}
取消以下内容前面的注释:
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
重新载入nginx的配置文件。
[root@localhost php-fpm.d]# service nginx reload
在 /usr/local/nginx/html/ 新建 index.php 的测试页面,内容如下。
<?php
phpinfo();
浏览器访问测试,如看到以下内容则表示 LNMP
平台构建完成。
本作品采用《CC 协议》,转载必须注明作者和本文链接
使用lnmp一键安装,美滋滋。https://lnmp.org/install.html
@dannyvan 我室友之前用的就是
Ubuntu
加lnmp
一键安装,图个方便,一条命令跑下去,编译了半个多小时,最后失败了,因为集成了很多东西,出了问题不好定位,花了两个多小时来排错,最后还是选择了编译安装 :joy: 。。。。。。编译安装虽然比较麻烦,也比较耗时,但是一整套流程走下来,能学到很多东西,而且编译安装换做其他发行版也适用 。:joy:哥们你买的centos吗
@fury 是的 :joy:
写成shell。下次一键就ok了。
@xianyunyehe 嗯嗯,好办法,下次试试 :joy:
@dongzt 嗯嗯,然后就可以定制自己的一键lnmp。 然后高级点的用docker! 环境这东西,一年也整不了几次的。
@xianyunyehe 嗯嗯,是的 :joy:
yum groupinstall "Server Platform Development" "Development tools" -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Warning: group Server Platform Development does not exist.
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or update
请问安装mysql的时候有遇到这样的情况吗?
@ccccc111 抱歉,没遇到过 :sweat_smile:
很好的。
@eiomi :smile:
牛人。能否使用最新版本来编译安装?感觉上面这些版本稍微有点旧了。 :smile:
@hustnzj 最新版的我还没试过,毕竟PHP都更新到7.3了,我还在用7.0 :sweat_smile:
@dongzt 其实我一直在用5.6,最近才准备换到7.2,7.3还是测试版本吧 :joy:
@hustnzj 是的 :joy: