Centos install LAMP
System: Centos 6.5
Apache 2.4 + PHP 7.2 + Mysql 5.7
Preparation work
- centos check version
check centos version How to Check CentOS Version
cat /etc/redhat-release
cat /etc/ centos-release
cat /etc/os-release
- Update yum source
[[emailprotected] tmp]$ sudo yum update< /pre>Using yum to install Apache
[[emailprotected] tmp]$ sudo yum install httpdInstall and check the version
[[email protected] tmp]$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13Enable 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 correctOpen Apache’s common 80,443 port
Open A Pache's
80
,443
portExecute command:
sudo /sbin/iptables -I INPUT -p tcp - dport 80 -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPTSave the command to enter the open port number statement before
sudo /etc/rc.d/init.d/iptables saveView the open port command
sudo service iptables statussudo service iptables restart #restart iptables commandConfigure 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.confFind
and change Options Indexes FollowSymLinks
toOptions FollowSymLinks
, prohibit listing file directoriesAdd before
of the current group
Order allow, deny
Deny from allNo access to
.env
fileFinally
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 OKIf there is an error of
apr_sockaddr_info_get()
,
- Confirm the value set in
etc/sysconfig/network
$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos
/etc/hosts
append127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos< br />::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
/etc/httpd/conf/httpd.conf
modify#ServerName www.example. com:80
ServerName centos:80install Mysql 5.7
Update and install the yum source of mysql
- Download the source package from the official website
[[emailprotected] tmp]$ wget http://dev.mysql .com/get/mysql57-community-release-el6-7.noarch.rpm
- rpm install mysql yum source
[[emailprotected] tmp]$ sudo rpm -Uvh mysql57-community-release-el6-7.noarch.rpm
- Open the
mysql-community.repo
file to view the content about mysql , Make sure the value ofenable
of[mysql57-community]
is1
[[emailprotected] tmp]$ sudo vim /etc/yum.repos.d/mysql-community.repoinstall Mysql
Execute the install mysql command
[[email Protected] tmp]$ sudo yum install mysql-community-serverWhen installing, there will be two confirmations, enter
y
, pressEnter
to confirmStart the service after completion
[[emailprotected] tmp]$ sudo service mysqld startAfter 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
- After executing the above command, you need to enter the password generated temporarily by
root
, which can be found in the previous step< li>After entering the current password of
root
, you need to enter the new root password twiceChange the password for root? ((Press y|Y for Yes, any other key for No) :
Reply toy
to confirm the modification ofroot
user’s passwordDo you wish to continue with the password provided? (Press y|Y for Yes, any other key for No) :
Reply toy
to continue the following stepsRemove anonymous users? (Press y|Y for Yes, any other key for No):
Reply toy
to remove anonymous users (in the production environment, you should delete it)Dis allow root login remotely? (Press y|Y for Yes, any other key for No) :
Reply toy
to disableroot
remote login< li>
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
Reply toy
to remove the test databaseReload privilege tables now? (Press y|Y for Yes, any other key for No) :
Reply toy
to reload privilege tables nowThe mysql configuration file is by default in
/etc/my.cnf
Enable Mysql Autostart
[[email protected] tmp]$ sudo chkconfig mysqld onInstall PHP 7.2
If you have installed PHP before, you need to uninstall it.< /p>
[[email protected] tmp]$ sudo yum remove php* php-commonupdate and install yum of PHP Source
[[email protected] tmp]$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpmModify 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.repoChange the value of
enabled
under the[remi]
node from0
to1
.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.repoThrough the above command results, you can modify the corresponding version according to the PHP version you need to install
remi-php
.repo code>’s file Because I need to install the
7.2
version, the edit isremi-php72.repo
Execute the command:
sudo vim /etc/yum.repos.d/remi-php72.repoSet the
[remi-php72]
node under the < The value of code>enabled is changed from0
to1
.yum list phpList 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-cryptoDuring the installation process, there will be multiple confirmations, enter
y
and pressEnter
to confirm the installationInstallation is complete After that, you can view the php version through
php -v
orphp -m
to view the installed extensionsConfigure 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 = OffInstall 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 -VRedis installation (optional)
Enter Redis, a different version is required , You can choose from the official website page
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)
- Download the installation package
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
- Unzip and install
tar -xzf redis-4.0.14.tar.gz
cd redis-4.0.14
sudo make
sudo make installRedis 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
< li>Start redis
Directly execute the
redis-server
command to start itWith the startup script, in
/etc/ Create a file of
folder, such asredis_port number
under init.d/redis_6379
- 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
- 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.confFirst 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 no Change 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 |
- 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
- Enable redis-server startup
- Generate configuration file
- Edit configuration file
- Start supervisord
- Notes on commonly used commands
- Upgrading PHP7, MySQL5.7 under CentOS6.5. The main reference for the text description of the installation part of the article.
- Centos 6.5 firewall opens the designated port and sets up iptables quickly and easily
- 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 - 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 - CentOS 7. X Close SELinux SELinux close reference
- Redis installation under CentOS redis installation reference
- Linux chkconfig instructions are very helpful to understand the use of chkconfig
- (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”
- centos6.5 install supervisor Centos 6.5 install supervisor 3 The solution and the steps to install supervisor under centos are detailed in detail
ol>
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
echo_supervisord_conf> /etc /supervisord.conf
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
Use /etc/supervisord.conf
configuration file to start the supervisord
service
/usr/bin/supervisord -c /etc/supervisord.conf
#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=disabled
After setting, it needs to be restarted to take effect