Drush with several Virtual Hosts on Apache web server - apache

I have several Drupal installs on an Apache2 Web server.
Each install is a separate virtual host on the Document Root, like
/var/www/html/site-1
/var/www/html/site-2
/var/www/html/site-3
...
I want to perform Drush commands just on "site-1", for example install a module.
In order to do that just for "site-1", should i do the following?
1.) cd /var/www/html/site-1/sites/all/modules
2.) drush en module_name -y
Will the above download and enable "module_name" only for "site-1"?
Thanks!

You might want to use the option --rootto specify the webroot of your drupal installation. You can also specify the website URL using the option --uri, if you have a multisite installation. Look at http://docs.drush.org/en/master/usage/#options for an in-depth description.
But the best way to handle you setup is drush aliases (http://docs.drush.org/en/master/usage/#site-aliases). You define an alias #site1 etc. and this alias references the webroot and site URL (and optionally other parameters as well).

Yes, it will enable only site-1. If you just remain in /var/www/html/site-1/, that is enough.

Related

PHPmyadmin and Wordpress directories access denied

Running wordpress locally on a centOS 7 server running the latest apache, PHPmyadmin and mariadb-server.
IP/wordpress and IP/phpmyadmin on systems within the local network yields "403 forbidden" "you dont have permission to access (directory) on this server."
How can I fix this to allow the website to be seen on the public internet?
Could be a lot of things.
In your main Apache configuration file (e.g. /etc/httpd/conf/httpd.conf on Arch Linux), confirm your DocumentRoot path. The files you want to serve must reside there, or in sub-directories from there (If not, you might want to use an Alias to specify another path). Since you call IP/wordpress and IP/phpmyadmin, then you probably have directories called wordpress and phpmyadmin under your DocumentRoot path.
You also want to check the Directory groups in your Apache configuration file. Under those, the main culprit would be the Require directive set to all denied or something else too much restrictive like ip your_ip.
Finally, PHP can restrict path access with the open_basedir directive. Look for it in your php configuration file (e.g. /etc/php/php.ini on Arch Linux). If the line is commented, you're fine. But if a path is specified, your wordpress and phpmyadmin files must reside there.
Depending on your setup, any directive mentioned above could be in another Apache configuration file (e.g. /etc/httpd/conf/extra/* on Arch Linux).
Take a look at Apache and PHP online documentation for information about those directives.
Probably there is an issue with your directory privileges.
Use the follwing command to check it:
cd your_site_directory
ls -l
You can have a look to have a better understanding on directory privileges here.
As mentioned here apache runs under "apache" user.
Have a look at this post here to fix the issue.
All files should belong at least to apache group. To do it you can use
cd your_site_directory
chgrp -R apache ./*

How to change the apache user for a virtual host in Centos 7?

I am trying to set up a web server on Centos 7. I have created a virtual host by editing /etc/httpd/conf/httpd.conf. The root directory of the virtual host was set to /var/www/html/domain.com. I am able to open domain.com in the browser with no issue.
However, when I use get_current_user() in a PHP file to test what user the server is running under, the output is "root" which is a security concernt.
How do I change the user of the virtual host? When I set up a similar scenario in Ubuntu, I used apache2-mpm-itk module and configured the virtual host with "AssignUserID your_username your_username" and it did the trick. But I don't know how to do it in Centos.
Thanks
You can try to use SuexecUserGroup for that.
I found this method from plesk's configuration.
<VirtualHost *:80>
<IfModule mod_suexec.c>
SuexecUserGroup "anyuser" "anygroup"
</IfModule>
/VirtualHost>
In CentOS, this command gives you the file's owner, not the owner of the process ID. Something like that. It's in the PHP manual. Check out the comments at the bottom. get_current_user() By the way, check your User and Group directives in the httpd.conf and in httpd-vhost.conf. Also, use ps -faux to get a clear idea of the process spawning relationships between the httpd binary and the children it spawns. Just trying to help. ;-)
Also, check out How Apache Starts at the top of this page to make sure you understand how Apache is supposed to work by default. If yours in not working this way, that may be a good thing to know!! ;-)
In CentOS 7 you can use the httpd-itk package. It is in the EPEL repository, so you need to add that first. Something like this should get it:
yum install epel-release
yum install httpd-itk
Once installed you need to load the module by uncommenting the LoadModule line in:
/etc/httpd/conf.modules.d/00-mpm-itk.conf
Restart the httpd, and then you can use the new AssignUserID directive inside your VirtualHost sections.
have you looked into which user/group is specified in /etc/httpd/conf/httpd.conf? It would look something like this:
User apache
Group apache

Why laravel homestead is not running Apache

Obviously, I've Laravel project that really needs the .htaccess rules and Nginx doesn't seem to be the best solution for me,
1- my question is why Laravel didn't provide homestead with Apache!
After a small research that I made I found online tool for converting the rules but the output didn't work (was too short), whereas, Apache is more likely known and usable, plus it's easier to define rules for security and pretty URLs ..etc. ( at least for me )
2- Please give me answers explaining why they choose Nginx!, more importantly I need to know what Seniors and Experts will use ( Nginx, Apache )
3- Do you advise me to install Apache on Homestead?
Laravel homestead is currently able to install apache using your Homestead.yaml file.
Add a key to your sites called type. Set it to apache. like so:
sites:
- map: laravel.local
to: "/home/vagrant/laravel"
type: apache
Make sure you don't mix up apache and nginx, that won't work.
Then run vagrant up and to install apache and provision the right config files.
If it doesn't work, then first make sure to update to the latest version of homestead.
Here is an interesting article on the matter: https://www.nginx.com/blog/nginx-vs-apache-our-view/. TLDR: Nginx is faster.
Only when you have an existing project and you really need to use apache. Or in case your application is going to run on an apache server. Starting fresh? Use nginx.
Steps are as follows here.
SSH into vagrant -> vagrant ssh
Stop Nginx -> sudo service nginx stop
Remove it -> sudo apt-get purge nginx
Update you repos -> sudo apt-get update
Install apache -> sudo apt-get install apache2
Restart it -> sudo service apache2 restart
You are now on Apache server, update the apache conf file as your needs.
What exactly are you trying to do and perhaps we can supply a solution to your problem. You shouldn't really need to be rewriting URLs with .htaccess as Laravel's routing handles this.
1) Regardless of software, if you're needing to configure the webserver for each specific project, its probably better to go and configure your own vagrant box that is relevant for that project.
2) Nginx outperforms apache and reduces a lot of the bloat that simply isn't needed. Its also what forge uses and so homestead uses in turn so its mocking the forge environment.
3) See point 1, configure your own vagrant box for this project.

where should i define my virtual hosts? conf/httpd.conf or conf.d/user.conf

i have seen more than one tutorial that i have been using trying to get suPHP running on my centos 6.5 box.
first off, standard lamp virtual hosts tutorials always add virtual hosts into /etc/httpd/conf/httpd.conf however, a different tutorial that i was looking at (http://invision-web.net/web/install-configure-apache-php-suphp-virtual-hosts-centos/) puts the virtual hosts into /etc/httpd/conf.d/user.conf
is there a right or wrong way to do this? is one better than another?
also, i understand that httpd.conf is the main apache config file, but what exactly is the user.conf file?
The virtual host configurations should normally go in main Apache configuration file httpd.conf. In the article link you posted above the configuration
creates a virtual host for user invision on domains
n1.invision-web.net and www.invision-web.net
. Unless you have multiple site users which require configuration at a per-user level, this is not necessary. The article does not make this clear at all.
user.conf is for per-user configuration. For example, where sites have multiple users (e.g. access to http://www.mysite.com/~pedro (delivering content from the home directory or sub-directory of user pedro) can be configured in the users.conf file. More details in Apache docs.

permission Apache PHP public_html

I'm newbie in the web development, and I'm trying to make a website. So, my website works fine on the server but not on my own (Apache). My sources are in ~/public_html/. The problem is I don't have permissions on the sub/sub directory, I mean, when it's a directory, it works fine, when it's directory in a directory, it doesn't. (403 Forbidden). I don't change my default Apache configuration excluding for include mysql and php.
All my directories have the same permissions. Maybe I need to configure something for that?
Thanks
I used this little script found at this link http://boomshadow.net/tech/fixes/fixperms-script/
Fixperms – for one single user
To use the fixperms script, simply log into your server as root, wget the file from our server, then run it. Type in the cPanel username and it will run only for that particular account.
It does not matter which directory you are in when you run fixperms. You can be in the user’s home directory, the server root, etc. The script will not affect anything outside of the particular user’s folder.
Should be done in SSH
root#example [~]# wget boomshadow.net/tools-utils/fixperms.sh
root#example [~]# sh ./fixperms.sh -a USER-NAME
Fixperms – for all of the users
If you would like fix the permissions for every user on your cPanel server, simply use the ‘-all’ option:
root#example [~]# wget boomshadow.net/tools-utils/fixperms.sh
root#example [~]#sh ./fixperms.sh -all