+5 votes
299 views
How to mount Apache web server, PHP 5 and Mysql from scratch

in Web Servers by (552k points)
reopened | 299 views

1 Answer

+3 votes
Best answer

We will develop how to install, configure and optimize a web server under Linux. The tutorial is valid for any distribution by changing the corresponding commands to install or update files. In this case it will be done for a CentOS distribution.


image


The first step is to connect to our server through ssh from the terminal.

When we access the server we proceed to install Apache.
root @ server1: ~ # yum install httpd

Then we install php, be careful with the version that we install, because if it is very new, many web applications could become obsolete and not work.
root @ server1: ~ # yum apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

We install Mysql
root @ server1: ~ # yum install mysql mysql-server

In order to manage Mysql we can install phpmyadmin
root @ server1: ~ # yum install phpmyadmin


Configuring and optimizing server service

The first thing we will do is that apache starts automatically with the system, otherwise we should start it manually
root @ server1: ~ # yum chkconfig --level 235 httpd on

Restart or start the apache service manually (Restart or Start)
root @ server1: ~ # yum /etc/init.d/httpd start

We will also tell mysql to start automatically and start the service
root @ server1: ~ # yum chkconfig --level 235 mysqld on
root @ server1: ~ # yum /etc/inti.d/mysqld start


To test if the server is installed and working we can visit the server's ip and the apache page should respond



image


Optimizing apache

Hide version and information sensitive to the public. Malicious users can use this information to attack your server.
root @ server1: ~ # nano /etc/httpd/conf/httpd.conf

Add these policies or change them for the following
ServerSignature Off
ServerTokens Prod

Deactivate directory browsing
Options -Indexes

Then save the changes and restart Apache
root @ server1: ~ # /etc/init.d/httpd restart

Configure the following httpd.conf variables

root @ server1: ~ # nano /etc/httpd/conf/httpd.conf

Timeout defines, in seconds, the time the server will wait to receive and transmit during communication. 60 and 300 seconds, This interferes with the sending of files by forms, TCP requests, GET, etc. Therefore, it must be defined depending on the use of the server.

MaxClients establishes a limit to the total of the processes of the server or clients connected simultaneously, that can execute at the same time, depending on the use varies the performance of the server.

KeepAliveTimeout sets the number of seconds the server will wait after serving a request and closing the connection, usually 10 to 15 seconds.

Optimizing and configuring MYSQL

To optimize and configure mysql we are going to
root @ server1: ~ # nano /etc/my.cnf

Some variables to optimize and configure are:

Create a log where queries that take more than 2 seconds to optimize are saved
log-slow-queries = / var / log / mysql-slow-queries.log
long_query_time = 2 (in seconds)

Disconnect any inactive client in x seconds, thus avoiding that it occupies a connection
wait_timeout = 30
connect_timeout = 10

You can also configure the cache size and memory buffer that will depend on the needs of the server.

Optimizing php

The most important thing about php is to optimize php.ini, in this case it will depend on the needs of your applications
root @ server1: ~ # nano /etc/php.ini

max_execution_time - This determines the time a script can take to run, if you are using scripts that consume a lot of resources it may be convenient to adjust this in the most convenient way.

memory_limit - If your script uses a lot of memory to run effectively, since some of the shared hosting services only allow 16 MB, if you can configure it better put it in 32 MB.

post_max_size - If you have a site where users can upload files to the server, here you can configure the maximum size limit of the files they can upload, from the POST method, for tasks to import or upload files and images.

by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Jun 23, 2019 in Web Servers by backtothefuture (552k points) | 201 views
+3 votes
1 answer
asked Jun 24, 2019 in SEO by backtothefuture (552k points) | 367 views
+5 votes
1 answer
asked Jun 23, 2019 in PHP by backtothefuture (552k points) | 264 views
+5 votes
1 answer
asked Oct 15, 2019 in Linux / Unix by backtothefuture (552k points) | 236 views
+5 votes
1 answer
asked Jun 23, 2019 in Web Servers by backtothefuture (552k points) | 239 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users