前言
LAMP是 linux Apache MySQL PHP的简写,即把Apache MySQL PHP 安装在linux系统上,组成一个环境来运行PHP网站。这里的Apache是httpd服务。这些可以安装在一个机器上,也可以安装在多台机器上,但是httpd和PHP安装在一台机器上(php作为httpd的一个模块存在的。 他们两者必须要在一起,才能实现效果)
安装配置apache+php服务
apache和php安装命令
yum install httpd httpd-devel
yum -y install epel-release
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis
php配置优化
[global]
pid = /var/run/php-fpm/php-fpm.pid
error_log = /opt/servicelogs/php-fpm/error.log
daemonize = yes
include=/etc/php-fpm.d/*.conf
[www]
listen = /var/run/php-fpm/php-fpm.sock
;listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
listen.backlog = 16384
user = nginx
group = nginx
pm = static
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 35
pm.max_requests = 10000
request_terminate_timeout = 180
request_slowlog_timeout = 30
slowlog = /opt/servicelogs/php-fpm/www-slow.log
;access.log = /opt/servicelogs/php-fpm/access.$pool.log
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{seconds}d %{megabytes}M %{user}C%%"
ping.path = /php5fpm-ping
pm.status_path = /php5fpm-status
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 256M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
pcre.jit=0
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[Assertion]
zend.assertions = -1
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[curl]
[openssl]
[opcache]
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.validate_timestamps=0
opcache.file_cache=/tmp
php安装后测试
php -v
php --modules
整体功能测试
echo '<?php phpinfo(); ?>' > index.php
通过浏览器访问出现下图界面,即php安装正常
安装配置mysql数据库服务
清除默认的maradb
yum list installed | grep mariadb
yum -y remove mariadb-libs.x86_64
安装依赖包
yum install -y perl.x86_64 libaio.x86_64 net-tools.x86_64 perl-Compress-Raw-Bzip2 perl-Compress-Raw-Zlib perl-DBI perl-IO-Compress perl-Net-Daemon perl-PlRPC
下载mysql安装包,并安装
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.6/MySQL-client-5.6.51-1.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.6/MySQL-server-5.6.51-1.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.6/MySQL-devel-5.6.51-1.el7.x86_64.rpm
yum localinstall MySQL-*
配置 mysql
vim /etc/my.cnf
配置内容
[mysql]
port = 3306
socket = /data/mysql/mysql.sock
prompt = "\\u@\\h \\D \\R:\\m:\\s [\\d]>
tee = /data/logs/mysql/query.log
[mysqld]
user = mysql
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/mysql.pid
key-buffer-size = 32M
max-allowed-packet = 16M
max-connect-errors = 10000
skip-name-resolve
sysdate-is-now = 1
datadir = /data/mysql/
log-bin = /data/mysql/mysql-bin
sync-binlog = 1
tmp-table-size = 32M
max-heap-table-size = 32M
max-connections = 500
thread-cache-size = 50
open-files-limit = 9999
table-definition-cache = 4096
table-open-cache = 4096
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 512M
log-error = /data/logs/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /data/logs/mysql/mysql-slow.log
创建目录,修改目录权限
mkdir -p /data/mysql/ /data/logs/ /data/logs/mysql/
chown -R mysql:mysql /data/logs/mysql/
数据库初始化
mysql_install_db --user=mysql --datadir=/data/mysql
systemctl start mysql
/usr/bin/mysqladmin -u root password -S /data/mysql/mysql.sock
查看mysql服务状态
systemctl status mysql
安装完成
安装配置wordpress博客
下载安装包
wget https://wordpress.org/wordpress-5.6.tar.gz
wget https://wp101.net/wordpress-5.6.tar.gz
解压
tar xvf wordpress-5.6.tar.gz
sudo mv wordpress /var/www/html/mywordpress/
更改代码目录权限
chown -R apache:apache /var/www/html/mywordpress/
修改配置文件httpd服务的配置
vim /etc/httpd/conf/httpd.conf
配置内容
<VirtualHost *:80>
ServerName www.mywordpress.com
DocumentRoot /var/www/html/mywordpress
<Directory "/var/www/html/mywordpress">
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php
#ErrorDocument 404 /404.html
ErrorLog /var/log/httpd/mywordpress.err.log
CustomLog /var/log/httpd/mywordpress.acc.log combined
</VirtualHost>
重启httpd服务,使配置生效
systemctl restart httpd
建库授权
CREATE DATABASE `wpdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
create user 'wpuser'@'localhost' IDENTIFIED BY 'wpuser123';
grant all privileges on wpdb.* to 'wpuser'@'localhost';
flush privileges;
绑定域名到指定IP
echo '192.168.88.2 www.mywordpress.com' >> /etc/hosts
通过浏览器访问,并配置博客
FAQ
关闭自动更新
//wp-config.php
define('AUTOMATIC_UPDATER_DISABLED',true);
重定向次数过多
# 修改
vim wp-config.php
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
评论 (0)