PHP on CentOS ,LAMP and wordpress

http://php.net/manual/zh/install.windows.php

https://www.unixmen.com/install-wordpress-centos-7-linux/ (Very useful)

https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp (Very useful)

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-centos-7

https://www.tipsandtricks-hq.com/how-to-uninstall-and-reinstall-wordpress-245 (update wp-config.php and then go to wp-admin/install.php page)

https://codex.wordpress.org/Using_Themes#Get_New_Themes

https://www.tipsandtricks-hq.com/how-to-fix-the-unable-to-create-directory-error-in-wordpress-5264 (this happend, and might also related to faliure to install themes online)

https://httpd.apache.org/docs/2.2/vhosts/examples.html

下载中文版: https://cn.wordpress.org/

To check whether PHP got installed on your machine:

# rmp -qa | grep -i php (looks it looking for installed packages containing "php")

Or

# locate php (looks like it's searching files with name containing "php" )

#Install Apache on CentOS 7
sudo yum -y install httpd

sudo systemctl start httpd

sudo systemctl enable httpd

#Test Apache and use browser to check the default website by apache
sudo systemctl status httpd
#installing MySql/MariaDB
sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation
#install PHP
sudo yum -y install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl
#install Wordpress
sudo yum install zip unzip
sudo wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo cp -avr wordpress /var/www/html
sudo chmod -R 775 wordpress
sudo chown apache:apache wordpress

Quetions:

PHP configuratioin files?

Apache configuration files?

Answer: /etc/httpd/conf/httpd.conf

How to host multiple websites on apache in centos?

https://www.mysysadmintips.com/linux/servers/586-host-multiple-websites-on-apache-in-centos

This tutorial shows how to setup Apache Virtual Hosts in CentOS 7. This is useful if you want to host more than one website on a single CentOS web server. For instructions on how to setup Apache, PHP, and SQL database on CentOS 7, check this article.

Setup folder structure for your websites

We are going to create 2 folders for each website. The first will hold HTML and other content, second - log files.

/var/www/sites/domain1/html

/var/log/httpd/domain1

/var/www/sites/domain2/html

/var/log/httpd/domain2

/var/www/sites/domain3/html

/var/log/httpd/domain3

Log files will be stored in var/log/httpd/... subfolders, which is the default place to store log files in Linux. People often store Apache log files in /var/www/ subfolders, but in CentOS with SELinux enabled this can cause access denied errors. This can be fixed with chcon command, but I prefer to store all my log files in /var/logs...

You can also place index.html files with some sample text in each html directory which we'll use later for testing.

Create folder structure for virtual host files

Create folders:

/etc/httpd/sites-available

/etc/httpd/sites-enabled

sites-available will hold virtual host config files for websites that are configured, but not necessary enabled. These files are actually ignored when Apache starts, but this system allows to easily disable and enable websites without having to delete or create new virtual host files every time we want to take a site offline and put it back online.

sites-enabled will hold symbolic links to virtual host files inside sites-available that are enabled. They will be loaded when Apache starts.

Add sites-enabled to Apache config

Open file /etc/httpd/conf/httpd.conf and at the very end of the file add following text:

IncludeOptional sites-enabled/*.conf

This will tell Apache to look for virtual host files with extension .conf in sites-enabled directory.

Create Virtual Host files

In directory /etc/httpd/sites-available create config files for each website (domain1.conf, domain2.conf, etc.) with following content:

<VirtualHost *:80>

ServerName www.domain1.com

ServerAlias domain1.com

DocumentRoot /var/www/sites/domain1/html

ErrorLog /var/log/httpd/domain1/error.log

CustomLog /var/log/httpd/domain1/access.log combined

</VirtualHost>

Change domain1 to match your domain names and directories you created previously.

If Apache can't match the requested domain to any of the virtual hosts, the first (alphabetically) virtual host site will be loaded. If you want to have more control over this, you can create a dedicated virtual host (i.e. 00_default) that will be loaded only when no matching virtual host exist. ServerName and ServerAlias should not match any of your domains (i.e. example.com) The name starts with 00 so that it is always the first virtual hosts alphabetically. The site linked to this default virtual host could show an error message, redirect to another domain, etc.

Edit httpd.conf

Edit the main Apache configuration file /etc/httpd/conf/httpd.conf according to your requirements.

In my particular case, I made following changes:

Set webmaster email address:

ServerAdmin administrator@domain.com

Set main document root:

DocumentRoot "/var/www/sites"

Configure main document root:

<Directory "/var/www/sites">

AllowOverride All

Options FollowSymLinks

</Directory>

AllowOverride All - is required if you intend to use .htaccess files for directory level configuration. By default, this is set to None, in which case .htaccess overrides would be ignored.

Options -Indexes - prevents directory listing.

Enable Virtual Hosts

To enable websites, we need to create symbolic links in /etc/httpd/sites-enabled pointing to appropriate config files in sites-available. To do this, run:

ln -s /etc/httpd/sites-available/domain1.conf /etc/httpd/sites-enabled/domain1.conf

For changes to take effect we need to restart Apache:

systemctl restart httpd.service

To disable a particular website, simply delete relevant symbolic link (or change the extension) and restart Apache.

Before going live, you can test if everything is working locally. To do this, edit the hosts file on your client machine to point domains configured inside virtual hosts to the CentOS web server's IP address. If everything was setup properly, pointing your web browser to one of the domains should load index.html file from an appropriate /var/www/sites/... directory.

2015.01

CentOS 7


以下为最近学习小结:

问题一: 创建新用户并设置密码

解决方案:

创建新用户 adduser <username>

设置密码 passwd <username>

问题二:使用新用户登录,执行 "sudo yum update",没有sudo 权限,得到错误: “<user> is not in the sudoers file. This incident will be reported.”

解决方案:http://www.cnblogs.com/evasnowind/archive/2011/02/04/1949113.html

一、$whereis sudoers -------找出文件所在的位置,默认都是/etc/sudoers

二、 #chmod u+w /etc/sudoers 以超级用户登录su -root ,修改文件权限即添加文件拥有这的写权限 限,ls -al /etc/sudoers 可以查看原文件的权限。

三、vim /etc/sudoers 编辑文件,在root ALL=(ALL)ALL行下添加XXX ALL=(ALL)ALL,XXX为你的用户名。添加方法:找到root行,按下”i“键进入编辑模式添加即可!编辑好后esc键进入一般模式,“:wq"保存退出!

最后, #chmod u-w /etc/sudoers 回到文件的原权限!

问题三: 没有安装VIM

解决方案: # yum -y install vim*

操作4: Install MySQL on CentOS-7

https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7

操作5: 本机登录mysql创建帐户、密码及新的数据库

> mysql -u root

> create user '<username>'@'%';

> SET Password for '<username>'@'%' = Password('mypassword');

此时该用户已经可以远程登录了!

TODO: set password for mysql for root account.

> create database <db-name>;

> grant all privileges on <dbname>.* to '<user>'@'localhost';

> select current_user();

到此,数据库、连接用户名密码已经配置完成!

操作6:尝试直接使用IP或域名访问此服务器

[slin@iZwz9h33t7dnsizrtbp8yhZ www]$ wget http://www.linsw.com

--2017-06-14 10:52:14-- http://www.linsw.com/

Resolving www.linsw.com (www.linsw.com)... 120.77.38.243

Connecting to www.linsw.com (www.linsw.com)|120.77.38.243|:80... failed: Connection refused.

操作6-1: 尝试安装nodejs, 分别使用80与非80端口,来看一下服务器上的nodejs能否正常工作

> sudo yum install nodejs

准备以下内容给 nodetest /index.js文件:

var port = (process.env.port || 8080);

if (process.argv.length > 2) {

for (var i = 2; i < process.argv.length; i++) {

console.log(process.argv[i]);

var m = /port=(\d+)/.exec(process.argv[i]);

if (m) {

port = m[1];

}

}

}

var http = require('http');

var server = http.createServer(function(req, res, next){

console.log('got request:' + req.url);

res.writeHead(200, {'Content-Type': 'text/html'});

res.end('hello world from shawn. NodeJS');

});

/*server.on('listen', function(){

var addr = server.address();

var bind = typeof addr === 'string'

? 'pipe ' + addr

: 'port ' + addr.port;

console.log(bind);

});

*/

var port = 80;

server.listen(port);

server.on('error', function(err){

console.log(err);

});

console.log('server is listening on port: ' + port);

> sudo nodejs ~/www/nodetest/index.js

说明機器上沒有别的进程在使用80端口;那接下来应该需要安装apache httpd服务。

操作7:安装apache, php

http://www.cnblogs.com/swlin/p/PHP.html

> sudo yum -y install httpd

> sudo systemctl enable httpd

> sudo systemctl start httpd

至此,httpd服务成功安装,并可以通过域名成功访问,并显示一个默认的测试页面。

> sudo systemctl status httpd

操作7-2:

#install PHP

sudo yum -y install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl

#install Wordpress

sudo yum install zip unzip

sudo wget https://wordpress.org/latest.zip

sudo unzip latest.zip

sudo mkdir /var/www/websites/

sudo cp -avr wordpress /var/www/websites/mywebsite

sudo chmod -R 775 mywebsite

sudo chown apache:apache mywebsite

操作8: rewrite module

打开httpd.conf(在那里? APACHE目录的CONF目录里面),用文本编纂器打开后,查找

(1)

Options FollowSymLinks

AllowOverride None

改为

Options FollowSymLinks

AllowOverride All

(2)去掉下面的注释

LoadModule rewrite_module modules/mod_rewrite.so

(3) 修改文件 /etc/httpd/virutal_hosts/<your-host-file>.conf,在<VirtualHost *:80>节点里面增加如下内容

<Directory /var/www/websites/dev_gmpflex_com>

Options Indexes FollowSymLinks MultiViews

AllowOverride All

Order allow,deny

allow from all

</Directory>

操作9:解决wordpress安装主题时一直提示需要FTP用户名及密码,其它完全不需要安装 FTP SERVER的:

解决方案:

http://jingyan.baidu.com/article/4f34706efc1237e387b56da4.html

第一,如果我们安装的是lnmp一键安装包,那可以使用。授权组来解决。

chown -R 775 /home/wwwroot/my-website-name(修改成网站域名目录)

第二,如果是其他的可以使用在wp-config.php文件中添加脚本方式。

define("FS_METHOD","direct");

define("FS_CHMOD_DIR", 0777);

define("FS_CHMOD_FILE", 0777);

上述脚本添加到文件最后面就可以。

但是,之后我又遇到问题: 安装失败,无法创建目录。

操作9-1: chmod -R 777 /var/www/ (这个搞定问题,但不知道直接到本人使用的/var/www/websites/行不行?)

=================

centos new user: slin/ABcd1234

如果您的.htaccess文件可写,我们即会自动帮您完成,但其目前不可写,所以以下是您需要加入您的.htaccess文件中的mod_rewrite规则。点击文本框并按CTRL + a来全选。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

http://blog.sina.com.cn/s/blog_6452c6b40100qr7m.html