CentOS7编译安装lamp环境和wordpress
1.准备
使用fcgi模式
主机IP:192.168.214.20
准备包:apr-1.7.0.tar.gz,apr-util-1.6.1.tar.gz,httpd-2.4.43.tar.gz,php-7.4.4.tar.gz,MariaDB-server-10.4.12(yum安装),wordpress-5.4-zh_CN.tar.gz
[root@centos7 ~]# wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
[root@centos7 ~]# wget https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@centos7 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
[root@centos7 ~]# wget https://www.php.net/distributions/php-7.4.4.tar.gz
wordpress-5.4-zh_CN.tar.gz下载地址:http://cn.wp101.net/download/
2.安装mariadb
2.1 配置yum源
[root@centos7 ~]# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
[root@centos7 ~]# cp /etc/yum.repos.d/mariadb.repo /etc/yum.repos.d/mariadb.repo.bak
#修改成清华源
[root@centos7 ~]# sed -i 's@downloads.mariadb.com\/MariaDB\/mariadb-10.4@mirrors.tuna.tsinghua.edu.cn\/mariadb\/mariadb-10.4.12@' /etc/yum.repos.d/mariadb.repo
2.2 安装
[root@centos7 ~]# yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common -y
2.3 修改配置文件
[root@centos7 ~]# vi /etc/my.cnf.d/server.cnf
#添加
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log_bin=/data/mysql/mysql-bin
log_error=/data/mysql/mysql.err
[root@centos7 ~]# vi /etc/my.cnf.d/client.cnf
#添加
[client]
socket=/data/mysql/mysql.sock
2.3 重新初始化
[root@centos7 ~]# mkdir -pv /data/mysql
[root@centos7 ~]# chown mysql.mysql /data/mysql
[root@centos7 ~]# mysql_install_db --datadir=/data/mysql --user=mysql
[root@centos7 ~]# rm -rf /var/lib/mysql
2.4 启动创建用户
[root@centos7 ~]# systemctl start mariadb
[root@centos7 ~]# mysql
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> grant all on wordpress.* to wpuser@'127.0.0.1' identified by '123456';
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.002 sec)
3.httpd-2.4.43安装
3.1 安装相关的包
[root@centos7 ~]# yum install gcc prce-devel openssl-devel expat-devel -y
3.2 编译安装
[root@centos7 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.43.tar.gz
[root@centos7 ~]# for i in *.tar.gz ;do tar xvf $i;done
[root@centos7 ~]# mv apr-1.7.0 httpd-2.4.43/srclib/apr
[root@centos7 ~]# mv apr-util-1.6.1 httpd-2.4.43/srclib/apr-util
[root@centos7 ~]# useradd -r -s /sbin/nologin apache
[root@centos7 ~]# cd httpd-2.4.43
[root@centos7 httpd-2.4.43]# ./configure \
--prefix=/data/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@centos7 httpd-2.4.43]# make && make install
3.3 配置环境变量
[root@centos7 httpd-2.4.43]# echo 'PATH=/data/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@centos7 httpd-2.4.43]# . /etc/profile.d/httpd24.sh
3.4 修改配置文件
[root@centos7 httpd-2.4.43]# vi /data/httpd24/conf/httpd.conf
#找到下面两行取消注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#找到下面内容添加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#修改用户和组
User apache
Group apache
#末尾添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://localhost:9000/data/httpd24/htdocs/$1
#选择修改
#ServerName www.example.com:80
ServerName localhost:80
4.4 启动apache
[root@centos7 httpd24]# apachectl start
4.php7.4编译安装
4.1.准备包
[root@centos7 ~]#wget https://www.php.net/distributions/php-7.4.4.tar.gz
[root@centos7 ~]#tar xvf php-7.4.4.tar.gz
[root@centos7 php-7.4.4]# cd php-7.4.4
4.2.配置环境
[root@centos7 php-7.4.4]# yum -y install epel-release
[root@centos7 php-7.4.4]# yum -y install libxml-devel libxml2-devel sqlite-devel bzip2-devel libcurl-devel libpng-devel libwebp-devel libjpeg-devel freetype-devel
[root@centos7 php-7.4.4]# wget http://down.24kplus.com/linux/oniguruma/oniguruma-6.7.0-1.el7.x86_64.rpm
[root@centos7 php-7.4.4]# wget http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
[root@centos7 php-7.4.4]# rpm -ivh oniguruma-6.7.0-1.el7.x86_64.rpm oniguruma-devel-6.7.0-1.el7.x86_64.rpm
[root@centos7 php-7.4.4]# rm oniguruma-6.7.0-1.el7.x86_64.rpm oniguruma-devel-6.7.0-1.el7.x86_64.rpm
4.3.编译安装
[root@centos7 php-7.4.4]# ./configure --prefix=/data/php74 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@centos7 php-7.4.4]# make && make install
4.4.修改配置文件
[root@centos7 php-7.4.4]# cp php.ini-production /etc/php.ini
[root@centos7 php-7.4.4]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@centos7 php-7.4.4]# chmod +x /etc/init.d/php-fpm
[root@centos7 php-7.4.4]# chkconfig --add php-fpm
[root@centos7 php-7.4.4]# chkconfig php-fpm on
[root@centos7 php-7.4.4]# cd /data/php74/etc
[root@centos7 etc]# cp php-fpm.conf.default php-fpm.conf
[root@centos7 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@centos7 etc]# vi php-fpm.d/www.conf
#修改用户
user = apache
group = apache
4.5.启动php
[root@centos7 etc]# service php-fpm start
5.配置wordpress
5.1 解压赋权
[root@centos7 ~]# cd /data/httpd24/htdocs/
[root@centos7 htdocs]# cp ~/wordpress-5.4-zh_CN.tar.gz .
[root@centos7 htdocs]# tar xvf wordpress-5.4-zh_CN.tar.gz
[root@centos7 htdocs]# setfacl -Rm u:apache:rwx wordpress
5.2 访问安装
访问:http://192.168.214.20/wordpress/readme.html
照着网页安装即可
5.3 安装完成后解除权限
[root@centos7 htdocs]# setfacl -Rb wordpress
主题更新需添加代码
[root@centos7 wordpress]# vi wp-config.php
#末尾加
/** Override default file permissions */
if(is_admin()) {
add_filter('filesystem_method', create_function('$a', 'return "direct";' ));
define( 'FS_CHMOD_DIR', 0751 );
}
centos6编译PHP报错:
checking for sqlite3 > 3.7.4… no
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
Requested ‘sqlite3 > 3.7.4’ but version of SQLite is 3.6.20
yum install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-1.noarch.rpm
yum install sqlite-devel