安装
Introduction
The LAMP server is the cornerstone of Linux web hosting. In the early days of dynamic web content LAMP was what won Linux the crown in the web space, and it still is responsible for powering a very large portion of the Internet's sites.
If you're looking to set up a LAMP stack to host your website, it'd be hard to find a better option to build it on than Debian Stretch. Debian is, after all, well known for its stability, security, and massive package repositories, and Stretch is certainly no exception.
MariaDB(MySQL)
To get started, install and setup the database portion of the stack, MariaDB. Traditionally, the "M" in LAMP stands for MySQL. However, MariaDB is a drop-in replacement that isn't controlled by Oracle, so it tends to be a better option.
To install MaridaDB on Stretch, just use apt to install the packages.
apt install mariadb-client mariadb-server
During the install process, you will be prompted to create a root password for MariaDB. Make sure to choose something as secure as possible, since it will determine, in part, the security of your databases.
Now that the MariaDB server is installed, you can log in as your root user and set up a regular user and a database.
mysql -u root -p
MariaDB will then prompt you for the root password that you just set up.
Creating a database is fairly simple. Just run the following.
CREATE DATABASE newdb;
You need to create a regular user now to use the database. It is an absolutely terrible idea to use the root user for anything other than managing MariaDB as a whole.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'userpassword';
That command creates a regular user that can sign in locally and set that user's password.
In order for that user to be able to use the database that you just created, you need to grant them privileges on it. Since this is a general purpose user for managing everything on this database, it will be given all privileges.
GRANT ALL PRIVILEGES ON newdb.* to 'username'@'localhost';
Once that's done, flush all privileges from the console and exit.
FLUSH PRIVILEGES;
quit
That's all for the database. Certainly, you can customize any portion of this as you need.
PHP
The next step in getting the LAMP server set up is installing PHP. In the LAMP stack, PHP powers the web content and interacts with the database. To install PHP on Debian Stretch, run the following line.
apt install php7.0 php7.0-mysql
That's really all that you need. PHP is now ready to use.
Apache
The Apache web server is extremely powerful and can be extremely easy to set up or ridiculously difficult, depending how in-depth you wan to go. Because this is just a simple guide, it's going to follow the quickest path for getting a basic server set up.
So, install both the Apache server and the module for PHP support.
apt install apache2 libapache2-mod-php7.0
Testing Your Server
By default, Apache will server the contents of /var/www/html and will look first for a file called index.php or index.html. Create that file, and place the following line of code in it.
<?php phpinfo(); ?>
Open up your browser and type in localhost in your address bar. If you aren't doing this locally, type your domain name or IP. You should see a long table containing information about your PHP install. At this point, your sever is officially working.
If you want an easy way to manage your database through a graphical web interface, you can install an application called, phpmyadmin. It allows you to manage your database using PHP through your LAMP server. To install it on Stretch, just pull it with apt.
apt install phpmyadmin
Once the package installs, you can navigate in your browser to localhost/phpmyadmin You will be greeted with a login screen that will accept your database credentials and finally, an interface to work with your database.
Closing Thoughts
Your LAMP server is now ready to go. Of course, there are tons of other options, and if you plan to use this as a public facing server, you may want to look into more security options for Apache. That said, this LAMP server can run everything from your custom PHP application to popular solutions like WordPress and even development frameworks like Laravel.
Create Your Database
Once your server is ready, you can set up the database where you're going to store everything from WordPress. Log in to MariaDB as your root user.
mysql -u root -p
Once you're signed in, create a regular user for WordPress.
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'userpassword';
Now, create your WordPress database.
MariaDB [(none)]> CREATE DATABASE wp_database;
Finally, grand your user all permissions on the database.
MariaDB [(none)]> GRANT ALL ON wp_database
.* TO wpuser
@localhost
;
Flush your privileges and exit.
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
Download And Unpack WordPress
Here's where WordPress makes its entrance. You can either head over to the
https://wordpress.org and download it that way, or just use wget. The URL never changes, so wget will always work.
wget https://wordpress.org/latest.tar.gz
Unpack WordPress using tar.
$ tar xpf latest.tar.gz
The resulting folder will be wordpress. It contains the entire WordPress install. How and where you copy it is entirely up to you and depends on your web server configuration. The example provided covers the most basic possible install on Apache.
rm -rf /var/www/html
cp -r wordpress /var/www/html
If you're using Nginx, you probably just want to place the folder in /var/www/ as it is, and point your configuration at it. When WordPress is where you want it, change the permissions and ownership to improve security and grant your webserver proper access.
chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod 755 {} ;
find /var/www/html -type f -exec chmod 644 {} ;
Certainly, if your webserver is configured to run under a different user, change the ownership to that one.
WordPress Setup
ip:port/wp-admin/install.php进入WordPress安装界面。
WordPress's web-based installer handles the rest of the process. So, open up a web browser and navigate to the domain name or IP address of your server.
The first screen that you'll see will just greet you. When you click through to the next screen, WordPress will prompt you for your database information. Enter everything that you set up.
The final screen will ask you for information about your site. Enter everything as it pertains to the website that you're setting up. After that screen, the WordPress installer will run and set up everything. When it finishes, it will present you with the WordPress login screen. You can then log in and gain access to your admin interface.
Closing Thoughts
Congratulations! You have a working WordPress installation on Debian Stretch. If you're running this server in production, make sure that you properly secure it, and that includes WordPress itself.
WordPress日志开启:
配置文件说明
需要修改的配置文件是WordPress根目录下的 wp-config.php 文件,记得以 UTF-8 无 BOM 格式编码。
开启调试模式
设置调试模式要修改的是 WP_DEBUG 这个常量,默认是:
define(‘WP_DEBUG’, false);
需要开启时找到这行并修改为:
define(‘WP_DEBUG’, true);
即可,false代表关闭,true代表开启。
输出调试信息
如果需要输出调试信息到日志文件(前提是开启了调试模式),在下面加一句
define(‘WP_DEBUG_LOG’, true);
即可,调试信息会被保存到 wp-content 目录下 debug.log 文件。
不在页面显示
如果并不需要在页面显示调试信息,那么你可以加上这一句
define(‘WP_DEBUG_DISPLAY’, false);
来实现。这个一般配合 WP_DEBUG_LOG 使用,即只输出日志不在页面显示。
修改静态脚本
如果你需要调试WordPress的CSS和Javascript代码,那么你可以加这一句
define(‘SCRIPT_DEBUG’, true);
来调用完整版代码(默认调用的都是压缩版,压缩版根本没法看,通常都是修改完整版代码)。
记录数据查询
如果你需要记录页面都进行了哪些数据库查询,那么你可以加这一句
define(‘SAVEQUERIES’, true);
来实现,然后读取全局变量 $wpdb->queries 就可以知道有哪些查询了。
WordPress日志输出:tailf /var/www/html/wp-content/debug.log
官方参考资料
http://codex.wordpress.org/Debugging_in_WordPress
参考链接:
https://linuxconfig.org/how-to-install-a-lamp-server-on-debian-9-stretch-linux
https://linuxconfig.org/how-to-install-wordpress-on-debian-9-stretch-linux
https://cloud.tencent.com/document/product/213/8044
域名解析