LNMP編譯安裝基於centos7.2

CentOS 7.0默認使用的是firewall做爲防火牆,這裏改成iptables防火牆。
一、關閉firewall:
systemctl stop firewalld.service #中止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
二、安裝iptables防火牆
yum install iptables-services #安裝
vi /etc/sysconfig/iptables #編輯防火牆配置文件
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq! #保存退出
systemctl restart iptables.service #最後重啓防火牆使配置生效
systemctl enable iptables.service #設置防火牆開機啓動
 
安裝所需組件和包:
alhost cmake-2.8.11.2]# yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
 
安裝cmake
[root@localhost cmake-2.8.11.2]# tar xf cmake-2.8.11.2.tar.gz 
[root@localhost cmake-2.8.11.2]# ./configure 
[root@localhost cmake-2.8.11.2]# make && make install

關閉selinuxphp

vi /etc/selinux/config
#SELINUX=enforcing #註釋掉
#SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增長
setenforce 0 #使配置當即生效

 

安裝mysqlhtml

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql -s /sbin/nologin 
[root@localhost ~]# mkdir -p /mydata/data
[root@localhost ~]# chown -R mysql.mysql /mydata/data/
[root@localhost ~]# mkdir -p /usr/local/mysql
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar xf mysql-5.6.19.tar.gz 
[root@localhost src]# cd mysql-5.6.19/
[root@localhost mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc 
[root@localhost mysql-5.6.19]#make && make install
[root@localhost mysql-5.6.19]# rm -rf /etc/my.cnf
[root@localhost mysql-5.6.19]# cd /usr/local/mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
[root@localhost mysql]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/rc.d/init.d/mysqld 
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld 
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql]# vim /etc/profile.d/mysql.sh
PATH=$PATH:/usr/local/mysql/bin   //添加變量路徑
[root@localhost mysql]# source /etc/profile.d/mysql.sh 
[root@localhost mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@localhost mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@localhost mysql]# mkdir /var/lib/mysql
[root@localhost mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

[root@localhost mysql]# mysql_secure_installation 設置mysql root密碼
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] 
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] 
 ... Success!
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] 
 ... Success!
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

 

安裝nginxmysql

[root@localhost src]# groupadd nginx
[root@localhost src]# useradd -g nginx nginx -s /sbin/nologin 
[root@localhost src]# tar xf nginx-1.6.0.tar.gz 
[root@localhost ~]# yum -y install yasm libmcrypt libvpx tiff libpng freetype jpeg libgd t1lib


[root@localhost src]# cd nginx-1.6.0/ [root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module [root@localhost nginx-1.6.0]#make && make install [root@localhost nginx-1.6.0]# /usr/local/nginx/sbin/nginx 啓動 [root@localhost nginx-1.6.0]# vim /etc/rc.d/init.d/nginx 配置啓動文件 [root@localhost nginx-1.6.0]#chmod +x /etc/init.d/nginx 測試:
image
 
安裝php:
 
安裝所需組件和包,能夠配置epel源來進行安裝.如何配置可參照:http://www.cnblogs.com/ligao/p/6122904.html
 
[root@localhost ~]# yum -y install yasm libmcrypt libvpx tiff libpng freetype jpeg libgd t1lib
 
注意:若是系統是64位,請執行如下兩條命令,不然安裝php會出錯(32位系統不須要執行) 
\cp -frp /usr/lib64/libltdl.so*  /usr/lib/
\cp -frp /usr/lib64/libXpm.so* /usr/lib/
 
[root@localhost php-5.6.25]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@localhost src]# tar xf php-5.6.25.tar.gz 
[root@localhost src]# cd php-5.6.25/
[root@localhost php-5.6.25]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-jpeg-dir=/usr/local/jpeg --with-xpm-dir=/usr/ --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype 
[root@localhost php-5.6.25]# make && make install
[root@localhost php-5.6.25]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.6.25]# rm -rf /etc/php.ini 
[root@localhost php-5.6.25]# ln -sv /usr/local/php/etc/php
php-fpm.conf.default  php.ini               
[root@localhost php-5.6.25]# ln -sv /usr/local/php/etc/php.ini /etc/php.ini
‘/etc/php.ini’ -> ‘/usr/local/php/etc/php.ini’
[root@localhost php-5.6.25]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.6.25]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
[root@localhost php-5.6.25]# vim /usr/local/php/etc/php-fpm.conf
user = www #設置php-fpm運行帳號爲nginx
group = www #設置php-fpm運行組爲nginx
pid = run/php-fpm.pid #取消前面的分號
[root@localhost php-5.6.25]# cp /usr/local/src/php-5.6.25/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@localhost php-5.6.25]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@localhost php-5.6.25]# chkconfig php-fpm on
[root@localhost php-5.6.25]# vim /usr/local/php/etc/php.ini
找到:disable_functions =
修改成:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP能夠禁用的函數,若是某些程序須要用到這個函數,能夠刪除,取消禁用。
找到:;date.timezone =
修改成:date.timezone = PRC #設置時區
找到:expose_php = On
修改成:expose_php = Off #禁止顯示php版本的信息
找到:short_open_tag = Off
修改成:short_open_tag = ON #支持php短標籤
找到opcache.enable=0
修改成opcache.enable=1 #php支持opcode緩存
找到:opcache.enable_cli=1 #php支持opcode緩存
修改成:opcache.enable_cli=0
在最後一行添加:zend_extension=opcache.so #開啓opcode緩存功能

配置nginx支持php

vi /usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf 配置文件,需作以下修改
user nginx nginx; #首行user去掉註釋,修改Nginx運行組爲www www;必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,不然php運行出錯
index index.html index.htm index.php; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的註釋,注意fastcgi_param行的參數,改成$document_root$fastcgi_script_name,或者使用絕對路徑
/etc/init.d/nginx restart #重啓nginx
service php-fpm start #啓動php-fpm
測試篇
cd /usr/local/nginx/html/ #進入nginx默認網站根目錄
rm -rf /usr/local/nginx/html/* #刪除默認測試頁
vi index.php #新建index.php文件
<?php
phpinfo();
?>
chown www.www /usr/local/nginx/html/ -R #設置目錄全部者
chmod 700 /usr/local/nginx/html/ -R #設置目錄權限

 

測試:linux

image

相關文章
相關標籤/搜索