CentOS6.5 Installing Lamp

Centos install LAMP

System: Centos 6.5
Apache 2.4 + PHP 7.2 + Mysql 5.7

Preparation work

  1. centos check version

check centos version How to Check CentOS Version

cat /etc/redhat-release
cat /etc/ centos-release
cat /etc/os-release
  1. Update yum source
[[emailprotected] tmp]$ sudo yum update< /pre> 

Using yum to install Apache

[[emailprotected] tmp]$ sudo yum install httpd

Install and check the version

[[email protected] tmp]$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13

Enable apache automatic start

[[emailprotected] tmp]$ sudo chkconfig httpd on

< h2 id="apahce-related commands">Apahce related commands

sudo service httpd start #start apache
sudo service httpd stop # disable apache
sudo service httpd restart # restart apache< br />sudo apachectl configtest #Test whether the syntax of the configuration file is correct

Open Apache’s common 80,443 port

Open A Pache's 80, 443 port

Execute command:

sudo /sbin/iptables -I INPUT -p tcp - dport 80 -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT

Save the command to enter the open port number statement before

sudo /etc/rc.d/init.d/iptables save

View the open port command

sudo service iptables status
sudo service iptables restart #restart iptables command

Configure Apache configuration file

Edit /etc/httpd/conf/httpd.conf, prohibit List the file directory and access the file in the format of .env (Laravel configuration file)

Execute the command:

sudo vim /etc/httpd/conf/ httpd.conf

Find and change Options Indexes FollowSymLinks to Options FollowSymLinks, prohibit listing file directories

Add before of the current group


Order allow, deny
Deny from all

No access to .env file

Finally httpd.conf< /code> all contents of the node are similar

## This should be changed to w hatever you set DocumentRoot to.# Options FollowSymLinks AllowOverride All Order allow,deny Allow from all
Order allow,deny
Deny from all< br />

[[emailprotected] tmp]$ apachectl configtest
httpd: apr_sockaddr_info_get() failed for centos
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK

If there is an error of apr_sockaddr_info_get(),

  1. Confirm the value set in etc/sysconfig/network
$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos
  1. /etc/hosts append
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos< br />::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  1. /etc/httpd/conf/httpd.conf modify
#ServerName www.example. com:80
ServerName centos:80

install Mysql 5.7

Update and install the yum source of mysql

  1. Download the source package from the official website
[[emailprotected] tmp]$ wget http://dev.mysql .com/get/mysql57-community-release-el6-7.noarch.rpm
  1. rpm install mysql yum source
[[emailprotected] tmp]$ sudo rpm -Uvh mysql57-community-release-el6-7.noarch.rpm
  1. Open the mysql-community.repo file to view the content about mysql , Make sure the value of enable of [mysql57-community] is 1
[[emailprotected] tmp]$ sudo vim /etc/yum.repos.d/mysql-community.repo

install Mysql

Execute the install mysql command

[[email Protected] tmp]$ sudo yum install mysql-community-server

When installing, there will be two confirmations, enter y, press Enter to confirm

Start the service after completion

[[emailprotected] tmp]$ sudo service mysqld start

After the startup is complete, View the password generated temporarily for the root user

$ sudo grep "password" /var/log/mysqld.log< br />2018-08-08T02:59:58.687152Z 1 [Note] A temporary password is generated for [email protected]: 3fF4?tujHrfl
2018-08-08T03:00:04.204111Z 2 [Note] Access denied for user'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)

The first line [emailprotected]: 3fF4?tujHrfl This is the root password of the database p>

Modify the initialization password

For the safety of Mysql, it is recommended to modify the initial password of root

Execute the command:

[ [email protected] tmp]$ sudo mysql_secure_installation
  1. After executing the above command, you need to enter the password generated temporarily by root, which can be found in the previous step
  2. < li>After entering the current password of root, you need to enter the new root password twice

  3. Change the password for root? ((Press y|Y for Yes, any other key for No) : Reply to y to confirm the modification of root user’s password
  4. Do you wish to continue with the password provided? (Press y|Y for Yes, any other key for No) : Reply to y to continue the following steps
  5. Remove anonymous users? (Press y|Y for Yes, any other key for No): Reply to y to remove anonymous users (in the production environment, you should delete it)
  6. Dis allow root login remotely? (Press y|Y for Yes, any other key for No) : Reply to y to disable root remote login
  7. < li>Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Reply to y to remove the test database

  8. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Reply to y to reload privilege tables now

The mysql configuration file is by default in /etc/my.cnf

Enable Mysql Autostart

 [[email protected] tmp]$ sudo chkconfig mysqld on

Install PHP 7.2

If you have installed PHP before, you need to uninstall it.< /p>

[[email protected] tmp]$ sudo yum remove php* php-common

update and install yum of PHP Source

[[email protected] tmp]$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Modify yum source

Execute command:

#Install third-party source epel-release
[[emailprotected] tmp]$ sudo yum install epel-release
[[email Protected] tmp]$ sudo vi /etc/yum.repo sd/remi.repo

Change the value of enabled under the [remi] node from 0 to 1.

List the files in the /etc/yum.repos.d folder

[[emailprotected] tmp]$ ls -l /etc /yum.repos.d
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo epel-testing.repo mysql-community-source.repo remi-glpi92.repo remi-glpi94.repo remi-php70 .repo remi-php72.repo remi.repo
CentOS-Debuginfo.repo CentOS-Media.repo epel.repo mysql-community.repo remi-glpi91.repo remi-glpi93.repo remi-php54.repo remi-php71 .repo remi-php73.repo remi-safe.repo

Through the above command results, you can modify the corresponding version according to the PHP version you need to install remi-php.repo’s file

Because I need to install the 7.2 version, the edit is remi-php72.repo

Execute the command:

sudo vim /etc/yum.repos.d/remi-php72.repo

Set the [remi-php72] node under the < The value of code>enabled is changed from 0 to 1.

yum list php

List all installable software php lists. If it shows 7.x, there is no problem.

Start to install php

sudo yum install php php-cli php-curl php-json php-pdo php-mysql php-gd php-bcmath php-xml php-mbstring php-mcrypt php-redis php-crypto

During the installation process, there will be multiple confirmations, enter y and press Enter to confirm the installation

Installation is complete After that, you can view the php version through php -v or php -m to view the installed extensions

Configure PHP

By default, the configuration file is in /etc/php.ini

date.timezone = Asia/Shanghai
upload_max_filesize = 20M
post_max_size = 20M
#The generation environment needs to be turned off to display error messages
display_errors = Off
#Do not display PHP information in the HTTP return header
expose_php = Off

Install Composer

Install according to Command-line installation

cd /tmp
php -r "copy('https://getcomposer.org/installer ','composer-setup.php');"
# If the installed versions are not the same, sha384 will verify the failure.
php -r "if (hash_file('sha384','composer-setup .php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3 f0fe57a54d8f5') {echo'Installer verified';} else {echo'Installer corrupt'; unlink('composer-setup.php');} echo PHP_EOL;"

php composer-setup.php< br />
php -r "unlink('composer-setup.php');"
# Install composer globally
sudo mv composer.phar /usr/local/bin/composer
# View composer version
composer -V

Redis installation (optional)

Enter Redis, a different version is required , You can choose from the official website page

share picture

In the framed part of the above picture, you can see the link when you put the mouse on it, right-click on the download link, and select "Copy Link Address (E)" (the right-click menu option of Chrome browser)

  1. Download the installation package
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
  1. Unzip and install
tar -xzf redis-4.0.14.tar.gz
cd redis-4.0.14
sudo make
sudo make install

Redis has no other external dependencies, and the installation process is very simple. After compilation, you can find several executable programs in the src folder of the Redis source code directory. After installation, you can find the redis executable file you just installed in the /usr/local/bin directory. As shown below

share picture

    < li>Start redis

Directly execute the redis-server command to start it

With the startup script, in /etc/ Create a file of redis_port number under init.d/ folder, such as redis_6379

  1. Create folder< /li>
# Create a folder to store redis configuration
sudo mkdir -p /etc/redis
# Create a folder to store redis data, port number, default is 6379< br />sudo mkdir -p /var/redis/port number
  1. Modify configuration file
# Enter to download redis-4.0.14.tar.gz File directory, copy the file configuration template to /etc/redis, and rename it to `6379.conf`
sudo cp redis-4.0.14/redis.conf /etc/redis/6379.conf

First copy the configuration file template (redis-4.0.14/redis.conf) to the /etc/redis directory, name it with the port number (such as "6379.conf"), and then check it according to the following table Part of the parameters are edited.

Parameter Value Description
daemonize yes Make Redis run in daemon mode (by noChange to yes)
pidfile /var/run/redis_port No. pid Set the PID file location of Redis (the default is already /var/run/redis_6379.pid, no need to modify)
port Port number Set the port number that Redis listens to (the default is 6379, no need to modify)
dir /var/redis/port number Set the storage location of persistent files, the default is dir ./, modified to /var/redis/6379
  1. Create< code>/etc/init.d/redis_6379 file and configure it
sudo vim /etc/init.d/redis_6379

In the vim editor Fill in the following content

#!/bin/bash
# /etc/init.d/redis_6379

### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $remote_fs $syslog
# R equired-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis server script
# Description: This service is used to manage redis-server start or stop
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis- server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis /${REDISPORT}.conf"

case "$1" in
start)
if [-f $PIDFILE ];
then
echo " $PIDFILE exists,redis-server is already running or crashed"
else
echo "Starting Redis Server"
$EXEC $CONF
fi
;;
stop)
echo "Stopping Redis Server"
#killall redis server
kill $(ps aux | grep -m 1 "${EXEC}" | awk'{ print $2 }')
;;
*)
echo "Usage: service redis_6379 start|stop"
exit 1
;;
esac
exit 0

After saving, you can start or stop redis-server with the following commands

 # Start redis server
sudo service redis_6379 start
# Stop redis server
sudo service redis_6379 stop
  1. Enable redis-server startup
  2. sudo chkconfig redis_6379 on

    List the startup information of redis

    chkconfig --list | grep "redis"

    If it appears in the list

    redis_6379 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    It means that the boot setting is successful

    Deploying Laravel to the optimization of the build environment

    Install package

    composer install --optimize-autoloader --no-dev

    < blockquote>

    Among them, --optimize-autoloader means to generate an optimized autoloader. Although the generation process may be slower, the result is improved runtime efficiency. --no-dev means that the extension package declared by require-dev in composer.json is not installed. We don't need these development dependencies in the production environment.

    Create a cache

    php artisan optimize
    php artisan api:cache
    php artisan route:cache
    php artisan view:clear
    php artisan config:cache

    supervisor (optional)

    Because Centos 6.5 is installed via Yum, the version of supervisor is 2.1

    You can query the information of supervisor through yum info supervisor

    If it has been installed through the yum command< code>supervisor 2.1, you can uninstall it through yum remove supervisor*.

    Install supervisor

    # View python version
    [[emailprotected] tmp]$ python -V
    Python 2.6.6

    Specify the installation of supervisor 3.1.3 version, this version can use python2.6, it can be used directly after installation. You can pip install supervisor==3.1.3 or easy_install supervisor==3.1.3

    I installed it through the following:

    < pre>easy_install supervisor==3.1.3

    Configuration

    1. Generate configuration file
    echo_supervisord_conf> /etc /supervisord.conf
    1. Edit configuration file
    sudo vim /etc/supervisord.conf

    Find

    ;[include]
    ;files = relative/directory/*.ini

    Change to

    [include]
    ;files = relative/directory/* .ini
    files = /etc/supervisor/conf.d/*.conf

    After saving, create the included directory

    sudo mkdir -p /etc/supervisor/ conf.d

    The configuration files for future work can be placed in this directory

    1. Start supervisord

    Use /etc/supervisord.conf configuration file to start the supervisord service

    /usr/bin/supervisord -c /etc/supervisord.conf
    1. Notes on commonly used commands
    #View status
    supervisorctl status
    # Add or modify the configuration file, need to reload
    supervisorctl reload
    # Restart all
    supervisorctl restart all

    Problems encountered

    Apache error: default virtualhost overlap on port 443 or 80

    Apache error: _default_ virtualhost overlap on port 443 or 80, modify the httpd.conf file and add it around line 1002

    NameVirtualHost *:80
    #If you need to use https, Need to add port 443
    NameVirtualHost *:443

    You don’t have permission to access /index.html on this server.

    When DocumentRoot is confirmed, such as /home/testdomain/public_html the third level folder and index.html is 755 (drwxrwxr-x), the access is still You don't have permission to access /index.html on this server.

    < p>You can check the selinux status of Centos. After trying to close SELinux access, you should be able to access it

    Check SELinux status

    < pre>[[email protected] tmp]$ getenforce
    Enforcing #is enabled, if it returns Disabled, it is already disabled

    temporary shutdown

    sudo setenforce 0

    Permanently off

    vi /etc/selinux/config

    Set SELINUX=enforcing is changed to SELINUX=disabled
    After setting, it needs to be restarted to take effect

    References
    1. Upgrading PHP7, MySQL5.7 under CentOS6.5. The main reference for the text description of the installation part of the article.
    2. Centos 6.5 firewall opens the designated port and sets up iptables quickly and easily
    3. Centos view port occupancy And open the port command to open the content rules of the port, but the new rule must be placed in front of the line at the beginning of -A FORWARD, otherwise restarting iptables will not take effect
    4. CentOS / httpd> Starting httpd: httpd: apr_sockaddr_info_get() failed for [hostname].localdomain centos httpd restart display httpd: apr_sockaddr_info_get() failed for solution reference
    5. CentOS 7. X Close SELinux SELinux close reference
    6. Redis installation under CentOS redis installation reference
    7. Linux chkconfig instructions are very helpful to understand the use of chkconfig
    8. (Clear cache when online ) Laravel 5.1 program performance optimization (configuration file)-Brief Book and Easy Deployment of Laravel Applications | “10. Manual Deployment-Necessary Optimization of Production Environment”
    9. centos6.5 install supervisor Centos 6.5 install supervisor 3 The solution and the steps to install supervisor under centos are detailed in detail

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4861 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.