手动阀

Good Luck To You!

CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤

在CentOS 6.4系统下编译安装LNMP(Linux, Nginx, MySQL, PHP)环境并配置PHP环境,可以按照以下步骤进行,这是一个较为详细的指导,请确保你有root权限或使用sudo命令来执行这些操作。

更新系统软件包

更新你的系统软件包:

sudo yum update y

安装Nginx

安装依赖项:

sudo yum install y gcc pcredevel zlibdevel openssldevel

下载和解压Nginx源码:

cd /usr/local/src
wget http://nginx.org/download/nginx1.8.0.tar.gz
tar zxvf nginx1.8.0.tar.gz
cd nginx1.8.0

配置、编译和安装Nginx:

./configure prefix=/usr/local/nginx withhttp_ssl_module
make && sudo make install

创建软链接到/usr/bin和启动脚本:

sudo ln s /usr/local/nginx/sbin/nginx /usr/bin/nginx
sudo cp /usr/local/nginx/conf/nginx.conf /etc/nginx.conf
sudo cp /usr/local/nginx/sbin/nginx /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
chkconfig add nginx
chkconfig nginx on

启动Nginx:

sudo service nginx start

安装MySQL

安装依赖项:

sudo yum install y perl cmake ncursesdevel bisondevel libaiodevel libmecabdevel libselinuxdevel pamdevel readlinedevel openssldevel

下载和解压MySQL源码:

cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL5.6/mysql5.6.27.tar.gz
tar zxvf mysql5.6.27.tar.gz
cd mysql5.6.27

配置、编译和安装MySQL:

cmake . DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    DMYSQL_DATADIR=/usr/local/mysql/data \
    DSYSCONFDIR=/etc \
    DMYSQL_TCP_PORT=3306 \
    DEXTRA_CHARSETS=all \
    DDEFAULT_CHARSET=utf8mb4 \
    DDEFAULT_COLLATION=utf8mb4_general_ci \
    DWITH_INNODB_STORAGE_ENGINE=1 \
    DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    DWITH_READLINE=system \
    DENABLED_LOCAL_INFILE=1 \
    DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock
make && sudo make install

初始化数据库并启动MySQL:

sudo /usr/local/mysql/scripts/mysql_install_db user=mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data
sudo groupadd mysql
sudo useradd r g mysql s /bin/false mysql
sudo chown R mysql:mysql /usr/local/mysql /usr/local/mysql/data
sudo /usr/local/mysql/bin/mysqld_safe user=mysql &
sleep 5

设置MySQL为系统服务:

sudo cp /usr/local/mysql/supportfiles/mysql.server /etc/init.d/mysqld
sudo chmod +x /etc/init.d/mysqld
chkconfig add mysqld
chkconfig mysqld on

设置root密码:

sudo /usr/local/mysql/bin/mysqladmin u root password 'yourpassword'
sudo /usr/local/mysql/bin/mysql u root p'yourpassword' <<EOF
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY 'yourpassword';
EOF

启动MySQL:

sudo service mysqld start

安装PHP

安装依赖项:

sudo yum install y gcc libxml2devel bzip2devel libjpegdevel libmcryptdevel libpngdevel freetypedevel libxsltdevel curldevel libcurldevel libcclientdevel glibcdevel glib2devel libidndevel openssldevel libeditlinedevel libtermcapdevel

下载和解压PHP源码:

cd /usr/local/src
wget https://www.php.net/distributions/php5.6.27.tar.gz
tar zxvf php5.6.27.tar.gz
cd php5.6.27

配置、编译和安装PHP:

./configure prefix=/usr/local/php \
    withconfigfilepath=/usr/local/php \
    enableinlineoptimization \
    withbz2 \
    enablebz2 \
    withcurl \
    enablecurl \
    withjpegdir \
    withpngdir \
    withfreetypedir \
    withgd \
    enablegdnativettf \
    withopenssl \
    withmcrypt=shared \
    withzlib=shared \
    enablembstring \
    withxmlrpc \
    enablexmlrpc \
    withmysql=shared,/usr/local/mysql \
    withpdomysql=shared,/usr/local/mysql \
    withgettext \
    withiconvdir \
    withxsl \
    enablesoap \
    enableftp \
    withapxs2=/usr/local/apache2/bin/apxs \
    withfpmuser=www \
    withfpmgroup=www \
    enablefpm \
    disabledebug \
    disablerpath \
    enableinlineoptimization
make && sudo make install

创建软链接到PHP解释器:

sudo ln s /usr/local/php/bin/php /usr/bin/php

配置PHPFPM:

sudo cp sapi/phpfpm.service /etc/systemd/system/phpfpm.service
sudo systemctl enable phpfpm.service
sudo systemctl start phpfpm.service

配置Nginx与PHP的集成

编辑Nginx配置文件以支持PHP处理:

sudo vi /etc/nginx.conf

http块中添加以下内容:

include /usr/local/nginx/conf/fastcgi.conf;
include /usr/local/nginx/conf/fastcgi_params;

在server块中添加PHP处理配置:

server {
    listen       80;
    server_name  localhost;
    root   html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}

重启Nginx服务:

sudo service nginx restart

至此,你已经成功在CentOS 6.4上编译并安装了LNMP(Linux, Nginx, PHP, MySQL)环境,你可以访问http://<your_server_ip> 查看Nginx欢迎页面,并测试PHP文件是否工作正常。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.3

Copyright Your WebSite.Some Rights Reserved.