Installing Apache Mysql on Centos Ubuntu and creating WordPress website
Installing Apache Mysql on Centos Ubuntu and creating WordPress website Once you got the Server or VPS, Login to the server through SSH using a the tool called putty. Once you have logged in. type in the below command. For CentOs : Installing Apache with Mysql support
[email protected] # yum install httpd php php-mysql
sudo apt-get install httpd php php-mysql
Set the Apache service to start automatically when you restart.
[email protected] # chkconfig httpd on [email protected] # service httpd start
Start the Apache server by service httpd start or /etc/init.d/httpd start Now, we need to install mysql server
[email protected] # yum install mysql-server
sudo apt-get install mysql-server
Set the Mysql service to start automatically when you restart.
[email protected] # chkconfig mysqld on [email protected] # service mysqld start
Start the Mysql server by service mysqld start or /etc/init.d/mysqld start Once the Apache Webserver and MySql server is installed and started. We need to configure it. Now, Preparing the Apache Web Server. Its simple, if you want to load WordPress or any other script through the IP Address, Just upload the files to /var/www/html and proceed to the MySql configuration process. If you want to host a website and load through a website or domain name. follow the below steps. Just edit the httpd.conf file using nano text editor.
[email protected] # nano /etc/httpd/conf/httpd.conf
Go to very bottom of the configuration file and add this below lines and replace your domain name instead of example.com.
<virtualhost 192.168.1.1:80> ServerName example.com ServerAlias *.example.com www.example.com ServerAdmin [email protected] ErrorLog /var/log/httpd/error_log CustomLog /var/log/httpd/example.log combined DocumentRoot /var/www/example.com <Directory "/var/www/example.com"> Order allow,deny Allow from all </Directory> </virtualhost>
or you can also create a file called example.com.conf at the path /etc/httpd/conf.d/example.com.conf and paste the above details and save it. Once done, Just restart the Apache server by service httpd restart now, you can access the website through your domain name, eg. http://example.com The Apache setup is complete. We will now prepare the Mysql server. MySql server is installed with no root password set. We will now secure the mysql installation and its sooo easy. Just type : mysql_secure_installation
[email protected] # mysql_secure_installation
follow the setup steps after you enter the above command. Just press enter on the first prompt, enter the mysql root users password now. we will now login to the mysql server by below command. after you complete the mysql server secure setup.
[email protected] # mysql -u root -p
Once you logged in with MySQL root password, We need to create database for wordpress installation:
CREATE DATABASE exampledb;
Now wee need to create a new user.
CREATE USER 'databaseuser'@'localhost' IDENTIFIED BY 'userpassword' ;
change userpassword with your own pass code. Use Strong Password Generator to get a secure password here http://www.mynetworkip.com/strongsecurepasswordgenerator/ Now, we are going to provide PRIVILEGES to the dbuser on the database we created.
GRANT ALL PRIVILEGES ON exampledb.* TO [email protected] IDENTIFIED BY 'userpassword';
and also flush the privileges
Now, type exit to come out of the mysql prompt. Preparing the WordPress Script to install. Downloading the WordPress Installation Files.
[email protected] # cd /var/www/example.com/ [email protected] # wget https://wordpress.org/latest.zip [email protected] # unzip latest.zip
Here, You may get an error like below
[email protected] # wget https://wordpress.org/latest.zip Resolving wordpress.org... 184.108.40.206, 220.127.116.11 Connecting to wordpress.org|18.104.22.168|:443... connected. ERROR: certificate common name `*.wordpress.org' doesn't match requested host name `wordpress.org'. To connect to wordpress.org insecurely, use `--no-check-certificate'.
To Resolve the issue, Just add –no-check-certificate at the end of the wget command. eg: wget https://wordpress.org/latest.zip –no-check-certificate
[email protected] # wget https://wordpress.org/latest.zip --no-check-certificate
Now, You will see a folder called wordpress.
cd wordpress mv -Rf * /var/www/example.com/
This two lines command will move the wordpress files from /wordpress to main domain folder. make sure you change the path with yours. Now, Copy the sample wordpress config file “wp-config-sample.php” from the wordpress directory to “wp-config.php”
[email protected] # cd /var/www/example.com/ [email protected] # cp wp-config-sample.php wp-config.php
Edit the the file wp-config.php using nano text editor.
[email protected] # nano /var/www/example.com/wp-config.php
You will find this below details on the php file, make sure you update with your mysql credentials. /** The name of the database for WordPress */ define(‘DB_NAME’, ‘WordPressdb’); /**MySQL database exampledb */ define(‘DB_USER’, ‘databaseuser’); /** MySQL database password */ define(‘DB_PASSWORD’, ‘userpassword’); Save it by Pressing “CTRL + O” and Exit by Pressing “CTRL + X“. Now, access the wordpress URL, http://youripaddress/wp-admin/install.php or http://example.com/wp-admin/install.php OPTIONAL : Set the permissions on the installation directory. First, switch in to the web directory: [email protected] # cd /var/www/ Give ownership of the directory sudo chown www-data:www-data * -R sudo usermod -a -G www-data username If this guide helpful, help us sharing this to your friends in need of help.