安装LNMP(Nginx+Mysql+PHP)

时间:2024-11-24 20:04:37

1:安装nginx
yum install -y gcc pcre-devel openssl-devel
wget http://www.nginx.org/download/nginx-1.4.2.tar.gz
useradd www
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module: 支持https
--with-http_spdy_module: 支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre: 为了支持rewrite重写功能,必须制定pcre
make && make install

2:安装mysql
yum install -y cmake ncurses-devel gcc-c++
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29.tar.gz
tar zxvf mysql-5.6.29.tar.gz
cd mysql-5.6.29
cmake ./ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install

groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin 或 useradd -s /sbin/nologin -g mysql -M mysql

chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data

cd /usr/local/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/init.d/mysqld

cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

修改/etc/my.cnf中数据存放目录及mysql.sock的路径
touch /tmp/mysql.sock

service mysqld start

3:安装PHP
yum install gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
http://cn2.php.net/distributions/php-5.5.5.tar.gz

tar -zxvf php-5.5.5.tar.gz
cd php-5.5.5
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir --with-zlib --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-bcmath --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-fpm-user=www --with-fpm-group=www
make && make instal

配置文件:
cp php.ini-development /usr/local/php/etc/php.ini

配置php-fpm 服务
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动 php-fpm
service php-fpm start