Linux运维笔记-Lnmp环境配置

时间:2022-09-23 22:15:58

1.PHP安装

依赖安装

1 yum -y install gcc gcc-c++  libxslt-devel libxslt make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel  pcre-devel libtool-libs libtool-ltdl-devel freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel

添加www账户

1 groupadd www
2 useradd -g www -s /usr/sbin/nologin www

下载php源码

wget http://php.net/get/php-5.6.30.tar.gz/from/this/mirror

编译php

1 ./configure  --prefix=/opt/app/php5  --with-config-file-path=/opt/app/php5/etc --with-fpm-user=www --with-fpm-group=www --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-fileinfo --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl --with-kerberos --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-xsl --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug --enable-opcache  --with-zlib-dir=DIR   --with-pcre-dir 

PS:错误解决

make ZEND_EXTRA_LIBS='-liconv'

 

a.

configure: error: Cannot find ldap libraries in /usr/lib
解决办法:
cp -frp /usr/lib64/libldap* /usr/lib/
 

configure: error: Cannot find ldap.h

解决方法

yum install openldap  openldap-clients  openldap-devel  openldap-servers 

yum安装完成了就ok了!

但是这里需要注意一个问题,如果是64位的系统,就需要把那个i386修改为x86_64,然后yum就可以了!

 
相关配置项
1 cp php.ini-development /opt/app/php5/etc/php.ini
2 
3 cp /opt/app/php5/etc/php-fpm.conf.default /opt/app/php5/etc/php-fpm.conf
4 
5 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
6 
7 chmod +x /etc/init.d/php-fpm56
8 
9 service php-fpm56 restart

添加环境变量

1 vi ~/.bash_profile
2 
3 #修改
4 ...
5 PATH=$PATH:$HOME/bin 改为: 
6 
7 PATH=$PATH:$HOME/bin:/opt/app/php5/bin
8 ...

 

2.nginx编译安装

依赖安装

1 yum install pcre-devel openssl openssl-devel

下载源码

wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz

编译安装

1 ./configure --prefix=/opt/app/nginx/ --with-http_ssl_module --with-http_gzip_static_module
2 
3 make && make install

 

 
 
3.mysql安装
依赖安装
yum install cmake

 

下载源码

1 wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz

 

编译安装

1 添加mysql用户组
2 groupadd mysql
3 
4 cmake -DCMAKE_INSTALL_PREFIX=/opt/app/mysql      -DWITH_DEBUG=0      -DDEFAULT_CHARSET=utf8      -DEXTRA_CHARSETS=all      -DMYSQL_UNIX_ADDR=/opt/app/mysql/mysql.sock      -DMYSQL_DATADIR=/data/mysql/var      -DMYSQL_USER=mysql      -DWITH_READLINE=1      -DENABLED_LOCAL_INFILE=1      -DDEFAULT_COLLATION=utf8_general_ci
5 
6 make && make install
7 
8 #添加mysql用户
9 useradd -g mysql -d /opt/app/mysql -M mysql

 

相关配置项

1 cp /opt/app/mysql/support-files/my-default.cnf /opt/app/mysql/my.cnf
2 
3 cp /opt/app/mysql/support-files/mysql.server /etc/init.d/mysqld
4 
5 chmod +x /etc/init.d/mysqld

 

初始化msyql
1 mkdir /data/mysql
2 
3 /opt/app/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/var --basedir=/opt/app/mysql

 

启动mysql

1 chmod -R 777 /opt/app/mysql
2 chown -R mysql.mysql /opt/app/msyql
3 chown -R /data/mysql
4 
5 
6 service mysqld start

设置密码

/opt/app/mysql/bin/mysqladmin -u root password 'root'

测试

 1 [root@iZuf6610s5jsqm9fr53nslZ ~]# /opt/app/mysql/bin/mysql -uroot -p
 2 Enter password: 
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 2
 5 Server version: 5.6.35 Source distribution
 6 
 7 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql>